c# - Renaming xml element of generic type only for specific type parameter -
if write this,
class program { static void main(string[] args) { using (filestream s = new filestream("output.xml", filemode.create)) { new xmlserializer(typeof(data<item>)).serialize(s, new data<item>()); } } } [xmltype(typename = "content")] public class item { } public class data<t> { }
output.xml be
<?xml version="1.0"?> <dataofitem xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" />
but want "dataofitem" "dataofcontent". there way changing data class?
not wanted, can provide custom root name when create xmlserializer. this:
var xmltypeattr = typeof(item).getcustomattributes(true).oftype<xmltypeattribute>().firstordefault(); var customroot = new xmlrootattribute("dataof" + xmltypeattr.typename); new xmlserializer(typeof(data<item>), customroot).serialize(s, new data<item>());
Comments
Post a Comment