NonSerialized on property
Когда я пишу код вроде этого
[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]
для свойства?
Ответы
Ответ 1
ну... первая ошибка сказать, что ты не можешь..
от 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;
Ответ 2
Простое использование:
[XmlIgnore]
[ScriptIgnore]
public List<string> paramFiles { get; set; }
Надеюсь, это поможет.