定制与非定制属性? [英] Custom vs. non-custom attributes?

查看:133
本文介绍了定制与非定制属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

东西,它实现了 ICustomAttributeProvider 界面将让你得到那些通过 GetCustomAttributes 方法。据我了解,一个自定义属性基本上是一类特殊的(结局中的属性,延长属性类)所创建应用于类似的方法或使用适当的语法类( [FooAttribute] 只是方法/类/等。在C#中,例如之前)。但是,如果这是一个自定义属性,什么是的的-custom属性?我曾经认为这是捆绑了.NET属性是非定制,但 GetCustomAttributes 甚至返回我的属性,如 System.ThreadStaticAttribute ,这是非常核心的.NET框架。

Something which implements the ICustomAttributeProvider interface will allow you to get custom attributes that have been applied to it via the GetCustomAttributes method. As I understand it, a custom attribute is basically a special class (ending in "Attribute" and extending the Attribute class) that is created to be applied to something like a method or class using the appropriate syntax ([FooAttribute] just before the method/class/etc. in C#, for example). But if that is a custom attribute, what is a non-custom attribute? I used to think that attributes that were bundled with .NET were non-custom, but GetCustomAttributes even returns me attributes like System.ThreadStaticAttribute, which are very core to the .NET framework.

有没有这样的事,作为一个非自定义属性,或者是自定义属性只是一种同义反复?

Is there such a thing as a non-custom attribute, or is "custom attribute" just a tautology?

推荐答案

我不知道下面有什么关联,但是如果说

I don't know if the following has any relevance, but if you say

var a = typeof(string).Attributes;

你称为标志枚举类型的值 TypeAttributes 。也许这些标志都是类型的非定制属性?

you get a value of a flags enum type called TypeAttributes. Maybe these flags are the "non-custom" attributes of the type?

这篇关于定制与非定制属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆