C#反射结合System.Type类实例

namespace myNameSpace { class Program { static void Main(string[] args) { /* TypeView示例 star */ Type t = typeof(myClass); AnalyzeType(t); /* TypeView示例 end */ Console.ReadLine(); } //定义嵌套类myClass class myClass { private string _my; public string My { get { return _my; } set { _my = value; } } } //通过System.Type类提供的方法分析类中的成员信息 static void AnalyzeType(Type t) { //当前成员名 Console.WriteLine(t.Name); //myClass //完全限定名,包含命名空间 Console.WriteLine(t.FullName); //myNameSpace.myClass //命名空间 Console.WriteLine(t.Namespace); //myNameSpace //获取直接继承的类 Type tBase = t.BaseType; if (tBase != null) { Console.WriteLine(tBase.Name); //Object } //该类公共语言运行库提供的类型 Type tUnderlyingSystem = t.UnderlyingSystemType; if (tUnderlyingSystem != null) { Console.WriteLine(tUnderlyingSystem.Name); //myClass } //返回当前类型的所有公共成员数组 MemberInfo[] Members = t.GetMembers(); //遍历数组,迭代每个成员信息 foreach (MemberInfo NextMember in Members) { Console.WriteLine(NextMember.DeclaringType + "," + NextMember.MemberType + "," + NextMember.Name); } } } }

你可能感兴趣的:(String,C#,null,Class,语言)