C# 获取自定义Attribute

ACKD:自定义类。

 

object[] s =typeof(ACKD).GetCustomAttributes(true);//获取该类上施加的 Attribute

 

System.Reflection.PropertyInfo[] propertyInfoArray = typeof(ACKD).GetProperties();//获取该类的所有属性集合
propertyInfoArray[0].GetCustomAttributes(true);//取得属性集合0元素的Attribute

 

 

System.Reflection.MethodInfo[] methodInfoArray = typeof(ACKD).GetMethods();//获取该类的所有方法集合
methodInfoArray[0].GetCustomAttributes(true);//取得方法集合0元素的Attribute

转载于:https://www.cnblogs.com/harryliu/archive/2012/04/24/2468420.html

你可能感兴趣的:(C# 获取自定义Attribute)