using System;
using System.Reflection;
class DebugObjectType
{
internal void FunctionType(object o)
{
//类型
Type objType = o.GetType();
//程序集构造块(字段、方法)
Assembly objAssembly = objType.Assembly;
//将每个类型的内部构造块,储存到数组中
Type[] types = objAssembly.GetTypes();
//遍历
foreach (Type type in types)
{
Console.WriteLine("class's name:" + type.FullName);
ConstructorInfo[] myConstructor = type.GetConstructors();
Show(myConstructor);
MethodInfo[] myMethod = type.GetMethods();
Show(myMethod);
//PropertyInfo myProperty = type.GetProperties();
//Show(myProperty);
}
Console.ReadLine();
}
private void Show(object[] myObj)
{
int i = 0;
foreach (object var in myObj)
{
i++;
Console.WriteLine(var.ToString() +"+++++++++"+ i);
}
Console.WriteLine("-------------------");
}
}
class MyClass{
static void Main(){
ClassA a = new ClassA();
DebugObjectType debug = new DebugObjectType();
debug( a );
}
}
class ClassA{
public int i;
private int j;
public void Function(){
}
}
运行后输出程序集内的所有公共方法和返回值类型