English 中文(简体)
• 如何防止已实施的财产被序列化?
原标题:How to prevent auto implemented properties from being serialized?

How can I prevent a auto implemented property from being serialized by the binary formatter? The [NonSerialized] attribute can only be used with fields. And the field is hidden when using auto implemented properties.

最佳回答
问题回答
// This works for the underlying delegate of the `event` add/remove mechanism.
[field:NonSerialized]
public event EventHandler SomethingHappened;

但是,这似乎并不涉及自动执行的财产。 我认为,值得一提,因为它有助于知道在把附随该物体的事件用户的物体序列化时。

如果您重新编号为Json,并使用Json.NET序列izer。 (我高度建议,因为与市场上的其他一些序列器相比,它还要提供很多东西),因此,你可以通过<代码>([JsonIgnore],在财产问题上取得预期结果。

你不需要建立一个领域。

因此,你的法典是:

public class ClassName
{
     [JsonIgnore]   
     public object IgnoreMe { get; set; } 

     public object DoNotIgnoreMe { get; set; } 
}

如果您的序号是Xml,你可以使用XmlIgnore属性。

我不相信你。 http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx” rel=“noreferer” 关于<代码>可移植的MSDN条建议你实施可追溯性并控制序列:

凡是以SerializableAttribute为标志的公共和私人领域,都是按违约顺序排列的,除非这种类型将可实现的界面压倒序列化过程。

或者从这种特定领域的汽车购买物。

It s not possible for auto implemented properties. Consider folowing:

This behavior is "by design". The decision at the time auto-properties were implemented was that they would work in the "common case" which among other things means no attributes on the generated field. The idea behind that is keeping them simple and not slowly mutating them into full properties. So, if you need to use the NonSerialized attribute full properties are the way.

()

拟议的使用非航空背书领域的解决办法似乎与4.0(至少在Xml序列化的情况下)运作不大。 该领域确实没有序列化,而是使用它的公共财产确实具有序列性,因此达不到目的。 在Xml序列化的情况下使用XmlIgnore 工作环线。 申斥——我没有核实双轨序列化行为。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签