I have seen from other questions, e.g. How to add an attribute to a property at runtime, that it is possible to add an Attribute to a Property dynamically. Suppose I have a property to which I have added an attribute, as shown:
[MyCustomAttribute("MyCustomAttributeValue")]
public bool PropertyName { get; set; }
If my class were serialized, this would probably appear as follows, without MyCustomAttribute/MyCustomAttributeValue:
<q1:Object>
<PropertyName xmlns="namespace">Value</PropertyName>
</q1:Object>
XmlAttribute allows the user to set a custom Namespace or DataType, which then appears within the PropertyName element, but what can be done so that the custom attribute is serialized and saved to the XML, as something like:
<q1:Object>
<PropertyName xmlns="namespace" MyCustomAttribute="MyCustomAttributeValue">Value</PropertyName>
</q1:Object>
Is this possible without writing a custom XML Serializer?
Aucun commentaire:
Enregistrer un commentaire