开发者

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


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.


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

  • http://www.jaggersoft.com/csharp_standard/24.2.htm


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


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.


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.


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")]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜