zoukankan      html  css  js  c++  java
  • 反射理解

     Assembly asm = Assembly.Load("ApiFun");//加载程序集
                Type[] typeInfo = asm.GetTypes();//获取程序集类型数组
                foreach (Type types in typeInfo)
                {
                    Console.WriteLine("程序集中类型:{0}", types.Name);
                    MethodInfo[] mInfo = types.GetMethods();
                    foreach (MethodInfo information in mInfo)
                    {
                        Console.WriteLine("此类型所有的方法:{0}", information.Name);
                    }
                    Console.WriteLine("\n");
                }
                Console.WriteLine("\n\n");
                Console.WriteLine("开始!");

                Type inType = typeof(ThreadTest);
                object obj = Activator.CreateInstance(inType);
                string[] s = { "mlg" };//方法的参数
                object objName = Activator.CreateInstance(inType, s);//创建指定类型的实例

                MethodInfo methodInfo = inType.GetMethod("ThreadMethod");//根据字符串来获取方法信息
                // methodInfo.Invoke(obj, null);
                methodInfo.Invoke(objName, null);//调用类型中的方法
                Console.ReadLine();

  • 相关阅读:
    70.BOM
    69.捕获错误try catch
    68.键盘事件
    523. Continuous Subarray Sum
    901. Online Stock Span
    547. Friend Circles
    162. Find Peak Element
    1008. Construct Binary Search Tree from Preorder Traversal
    889. Construct Binary Tree from Preorder and Postorder Traversal
    106. Construct Binary Tree from Inorder and Postorder Traversal
  • 原文地址:https://www.cnblogs.com/leischen/p/2729022.html
Copyright © 2011-2022 走看看