帮助理解 C# 中此语句的语法

发布于 2024-11-13 09:12:45 字数 294 浏览 1 评论 0原文

我目前正在开发 DevExpress Report,我到处都能看到这种语法。我想知道它们是什么?它们有什么用?我的意思是方括号 [] 内的那个。我们在 C# 中怎么称呼它?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

转身以后 2024-11-20 09:12:45

这些称为属性

属性可用于将元数据添加到代码中,稍后可以通过反射访问这些元数据,或者在 面向方面编程,属性实际上可以修改代码的执行。

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.

高速公鹿 2024-11-20 09:12:45

类型或成员上方的 [] 语法称为属性规范。它允许开发人员将属性与特定类型或成员应用/关联。

C# 语言规范的第 24.2 节对此进行了介绍

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

半城柳色半声笛 2024-11-20 09:12:45

它们称为属性。它们对于提供有关类的元数据(有关数据的数据)非常有用。

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

耳钉梦 2024-11-20 09:12:45

它们被称为属性,您可以使用它们用一些元数据来标记类、方法或属性,您可以通过 运行时反射

例如,常见的一个是 可序列化,将类标记为适合转换为离线形式以便稍后存储。

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.

森林散布 2024-11-20 09:12:45

它被称为属性。

在本例中,DevExpress 在其报告类上使用自定义属性

如果您对为什么要创建自定义属性感兴趣,本文对此进行了解释

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.

我也只是我 2024-11-20 09:12:45

继续前面的答案,这是一个在其构造函数中采用字符串值的属性。在这种情况下,中间的“+”有点令人困惑......它也应该正确地与以下内容一起工作:

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

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")]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文