Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[XmlType(AnonymousType = true)]

Hello what does mean this line during serialization?

[XmlType(AnonymousType = true)]
public class classname
{
}

xsd.exe generates this for all classes. I read documentation, but still can't understand how it affects me if I remove this line.

Thanks,

like image 465
Yaplex Avatar asked Apr 01 '11 14:04

Yaplex


1 Answers

It lets the compiler know whether or not to name the resulting XSD elements or make them anonymous

http://www.ibm.com/developerworks/library/xml-schema/

Elements with attributes must have a complex type

Now, try adding the attribute currency to the simple element price from Listing 7. You can't. An element of a simple type cannot have an attribute. If you want to add an attribute, you must define price as a complex type. In the example in Listing 8, we have defined what is called an anonymous type, where no explicit name is given to the complex type. In other words, the name attribute of the complexType element is not defined.

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmltypeattribute.anonymoustype.aspx

like image 167
Mike Avatar answered Oct 27 '22 00:10

Mike