Reputation: 11299
If I have a class with attributes on it's properties and want to serialize the class to XML, is it possible to include these attributes in the generated XML?
For Instance:
<SomeClassAttribute()> _
Public Class MyClass
private m_Property1 as string
<SomePropertyAttribute()> _
public Property1 as string
get
return m_Property1 as string
end get
set(ByVal Value as string)
m_Property1 = value
end set
end property
end Class
Upvotes: 0
Views: 74
Reputation: 1062502
No, basically. Unless you expose a regular property that provides them, or implement IXmlSerializable
. The intent of serialization is to serialize an individual object's properties; attributes are metadata annotations, that are not really associated with any specific instance. As such, they don't naturally fit into object serialization, except perhaps (as metadata) to guide it (for example [XmlTypeAttribute]
, [XmlRootAttribute]
, etc)
Upvotes: 2