zoukankan      html  css  js  c++  java
  • 反射

    反射是为了程序在运行时程序能获取到一些关于程序集(assembly),class,method,property的一些信息的 这样的机制

    反射相当于一种进程,这种进程可以修改自己机构和行为的一种能力.

    string s = "Hello Reflection";
                Type t = s.GetType();
                Console.WriteLine(t.FullName);
                Type t2 = Type.GetType("system.string", false, true);
                Console.WriteLine(t2.FullName);
                Type t3 = typeof(string);
                Console.WriteLine(t3.FullName);
                Console.ReadLine();
            static void Main(string[] args)
            {
                string s = "Hello Reflection";
                Type t = s.GetType();
                Console.WriteLine(t.FullName);
                Type t2 = Type.GetType("system.string", false, true);
                Console.WriteLine(t2.FullName);
                Type t3 = typeof(string);
                Console.WriteLine(t3.FullName);
                //GetMothods(t3);
                Console.WriteLine(t3.GetMethod("Copy"));
                Console.ReadLine();
    
            }
            public static void GetMothods(Type t)
            {
                MethodInfo[] mti = t.GetMethods();
                foreach (MethodInfo m in mti)
                {
                    Console.WriteLine("type:{0}", m.Name);
                }
            }

    //getmethod getmethods gettype getproperty 都是反射

  • 相关阅读:
    redhat 5 中文乱码
    生成树
    交换机端口模式
    链路聚合
    AP注册
    信息收集
    Python 25 Django跨域请求
    Python 24 Django之csrf中间件
    Python 23 Django基础
    Python 21 Flask(三)第三方组件
  • 原文地址:https://www.cnblogs.com/handsomer/p/4554087.html
Copyright © 2011-2022 走看看