A
ASwanevelder
Dear All,
I really enjoy the cleaness of using the build in Serialization of .NET. Now I am sitting with a dillema. I need to limit the Properties serialized in certain cases. Now the preposed way of doing this according to the MSDN is to use the XmlSerializer class and using Serialize and Deserialize on that class and customize the attributes with the XmlAttributeOverrides class. I think this is really messy and in my arhitecture I do not want people to write custom handlers to serialize and deserialize.
Is there not a way that I can write a Custom Attribute that can be attached to these properties that take in an XmlAttributeOverrides instance into its contructor and then from that tell the XmlAttributes.XmlIgnore attribute to be true or false? Can you somehow access the XmlAttributes.XmlIgnore from within a Custom Attribute.
PSEUDO:
[CustomXmlIgnore(XmlAttributeOverrides)]
public int Parameters
{
get;
set;
}
class CustomXmlIgnore: Attribute
{
CustomXmlIgnore(XmlAttributeOverrides)
{
Loop through all the Attributes overrides
{
if (attribute equals CustomXmlIgnore and XmlIgnore)
set XmlAttributes.XmlIgnore accordingly
}
}
I really enjoy the cleaness of using the build in Serialization of .NET. Now I am sitting with a dillema. I need to limit the Properties serialized in certain cases. Now the preposed way of doing this according to the MSDN is to use the XmlSerializer class and using Serialize and Deserialize on that class and customize the attributes with the XmlAttributeOverrides class. I think this is really messy and in my arhitecture I do not want people to write custom handlers to serialize and deserialize.
Is there not a way that I can write a Custom Attribute that can be attached to these properties that take in an XmlAttributeOverrides instance into its contructor and then from that tell the XmlAttributes.XmlIgnore attribute to be true or false? Can you somehow access the XmlAttributes.XmlIgnore from within a Custom Attribute.
PSEUDO:
[CustomXmlIgnore(XmlAttributeOverrides)]
public int Parameters
{
get;
set;
}
class CustomXmlIgnore: Attribute
{
CustomXmlIgnore(XmlAttributeOverrides)
{
Loop through all the Attributes overrides
{
if (attribute equals CustomXmlIgnore and XmlIgnore)
set XmlAttributes.XmlIgnore accordingly
}
}