Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
During my researches, i've known how to override the xmlarray attribute with dynamic types but did not find how to override the "XMLInclude" for classes.
Can anyone help?
Posted

1 solution

[I scratched part of this answer in response to the comment by DaBombNL. Still, Mehdi is recommended to ask questions more clearly; he could mention XmlAttributeOverrides (is that it all about?) explicitly — SA]

Sorry, this is invalid question. The notion of "override" is only relevant to the virtual class methods or properties (more exactly, getters or setters of a property) and nothing else.

The attribute System.Xml.Serialization.XmlIncludeAttribute can is applied to a class, structure, method or an interface, see http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlincludeattribute.aspx[^].

By the way, the XmlIncludeAttribute class itself is not sealed, so you could create a derived class out of it, but why? The purpose of any attribute is to add some meta-data to the code; it basically plays the same role as type name or inheritance relationship, etc. The presence/absence and properties of the attribute and its properties simply serve as a reference for some code (serialization code in this case); basically, the code detects the presence of some attributes, reads their properties and "decides" how to proceed based on this meta-data.

If I dare to suspect that you're not well familiar with the override concept, I would suggest you should set aside all your serialization and learn it right away, as this is a hart of OOP; you could not do any real programming without.
I hope, this is not that bad: you could simply misuse the terminology.

In this case, you need to explain your base idea (not how to "override" but what you want to achieve).

—SA
 
Share this answer
 
v6
Comments
Espen Harlinn 18-Apr-11 17:47pm    
Good points, my 5
Sergey Alexandrovich Kryukov 18-Apr-11 22:20pm    
Thank you, Espen.
--SA
DaBombNL 10-May-11 16:52pm    
He is not referring to "override" as in the inheritance concept, but as in part of the `XmlAttributeOverrides` class. Which allows you to specify XML attributes on elements of a class you don't have control over.

It is true that `XmlAttributeOverrides` will only let you override any XML attributes except for XmlInclude. The question is how do you do so for XmlInclude. The answer is that you specify the XmlIncludes as types in the additionaltypes parameter of the XmlSerializer constructor.
Sergey Alexandrovich Kryukov 10-May-11 21:43pm    
Got it, thank you, I'll fix my answer. Thank you for this note.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900