正文
获取名为”MyClass”的类型
1 | Type t = Type.GetType("MyClass"); |
或者
1 | MyClass myclass = new MyClass(); |
获取”MyClass”的属性
1 | PropertyInfo[] properts = t.GetProperties(); |
获取属性名称
1 | using System.Reflection; |
根据属性名获取某一属性
1 | PropertyInfo p = t.GetProperty("Id"); |
设置某一属性的值
1 | MyClass my = new MyClass(); |
应用:
1 | public T Test<T>() where T: class, new() |