使用反射访问: 自定义属性的信息和对其进行操作的方法。
一、实例1
1、代码:
如:System.Attribute[] attrs=System.Attribute.GetCustomAttributes(typeof(FirstClass));
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
PrintAuthorInfo(typeof(FirstClass));
PrintAuthorInfo(typeof(SecondClass));
PrintAuthorInfo(typeof(ThirdClass));
Console.ReadKey();
}
private static void PrintAuthorInfo(System.Type t)
{
System.Console.WriteLine("\n类型的 System.Type 对象是:{0}", t);
System.Attribute[] attrs = System.Attribute.GetCustomAttributes(t); //反射获得用户自定义属性