草庐IT

binary-serialization

全部标签

c# - 使用 .NET 自定义序列化时测试可选字段

给定这样一个类:[Serializable]publicclassMyClass{stringname;stringaddress;publicMyClass(SerializationInfoinfo,StreamingContextcontext){name=info.GetString("name");if(/*todo:checkifavalueforaddressexists*/)address=info.GetString("address");}publicvoidGetObjectData(SerializationInfoinfo,StreamingContextco

c# - "The binary operator Add is not defined for the types ' System.String ' and ' System.String '."-- 真的吗?

尝试运行以下代码时:Expression>stringExpression=Expression.Lambda>(Expression.Add(stringParam,Expression.Constant("A")),newList(){stringParam});stringAB=stringExpression.Compile()("B");我收到标题中提到的错误:“二元运算符Add没有为类型‘System.String’和‘System.String’定义。”真的是这样吗?显然在C#中它有效。在C#中执行strings="A"+"B"是表达式编译器无法访问的特殊语法糖吗?

c# - BinaryFormatter.ILMerge 后反序列化 "unable to find assembly"

我有一个带有引用dll的C#解决方案(也是具有相同.Net版本的C#)。当我构建解决方案并运行生成的exe时,没有合并exe和引用的dll,一切正常。现在我想将它们合并到一个exe中。我运行ILMerge,一切似乎都正常。我尝试执行exe,它似乎运行良好,直到它尝试反序列化在引用的dll中定义的对象。using(Streamfstream=newFileStream(file_path,FileMode.Open)){BinaryFormatterbf=newBinaryFormatter();returnbf.Deserialize(fstream)asControlledRuleC

c# - Serial Port ReadLine vs ReadExisting 或如何从串口正确读取数据

我正在从串口读取数据。数据超出了规模。我现在正在使用Readline(),即使在我删除DiscardInBuffer()之后数据也会丢失。从串口读取数据的正确方法是什么?网上的例子太少了,我觉得这就像是无人问津的chalice。C#、WinCE5.0、HP瘦客户机、Compact框架2.0privatevoidWeighSample(){this._processingDone=false;this._workerThread=newThread(CaptureWeight);this._workerThread.IsBackground=true;this._workerThread

c# - ASP.net Web API : change class name when serializing

我有一个产品的数据传输对象类publicclassProductDTO{publicGuidId{get;set;}publicstringName{get;set;}//Otherproperties}当Asp.net序列化JSON(使用JSON.NET)或XML中的对象时,它会生成ProductDTO对象。但是,我想在序列化期间更改名称,从ProductDTO到Product,使用某种属性:[Name("Product")]publicclassProductDTO{[Name("ProductId")]publicGuidId{get;set;}publicstringName{

c# - Json Serialize Dictionary<Enum, Int32> 的问题

每当我尝试序列化字典时,我都会得到异常:System.ArgumentException:Type'System.Collections.Generic.Dictionary`2[[Foo.DictionarySerializationTest+TestEnum,Foo,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null],[System.Int32,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]]'isnotsupportedfors

c# - 串口通信 : polling serial port vs using serial port DataReceived event

我只是在回顾我在CF2.0上用C#编写的与串行端口通信的一些代码。我没有使用DataReceived事件,因为它不可靠。MSDNstatesthat:TheDataReceivedeventisnotgauranteedtoberaisedforeverybytereceived.UsetheBytesToReadpropertytodeterminehowmuchdataislefttobereadinthebuffer.我用read()轮询端口,并有一个委托(delegate)在读取数据时处理数据。我还在某处读到“轮询不好”(没有给出解释)。知道轮询为什么不好吗?除了通常的线程警告

c# - 具有内部属性的 JSON Serializer 对象

我有一些内部属性的类,我也想将它们序列化为json。我怎样才能做到这一点?例如publicclassFoo{internalintnum1{get;set;}internaldoublenum2{get;set;}publicstringDescription{get;set;}publicoverridestringToString(){if(!string.IsNullOrEmpty(Description))returnDescription;returnbase.ToString();}}使用保存Foof=newFoo();f.Description="FooExample";

c# - 如何在 C# 中执行 System.Web.Script.Serialization?

如何在C#现代UI中执行此操作?varurl="http://ajax.googleapis.com/ajax/services/feed/load?q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml&v=1.0";varwc=newWebClient();varrawFeedData=wc.DownloadString(url);//YoucanuseSystem.Web.Script.Serializationifyoudon'twanttouseJson.NETJavaScriptSerializerser=newJavaScriptSer

c# - 如何忽略二进制序列化的事件类成员?

我需要避免序列化Event类成员,因为当事件由未标记为可序列化的对象处理时,序列化将失败。我尝试在Event类成员上使用NonSerialized属性,但编译失败。这行代码:PublicEventPropertyValueChanged()产生以下错误:Attribute'NonSerializedAttribute'cannotbeappliedto'PropertyValueChanged'becausetheattributeisnotvalidonthisdeclarationtype.PublicEventPropertyValueChanged()'compilesbutn