zoukankan      html  css  js  c++  java
  • 特性类

    [AttributeUsage(AttributeTargets.Class)]//该特性类可以应用到的程序结构有哪些
    MyTestAttribute:system.Attribute{
            public string Description{get;set;}
            public string VersionNumber{get;set;}
            public int ID{get;set;}
           
         public MyAttribute(string desc)
        {
            cw (this.Description=desc)
        }
    }
    1.以Attribute结尾
    2.需要继承自System.Attribute
    3.一般情况下声明为sealed
    4.一般情况下表示目标结构的一些状态
    使用的时候
    [MyTest(“简单的特性类”,ID=100)]//此处胜省略了Attribute,指定属性的名字给属性命名,为参数命名
    class Program
    {
      Type type=typeof(Program);

    Object[] array=type.getCustomAttribute(false);//表示是否搜索他的父类的特性
      MytestAttribute mytest=array[0] as MyTestAttribute;
    Console.writeLine(myTest.ID); }
  • 相关阅读:
    Spring Boot自动配置
    Servlet、JSP总结(1)
    Spring MVC
    Springboot中的数据库事务
    数据库访问
    AOP
    全注解下的IOC
    spring boot入门
    安卓工程化开发笔记(2)
    2048功能说明模板
  • 原文地址:https://www.cnblogs.com/1521681359qqcom/p/11367099.html
Copyright © 2011-2022 走看看