# .NET Reflection API 快速攻略
```
using System.Reflection;
namespace ConsoleApp3
{
public class Test
{
public int X { get; set;}
public void Spit()
{
Console.WriteLine(" X is " + X);
}
}
internal class Program
{
static void Main(string[] args)
{
Test a = new Test();
// ----- 設定屬性
a.X = 0xBEEF;
// ----- 取得CLR型別
Type t = a.GetType();
if (t == null) return;
// ----- 取得屬性Handle
PropertyInfo np = t.GetProperty("X");
// ----- 取得屬性值
Console.WriteLine(np.GetValue(a));
// ----- 取得方法Handle
MethodInfo mi = t.GetMethod("Spit");
// ----- 呼叫方法
mi.Invoke(a, null);
Console.Read();
}
}
}
```