zoukankan      html  css  js  c++  java
  • C#反射取得类的字段与方法信息

    using System;
    using System.Reflection;
    namespace TestReflect
    {
        class BaseClass
        {
            public int MyFieldBase=1;
            public int getfieldBase()
            { return MyFieldBase; }
        }
        class DerivedClass : BaseClass
        {
            public int MyFieldDerived=2;
            public int getfieldBase(int i)
            { return MyFieldDerived; }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Type tbc=typeof(DerivedClass);
                Console.WriteLine("类型名:{0}.", tbc.Name);
                Console.WriteLine("它有如下字段:");
                FieldInfo[] fi = tbc.GetFields();
                MethodInfo[] me = tbc.GetMethods();
                foreach (var f in fi)
                {
                    Console.WriteLine("字段类型{0},字段名{1}",f.FieldType,f.Name);
                }
                Console.WriteLine();
                Console.WriteLine("它有如下方法:");
                foreach (var f in me)
                {
                    Console.WriteLine("返回值类型:{0},函数名:{1}",f.ReturnType ,f.Name);
                    ParameterInfo[] paramsInfo = f.GetParameters();
                    foreach (var p in paramsInfo)
                    {
                        Console.WriteLine("参数类型:{0}参数名:{1}",p.ParameterType,p.Name);
                    }
                    Console.WriteLine();
                }
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    HDU-4027-Can you answer these queries?
    Python的多协程(三种简单生成多协程方法)
    关于django 如何实现简单api的restful 接口
    flask 框架服务原理
    DVWA渗透测试环境搭建
    装饰器 python 你也可以叫语法糖
    websocket python实现原理
    robotframe 自定义开发库
    mysql linux 安装卸载
    python+jenkins 构建节点环境编译器配置问题
  • 原文地址:https://www.cnblogs.com/sulong/p/4792877.html
Copyright © 2011-2022 走看看