|
ToDo:
|
蚊宴⒢絎音ゃc若鐚 蕋狗⒢
[Win] с
罨<羔我莢激
[C#] Reflection
using System;
namespace ConsoleApplication1
{
[AttributeUsage(AttributeTargets.Field)]
class SampleAttribute : Attribute
{
private string _name;
public string name
{
get { return _name;}
}
public SampleAttribute()
{
_name = this.GetType().ToString();
}
}
class Class1
{
[Sample]
public string _prop ;
[STAThread]
static void Main(string[] args)
{
Class1 obj = new Class1() ;
System.Reflection.FieldInfo [] lists = obj.GetType().GetFields();
foreach(System.Reflection.FieldInfo i in lists)
{
object[] ls = i.GetCustomAttributes(typeof(SampleAttribute),true);
foreach(SampleAttribute sa in ls)
{
System.Console.WriteLine("{0}",sa.name);
}
}
}
}
}