25 lines
1014 B
HTML
25 lines
1014 B
HTML
<div>//自定义的类</div>
|
|
<div>model m = new model();</div>
|
|
<div> </div>
|
|
<div>//取得类的Type实例</div>
|
|
<div>//Type t = typeof(model); </div>
|
|
<div> </div>
|
|
<div>//取得m的Type实例</div>
|
|
<div>Type t = m.GetType(); </div>
|
|
<div> </div>
|
|
<div>string className = t.Name +"\r\n"; </div>
|
|
<div> </div>
|
|
<div>//获取所有方法 </div>
|
|
<div>System.Reflection.MethodInfo[] methods = t.GetMethods(); </div>
|
|
<div> </div>
|
|
<div>//获取所有成员</div>
|
|
<div>System.Reflection.MemberInfo[] members = t.GetMembers(); </div>
|
|
<div> </div>
|
|
<div>//获取所有属性 </div>
|
|
<div>System.Reflection.PropertyInfo[] properties = t.GetProperties(); </div>
|
|
<div> </div>
|
|
<div>//取得类的属性名并获取属性值</div>
|
|
<div>foreach (System.Reflection.PropertyInfo s in t.GetProperties())</div>
|
|
<div>{</div>
|
|
<div> className += s.Name + ":" + m.GetType().GetProperty(s.Name).GetValue(m, null).ToString() + "\r\n";</div>
|
|
<div>}</div> |