属性的优势和使用 [英] Advantage and Use of Attributes

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

问题描述

c#中属性的优点和用途是什么?
创建和实现自定义属性?
在c#

What is Advantages and Uses of Attribute in c# ?
Create and Implement of Custom Attribute ?
Check a String with help of attribute in Console Application in c#

推荐答案

的控制台应用程序中,借助属性检查字符串.但通常将其与反射结合使用.

例如,当使用winforms/wpf设计器时,Visual Studio使用DisplayNameAttribute,DiscriptionAttribute,CategoryAttribute和DefaultValueAttribute来填充属性窗格.
我所知道的所有面向方面的框架都使用属性来指示将哪个方面应用于哪个类,方法或属性.

您可以通过继承类Attribute来实现自己的属性,并将其与其他任何属性一样使用.
The uses of attributes varies. But in general it''s used in combination with reflection.

For example DisplayNameAttribute, DiscriptionAttribute, CategoryAttribute and DefaultValueAttribute are used by Visual Studio to populate the property pane when using the winforms/wpf designer.

All the aspect-oriented frameworks I know of uses attributes to indicate which aspect is to be applied to which class, method or property.

You implement your own attribute by inheriting from the class Attribute and use it like any other attribute.
[MyAttribute]
public class MyClass { }


转到此处 [ ^ ]


这篇关于属性的优势和使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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