System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeof(CustomAttribute));
System.Type[] types = asm.GetExportedTypes();
Func<Attribute[], bool> IsMyAttribute = o =>
{
foreach(Attribute a in o)
{
if (a is CustomAttribute)
return true;
}
return false;
};
System.Type[] cosType = types.Where(o =>
{
return IsMyAttribute(System.Attribute.GetCustomAttributes(o,true));
}
).ToArray();
cosType数组即为所有被CustomAttribute标记过的类。