sách gpt4 ai đã đi

.net - .NET 中的自定义属性是什么

In lại 作者:行者123 更新时间:2023-12-01 11:00:12 25 4
mua khóa gpt4 Nike

问题没那么简单:)。

基本上,我需要知道什么将包含在从 Attribute.GetCustomAttributes() 方法系列的任何方法返回的数组中。

当然,我定义的所有属性都会在那里。然而,不仅是他们。例如,所有 Entity Framework 属性(如 EdmScalarPropertyAttribute)也都在那里。哪些属性不会被视为自定义?

1 Câu trả lời

几乎所有派生自 System.Attribute và sử dụng [AttributeName] 语法添加的属性都将存在。其中一些甚至是编译器自己添加的,例如 ngoài 关键字的 OutAttribute.

“自定义”一词将它们与直接构建到运行时的属性区分开来,例如成员/类型的可见性、tĩnh 的方法、ảohoặc密封

Ví dụ Type.Attributes 是类型为 TypeAttributes 的枚举, 或 MethodBase.Attributes 对应于 MethodAttributes枚举。这些不算作“自定义”。


Về [Serializable] 和内存布局,有一些奇怪的极端情况。

基础 C# writes :

One of the characteristics that make System.SerializableAttribute not just a custom attribute, however, is the fact that the CIL has a special header notation for serializable classes.

...

SerializableAttribute translates to a set bit within the metadata tables. This makes SerializableAttribute Một pseudoattribute, an attribute that sets bits or fields in the metadata tables.

关于.net - .NET 中的自定义属性是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11742829/

25 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com