反射的用法1

反射用到的几个类:

1.代表程序集:System.Reflection.Assembly

2.代表类与结构:System.Reflection.Type

3.代表方法:System.Reflection.MethodInfo

4.代表字段:System.Reflection.FieldInfo

5.代表方法参数:System.Reflection.ParameterInfo

例子:

using System;
using System.Reflection;

namespace ReflectionConsoleApplication1
{
    
class Program
    {
        
static void Main(string[] args)
        {
            Assembly assembly 
= Assembly.GetExecutingAssembly();
            
foreach(Type type in assembly.GetTypes())
            {
                Console.WriteLine (
"Class:"+type.ToString());
                
foreach (MethodInfo method in type.GetMethods())
                {
                    Console.WriteLine(
"method:" + method.ToString());
                    
foreach (ParameterInfo param in method.GetParameters())
                        Console.WriteLine(
"Parameter:"+param.ToString ());
                }
            }
            Console.ReadLine();
        }
    }
}
原文地址:https://www.cnblogs.com/ringwang/p/1897051.html