zoukankan      html  css  js  c++  java
  • 反射的用法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();
            }
        }
    }
  • 相关阅读:
    发现IDEA两个超级好用的工具
    事务的传播属性
    Java 单元测试PowerMockito
    Spirng源码学习 第一天
    2021年 每日打卡
    Spring源码调试环境搭建成功
    practice
    学习进度表
    报数
    负二进制转换
  • 原文地址:https://www.cnblogs.com/ringwang/p/1897051.html
Copyright © 2011-2022 走看看