I keep seeing the following syntax when looking at C# code (using .NET 4.0 framework):
[XmlIgnore, Bindable(false)]
public virtual FieldBase Field {get;set;}
What is the purpose of the square brackets above the property header?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
These are attributes, they can be applied to elements of your code-base and in doing so applies metadata to that thing – like descriptive declarations. These things can have multiple attributes. There are a bunch of ‘built-in’ attributes exposes by the .NET framework, you can however define your own.
Types that are attributes are actually defined with a fully qualified name of
SuchAThingAttribute, whereas in being applied you need only specify the name minusAttributewhich becomesSuchAThing. And they must derive fromSystem.Attribute(at least to be compliant).An attribute can have ‘settings’, that is, you can specify (when writing your own) which types of elements the attribute is applicable to, and whether an element can have more than one of this type of attribute or not, and so on.
The metadata of the attribute can later be got at using Reflection and
GetCustomAttribute-like methods. Links here and here show examples of doing so.