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

    //如果没有定义 wjire 或者 refuge,
    //编译器不会再元数据中生成特性信息,也就是说利用反射找不到特性信息
    //但是,特性类的定义元数据和实现仍在程序集中
    //#define wjire
    #define refuge
    
    using System;
    using System.Diagnostics;
    using System.Reflection;
    
    namespace Test3
    {
        [Cond]
        class Program
        {
            static void Main(string[] args)
            {
                //条件特性类
                var flag = CustomAttributeExtensions.IsDefined(typeof(Program), typeof(CondAttribute));
                Console.WriteLine(flag);
    
                var cond = CustomAttributeExtensions.GetCustomAttribute(typeof(Program), typeof(CondAttribute));
                Console.WriteLine(cond?.GetType());
                Console.ReadKey();
            }
        }
    
    
        [Conditional("wjire")]
        [Conditional("refuge")]
        class CondAttribute : Attribute
        {
            public CondAttribute()
            {
                Console.WriteLine("this is ctor");
            }
        }
    }
  • 相关阅读:
    Unbuntu--安装VMware Tools
    方法引用的基本使用
    Stream流
    Stream流的常用方法
    枚举
    编程式路由导航
    向路由组件传递数据
    缓存路由组件
    嵌套路由
    基本路由
  • 原文地址:https://www.cnblogs.com/refuge/p/8971711.html
Copyright © 2011-2022 走看看