有OptionalField被废弃,在C#中? [英] Have OptionalField been obsoleted in C#?
问题描述
看来,<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.optionalfieldattribute.aspx"相对=nofollow> OptionalFieldAttribute 是不再(如果有的话)需要序列化的BinaryFormatter。
It seems that the OptionalFieldAttribute is not longer (if ever) needed for serialization with BinaryFormatter.
随着例如,从codeguru 有不再建造code在Visual Studio 2010时抛出的异常,针对旧版本的.NET框架时也是如此。
With a example from codeguru there is no longer any exception thrown when building the code in Visual Studio 2010, even when targeting older versions of the .NET framework.
计算器上的另一个问题表明,它一直都是可选的。这是真的?如果是这样,有其实并没有什么办法让一个例外,缺少现场,序列化二进制内容时,在.NET?
Another question on stackoverflow suggests that it's always been optional. Is this true? And if so, is there actually not any way to get a exception for a missing field, when serializing to binary content in .NET?
推荐答案
要得到的异常,这个语句添加到反序列化code:
To get the exception, add this statement to the deserialization code:
formatter.AssemblyFormat = FormatterAssemblyStyle.Full;
这篇关于有OptionalField被废弃,在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!