属性及其构造函数...... [英] Attributes and their constructors...

查看:79
本文介绍了属性及其构造函数......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于属性的快速问题



当我们使用描述属性时,我们正常地这样做

 [描述( 类包含关于用户的信息)] 
公共类用户

但是,如何来我们可以构造等描述( )和DescriptionAttribute(类型)???我的意思是,当我用对象浏览器查看时,我似乎找不到名为 Description 的类,但是DescriptionAttribute是那里。[confused] [confused]

我一直在寻找MSDN,但似乎没有任何关于此的弹出。

任何人都有答案[D''哦] [D''哦]

解决方案

来自MSDN( http://msdn.microsoft.com/en-us/library/bfz783fz.aspx ):



按照惯例,所有的属性名与属性结束但是,几种针对运行时的语言(如Visual Basic和C#)不需要您指定属性的全名。例如,如果要初始化 System :: ObsoleteAttribute ,你只需要引用它作为<强>过时即可。


东西包围 [ 和 ]不是正常的类。它们是类属性,可以使用数百种不同的方式...

在这里查看更多信息:http://www.codeproject.com/KB/cs/attributes.aspx [ ^ ]


Hello Paw,



*我可以看到这个问题是5岁;),但我刚刚读完它...



请参阅DescriptionAttribute类
MSDN上的
[ ^ ]



你可以在属性上看到这篇关于CP的文章在C#中的一般(it''sa有点老了,但它的确定):

属性在C# [ ^ ]



干杯,

Edo


I have a quick question about Attributes

When we use the Description attribute we normaly do it like this

[Description("Class that contains information about an user")]
public class user

But how come we can construct the type like Description("") and DescriptionAttribute("") ???
i mean, i can''t seem to find the class called Description, when i look with the object browser, but the DescriptionAttribute is there.[confused][confused]

I have been looking on MSDN, but nothing seems to popup about this.

Anyone have a answer [D''Oh] [D''Oh]

解决方案

From MSDN (http://msdn.microsoft.com/en-us/library/bfz783fz.aspx):

"By convention, all attribute names end with Attribute. However, several languages that target the runtime, such as Visual Basic and C#, do not require you to specify the full name of an attribute. For example, if you want to initialize System..::.ObsoleteAttribute, you only need to reference it as Obsolete."


stuff surrounded by "[" and "]" are not normal classes. They are class attributes and can be used hundreds of different ways...

Look here for more info: http://www.codeproject.com/KB/cs/attributes.aspx[^]


Hello Paw,

* I can see that the question is 5 years old ;) , but I''ve just happened to read it now...

See DescriptionAttribute Class
on MSDN
[^]

You can see this CP article on Attributes in C# in general (it''s a little old but it''s ok):
Attributes in C#[^]

Cheers,
Edo


这篇关于属性及其构造函数......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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