For example I want to remove or change below property attributes or add a new one. Is it possible?
[XmlElement('bill_info')] [XmlIgnore] public BillInfo BillInfo { get { return billInfo; } set { billInfo = value; } }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(edit – I misread the original question)
You cannot add actual attributes (they are burned into the IL); however, with
XmlSerializeryou don’t have to – you can supply additional attributes in the constructor to theXmlSerializer. You do, however, need to be a little careful to cache theXmlSerializerinstance if you do this, as otherwise it will create an additional assembly per instance, which is a bit leaky. (it doesn’t do this if you use the simple constructor that just takes aType). Look atXmlAttributeOverrides.For an example:
Note also; if the xml attributes were just illustrative, then there is a second way to add attributes for things related to data-binding, by using
TypeDescriptor.CreatePropertyand eitherICustomTypeDescriptororTypeDescriptionProvider. Much more complex than the xml case, I’m afraid – and doesn’t work for all code – just code that uses the component-model.