zoukankan      html  css  js  c++  java
  • 反射学习

    namespace ReflectionTest
    {
       public class test
        {
           public void writeString(string s)
           {
               Console.WriteLine("writeString:" + s);
           }
           public static void staticWrite(string s)
           {
               Console.WriteLine("staticString:" + s);
           }
           public string addString(string s)
           {
               return s + s;
           }
        }
    }

    调用    记得调用  using System.Reflection;

         static void Main(string[] args)
            {
                Assembly dll = Assembly.LoadFile(@"C:UsersFoxDesktop反射学习ReflectionTestinDebugReflectionTest.dll");
                Type type = dll.GetType("ReflectionTest.test");
                Console.WriteLine(type.FullName);
                MethodInfo mi = type.GetMethod("writeString");
                object obj = dll.CreateInstance("ReflectionTest.test");
                Object[] oo = new Object[] { "wq" };
                //调用非静态方法 第一个参数得为其创建一个实例
                mi.Invoke(obj, oo);
                mi = type.GetMethod("staticWrite");
                //调用静态方法 第一个参数可以为NULL
                mi.Invoke(null, oo);
                Console.ReadLine();
            }
    

      

  • 相关阅读:
    计算机视觉(四)
    计算机视觉(三)
    计算机视觉(二)
    计算机视觉(一)
    基于opencv3实现运动物体识别
    tensorRT程序设计框架_4
    Cuda程序的设计-2
    神经网络的快速体验
    STL简介_18
    函数模板-17
  • 原文地址:https://www.cnblogs.com/Rock-Lee/p/3318695.html
Copyright © 2011-2022 走看看