非系列化属性
当我写这样的代码
[XmlIgnore] [NonSerialized] public List<string> paramFiles { get; set; }
我得到以下错误:
Attribute 'NonSerialized' is not valid on this declaration type. It is only valid on 'field' declarations.
如果我写
[field: NonSerialized]
我收到以下警告
'field' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'property'. All attributes in this block will be ignored.
如果我写
[property: NonSerialized]
我收到以下错误(再次):
Attribute 'NonSerialized' is not valid on this declaration type. It is only valid on 'field' declarations.
我如何在一个属性上使用[NonSerialized]
?
以及…第一个错误告诉你不能..从http://msdn.microsoft.com/en-us/library/system.nonserializedattribute.aspx
[AttributeUsageAttribute(AttributeTargets.Field, Inherited = false)] [ComVisibleAttribute(true)] public sealed class NonSerializedAttribute : Attribute
我build议使用支持领域
public List<string> paramFiles { get { return list;} set { list = value; } } [NonSerialized] private List<string> list;
简单使用:
[XmlIgnore] [ScriptIgnore] public List<string> paramFiles { get; set; }
希望它有帮助。