TypeView例子。
using System;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace Sample
{
public class MainEntryPoint
{
static StringBuilder outputText = new StringBuilder();
static int Main(string[] args)
{
Type t = typeof(double);
AnalyzeType(t);
MessageBox.Show(outputText.ToString(), "Analysis of type" + t.Name);
Console.ReadLine();
return 0;
}
static void AnalyzeType(Type t)
{
AddToOutput("Type Name:" + t.Name);
AddToOutput("FullName:" + t.FullName);
AddToOutput("Namespace:" + t.Namespace);
Type tBase = t.BaseType;
if(tBase != null)
{
AddToOutput("Base Type:" + tBase);
}
Type tUnderlyingSystem = t.UnderlyingSystemType;
if(tUnderlyingSystem != null)
{
AddToOutput("UnderlyingSystem Type:" + tUnderlyingSystem);
}
AddToOutput("\nPublic Mambers:");
MemberInfo[] members = t.GetMembers();
foreach(MemberInfo member in members)
{
AddToOutput("MemberInfo " + member.MemberType+" "+member.Name);
}
}
static void AddToOutput(string text)
{
outputText.Append("\n"+text);
}
}
}