反射
Type t = typeof(People); 2. Console.WriteLine("----------------Method------------------"); 3. MethodInfo[] methods = t.GetMethods( ); 4. foreach (MethodInfo method in methods) 5. { 6. Console.WriteLine("Method:" + method); 7. 8. //Console.WriteLine(method); 9. //Console.WriteLine("返回值:" + method.ReturnParameter); 10. } 11. Console.WriteLine("---------------Field-------------------"); 12. FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance|BindingFlags.Static); 13. 14. foreach (FieldInfo field in fields) 15. { 16. Console.WriteLine("Field:" + field); 17. } 18. 19. Console.WriteLine("--------------Member--------------------"); 20. MemberInfo[] members = t.GetMembers(); 21. 22. foreach (MemberInfo member in members) 23. { 24. Console.WriteLine("Member:" + member); 25. } 26. Console.WriteLine("--------------Property--------------------"); 27. PropertyInfo[] properties = t.GetProperties( ); 28. 29. foreach (PropertyInfo property in properties) 30. { 31. Console.WriteLine("Property:" + property); 32. } 33. Console.WriteLine("--------------Constructor--------------------"); 34. ConstructorInfo[] constructors = t.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance); 35. 36. foreach (ConstructorInfo constructor in constructors) 37. { 38. Console.WriteLine("Constructor:" + constructor); 39. }
posted on 2016-01-27 13:02 HOT SUMMER 阅读(153) 评论(0) 编辑 收藏 举报