如何防止自动实现的属性被序列化? [英] 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.
推荐答案
不汇入作业支持自动实现的属性。你必须使用一个支持字段并设置 NonSerializedAttribute 就可以了。
It´s not supported for auto implemented properties. You have to use a backing field and set the NonSerializedAttribute on it.
public class ClassWithNonSerializedProperty {
[NonSerialized]
private object _data; // Backing field of Property Data that is not serialized
public object Data{
get { return _data; }
set { _data = value; }
}
}
这篇关于如何防止自动实现的属性被序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文