特性就是一个类,必须是Attribute的子类

一般以Attribute结尾,然后在使用的时候,可以去掉这个结尾

可以在特性中声明字段、属性、方法、构造函数、委托、事件...

    [AttributeUsage (AttributeTargets.All ,AllowMultiple =true )] //这样这个属性可以重复在一个类上使用
class CustomAttribute:Attribute
{
public CustomAttribute ()
{ }
private string _Remark = "";
public CustomAttribute (string remark)
{
this._Remark = remark;
} public string Description { get; set; } public int Id; public void Log()
{
Console.WriteLine(this._Remark);
} public delegate void DoDelegate();
public event DoDelegate DoEvent;
}
[Custom] //调用无参数的构造函数
[CustomAttribute()] //调用无参数的构造函数
[CustomAttribute("这里是我的测试")]//调用有参数的构造函数
[CustomAttribute("这里是Remark的",Description= "这里是Description")]//调用有参构造函数,给属性赋值
[CustomAttribute(Description = "这里是Description")]//调用无参构造函数,给属性赋值

特性可以影响编译,也可以影响运行

特性会被编译到matedata(exe或dll文件包含IL和metadata),metadata数据只能通过反射获取

通过特性,在不侵入原类型的情况,给对象增加了额外的行为

具体看代码

最新文章

  1. 汇编初入门debug实操
  2. Linux rm 删除文件
  3. android开发 NDK 编译和使用静态库、动态库 (转)
  4. android sqlite 一次创建多个表
  5. CakePHP的blog教程三
  6. Android应用程序窗口(Activity)的窗口对象(Window) 的创建过程分析
  7. 用 Python脚本生成 Android SALT 扰码
  8. 新版SDK自己主动加入PlaceholderFragment的思考
  9. 从MSSQL server 2005中移植数据到Oracle 10g
  10. 你用过CSS3的这个currentColor新属性吗?使用与兼容性
  11. oracle杀掉连接
  12. [原创]移动安全测试框架MobSF介绍
  13. FastCGI点滴
  14. C# 对图片加水印
  15. UGUI图集
  16. 《Android源码设计模式》--原型模式
  17. ORM------多表操作
  18. Ghost:一款简约风格博客系统
  19. springboot之RMI的使用
  20. Android开发:使用DialogFragment实现dialog自定义布局

热门文章

  1. Atitit.安全性方案规划设计4gm  v1 q928
  2. Android HandlerThread 总结使用
  3. android Service介绍
  4. android 启动模式介绍
  5. git推送本地分支到远程分支
  6. Linux 入门之修改主机名
  7. 安卓APP与智能硬件相结合的简易方案
  8. Java程序设计之链表结构
  9. 关于HTTP协议,一篇就够了
  10. h5+mui