ProgramingTip

속성에 관련 화되지 않음

bestdevel 2021. 1. 10. 22:56
반응형

속성에 관련 화되지 않음


이런 코드를 때 때

[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

나는 백업 필드를 사용하는 것이 좋습니다

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

간단한 사용 :

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

도움이 되셨기를 바랍니다.


.NET 3.0부터 Serializable 대신 DataContract사용할 수 있습니다 . DataContract를 사용하면 그러나 화 가능한 필드를 DataMember 속성으로 표시하여 "옵트 인"해야 합니다. 또는 IgnoreDataMember를 사용하여 "선택 해제"합니다 .

옵트 인과 옵트 아웃의 주요 차이점은 옵트 아웃의 주요 차이점은 옵트 아웃은 기본적으로 공개 멤버 만 내장 화하는 반면 옵트 인은 멤버 만 있다는 것과 관계입니다.

참조 URL : https://stackoverflow.com/questions/7693391/nonserialized-on-property

반응형