1. 程式人生 > 其它 >sequlizejs學習筆記整理

sequlizejs學習筆記整理

Type是最常用到的類,它一般用於裝載反射得到的類物件,通過Type可以得到一個類的內部資訊,也可以通過它反射建立一個物件。一般有三個常用的方法可以得到Type物件。 1.利用typeof()得到Type物件  Type type = typeof(Example); 2.利用System.Object.GetType()得到Type物件  Example example = new Example();  Type type = example.GetType(); 3.利用System.Type.GetType()得到Type物件 Type type = Type.GetType("MyAssembly.Example",false,true) //注意0是類名,引數1表示若找不到對應類時是否丟擲異常,引數2表示類名是否區分大小寫 public class Program { static void Main(string[] args) { Person p1 = new Person(); Type t1 = typeof(Person); Type t2 = p1.GetType(); Person p2 = Activator.CreateInstance(t1) as Person; Person p3 = Activator.CreateInstance(t2) as Person; Console.ReadKey(); } } public class Person { public int Id { get; set; } public string Name { get; set; } }