Brackets in class

Possible duplicate:
The meaning of the text between square brackets

The class I'm looking at looks like

public class SaveBundle { /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public SaveBundleHeader Header { get { return this.headerField; } set { this.headerField = value; } } } 

I do not know why there is [System.Xml.Serialisztion.Xml, etc.] or what is it intended to investigate further?

Can someone tell me the name [], and what is the purpose in this example?

+4
source share
4 answers

The XmlElement attribute is set in the Header property.

You can see it as an XmlElementAttribute on MSDN. Like here .

+2
source

This is an attribute used to decorate things with available metadata. You can use reflection to get this data and do something with it. Many parts of the framework already do this, as in the example in the MSDN link for the attributes denoting the Serializable class - you can perform custom serialization based on metadata, but you do not always need it because "automatic serialization" is already implemented based on this concept.

Square brackets are the syntax used to apply them, as shown in your example.

+6
source

This attribute.

MSDN provides here all the information about attributes (what they are, what they mean, etc.).

+2
source

To format your property when serializing your type

Indicates that the public field or property is an XML element when the XmlSerializer serializes or deserializes the object that contains it.

+1
source

Source: https://habr.com/ru/post/1438900/


All Articles