且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查找具有特定属性的所有类

更新时间:2023-01-17 18:10:17

IEnumerable<Type> GetTypesWith<TAttribute>(bool inherit) 
                              where TAttribute: System.Attribute
 { return from a in AppDomain.CurrentDomain.GetAssemblies()
          from t in a.GetTypes()
          where t.IsDefined(typeof(TAttribute),inherit)
          select t;
 }