NonSerialized 屬性忽略序列化報錯'NonSerialized' is not valid on this declaration type

[XmlIgnore]
[NonSerialized]
public List<string> paramFiles { get; set; }

//I get the following error:

//Attribute 'NonSerialized' is not valid on this declaration type.
It is only valid on 'field' declarations.

 

 
 
Well... the first error says that you can't do that... from  http://msdn.microsoft.com/en-us/library/system.nonserializedattribute.aspx
 [AttributeUsageAttribute(AttributeTargets.Field, Inherited = false)]
 [ComVisibleAttribute(true)]
 public sealed class NonSerializedAttribute : Attribute

I suggest using backing fieldhtml

 public List<string> paramFiles { get { return list;}  set { list = value; } }
 [NonSerialized]
 private List<string> list;

 

參考:https://stackoverflow.com/questions/7693391/nonserialized-on-propertypost

 

延伸:http://www.javashuo.com/article/p-yuhsvvvj-bd.html    Json序列化指定輸出字段 忽略屬性this

相關文章
相關標籤/搜索