Is it possible to do the following :
Create an instance of SomeCLass in another part of my code AND
Using this newly created instance/object can I obtain the :
[System.Xml.Serialization.XmlElementAttribute(“someClass”)]
XML Serialization rule
What I am Trying To Achieve :
1. Identify whether SomeCLass contains an XML Serialization rule on any property in it
2. If it does contain such a serialization rule, identify the rule.
(i.e. whether its an … XMLIgnore || XMLElement || XMLAttribute … etc.)
The class referred to in the question :
Class SomeClass
{
SomeOtherClass[] privtArr;
[System.Xml.Serialization.XmlElementAttribute("SomeOtherClass")]
public SomeOtherClass[] anInstance
{
get
{
return this.privtArr;
}
set
{
this.privtArr = value;
}
}
}
You don’t need to create an instance; simply look at the
Type, in particularGetFields()andGetProperties(). Loop over the public non-static fields/properties, and checkAttribute.GetCustomAttribute(member, attributeType)– i.e.If you do need to create an instance, use
neworActivator.CreateInstance.