Set The “NonSerializedAttribute” To An Auto Property

前端 未结 7 2327
青春惊慌失措
青春惊慌失措 2021-02-18 18:59

This cannot be done in C#. Any way to do it?

...

laugh, in case my little pun wasn\'t understood, what I mean is: how can I mark a property in C# as Non

7条回答
  •  [愿得一人]
    2021-02-18 19:23

      [NonSerialized]
      public string MyProperty { get; set; }
    

    Is an error

      [XmlIgnore]
      public string MyProperty { get; set; }
    

    Is not an error

    NonSerialized Indicates that a field of a serializable class should not be serialized.

    XmlIgnore Instructs the Serialize method of the XmlSerializer not to serialize the public field or public read/write property value

    so, if you ask

    I would expect to have some way to allow me to prevent their serialization.

    the answer yes, if you're using XmlSerializer

提交回复
热议问题