.net 简单反射应用

var attributes = typeof(MyClass).GetCustomAttributes(typeof(TestAttribute), true); //MyClass 表示引用特性的类 TestAttribute特性定义的类
foreach (var attribute in attributes)
{
     TestAttribute myAttribute = attribute as TestAttribute;
     if (myAttribute != null)
     {
          Console.WriteLine(myAttribute.Msg);
     }
}

posted @ 2017-08-15 15:34  ■乐  阅读(156)  评论(0编辑  收藏  举报