TypeView.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Text;
  3. using System.Windows.Forms;
  4. using System.Reflection;
  5. namespace Wrox.ProCSharp.TypeView
  6. {
  7.    class MainClass
  8.    {
  9.       static void Main()
  10.       {
  11.          // modify this line to retrieve details of any
  12.          // other data type
  13.          Type t = typeof(double);
  14.    
  15.          AnalyzeType(t);
  16.          MessageBox.Show(OutputText.ToString(), "Analysis of type " + t.Name);
  17.          Console.ReadLine();
  18.       }
  19.       static void AnalyzeType(Type t)
  20.       {
  21.          AddToOutput("Type Name:  " + t.Name);
  22.          AddToOutput("Full Name:  " + t.FullName);
  23.          AddToOutput("Namespace:  " + t.Namespace);
  24.          Type tBase = t.BaseType;
  25.          if (tBase != null)
  26.             AddToOutput("Base Type:" + tBase.Name);
  27.          Type tUnderlyingSystem = t.UnderlyingSystemType;
  28.          if (tUnderlyingSystem != null)
  29.             AddToOutput("UnderlyingSystem Type:" + tUnderlyingSystem.Name);
  30.          AddToOutput("nPUBLIC MEMBERS:");
  31.          MemberInfo [] Members = t.GetMembers();
  32.          foreach (MemberInfo NextMember in Members)
  33.          {
  34.             AddToOutput(NextMember.DeclaringType + " " + NextMember.MemberType +
  35.                " " + NextMember.Name);
  36.          }
  37.       }
  38.       static void AddToOutput(string Text)
  39.       {
  40.          OutputText.Append("n" + Text);
  41.       }
  42.       static StringBuilder OutputText = new StringBuilder(500);
  43.    }
  44. }