roxrook
roxrook

Reputation: 13843

Help understand syntax of this statement in C#

I'm currently working on DevExpress Report, and I see this kind of syntax everywhere. I wonder what are they? What are they used for? I meant the one within the square bracket []. What do we call it in C#?

[XRDesigner("Rapattoni.ControlLibrary.SFEAmenitiesCtrlTableDesigner," + "Rapattoni.ControlLibrary")] // what is this?
    public class SFEAmenitiesCtrl : XRTable

Upvotes: 1

Views: 111

Answers (6)

NateTheGreat
NateTheGreat

Reputation: 2305

Piling on to the previous answers, this is an attribute that takes a string value in its constructor. In this case, the '+' in the middle is a little confusing... it should also work correctly with:

[XRDesigner("Rapattoni.ControlLibrary.SFEAmenitiesCtrlTableDesigner,Rapattoni.ControlLibrary")]

Upvotes: 0

DOK
DOK

Reputation: 32831

It is called an attribute.

In this case, DevExpress is using custom attributes on their report classes.

If you're interested in why you want to create custom attributes, this article explains it.

Upvotes: 1

IanNorton
IanNorton

Reputation: 7282

They are called Attributes, You can use them to mark classes, methods or properties with some meta-data that you can find by reflection at runtime.

For instance, one common one is Serializable which marks a class as suitable for conversion into an offline form for storage later.

Upvotes: 1

Charles Lambert
Charles Lambert

Reputation: 5132

They are called attributes. They are quite useful for providing metadata about the class (data about the data).

Upvotes: 1

Justin Niessner
Justin Niessner

Reputation: 245389

Those are called Attributes.

Attributes can be used to add metadata to your code that can be accessed later via Reflection or, in the case of Aspect Oriented Programming, Attributes can actually modify the execution of code.

Upvotes: 7

JaredPar
JaredPar

Reputation: 754515

The [] syntax above a type or member is called an attribute specification. It allows a developer to apply / associate an attribute with the particular type or member.

It's covered in section 24.2 of the C# language spec

Upvotes: 1

Related Questions