C#_输出程序集

本文介绍了一个使用C#反射技术解析程序集内部结构的方法,包括获取类名、构造函数及方法等详细信息。通过实例演示了如何遍历并显示程序集中的所有公共方法及其返回类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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(){

}

}

运行后输出程序集内的所有公共方法和返回值类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值