There are two ways to make properties non-serializable in .NET using attributes.
You can set the attributes [NonSerialized] or [XmlIgnore]
If you serialize in binary or SOAP, you should use [NonSerialized] , if you want to serialize only in XML, you should use [XmlIgnore] .
So in your case the answer is [XmlIgnore]
EDIT: Cannot apply dynamic attribute properties to properties. Here is some information about this here: Can dynamic attributes be added in C #? and here remove attribute c # properties dynamically
Just like training, you may have different copies of your class with different attributes.
OR
You have a copy of your class that defines all the details as serializable, but filling only the properties you need, so every thing will be empty / empty, and after serializing this class, you should get the necessary XML code.
source share