Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square brackets in a class [duplicate]

Tags:

c#

Possible Duplicate:
Meaning of 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 don't know why the [System.Xml.Serialisztion.Xml etc] exists or what it is called to research it further?

Can some one tell me the name of [] and what in this example it's purpose is?

like image 228
Dave Avatar asked Dec 21 '22 15:12

Dave


1 Answers

It's an attribute, used to decorate things with accessible metadata. You can use reflection to get at this data and do something with it. Many parts of the framework already do this, as with the example in the MSDN link for attributes marking a class Serializable - you could do custom serialization based on metadata but you don't always need to because 'auto-serialization' is already implemented based on this concept.

The square brackets are the syntax used to apply them, as demonstrated in your example.

like image 84
Grant Thomas Avatar answered Dec 23 '22 04:12

Grant Thomas