Quand j’écris du code comme celui-ci
[XmlIgnore] [NonSerialized] public List paramFiles { get; set; }
Je reçois l’erreur suivante:
Atsortingbute 'NonSerialized' is not valid on this declaration type. It is only valid on 'field' declarations.
Si j’écris
[field: NonSerialized]
Je reçois l’avertissement suivant
'field' is not a valid atsortingbute location for this declaration. Valid atsortingbute locations for this declaration are 'property'. All atsortingbutes in this block will be ignored.
Si j’écris
[property: NonSerialized]
Je reçois l’erreur suivante (encore):
Atsortingbute 'NonSerialized' is not valid on this declaration type. It is only valid on 'field' declarations.
Comment puis-je utiliser [NonSerialized]
sur une propriété?
Eh bien … première erreur dire que vous ne pouvez pas .. de http://msdn.microsoft.com/en-us/library/system.nonserializedatsortingbute.aspx
[AtsortingbuteUsageAtsortingbute(AtsortingbuteTargets.Field, Inherited = false)] [ComVisibleAtsortingbute(true)] public sealed class NonSerializedAtsortingbute : Atsortingbute
Je suggère d’utiliser un champ de support
public List paramFiles { get { return list;} set { list = value; } } [NonSerialized] private List list;
Utilisation simple:
[XmlIgnore] [ScriptIgnore] public List paramFiles { get; set; }
J’espère que ça aide.