zoukankan      html  css  js  c++  java
  • 关于反射

      public void RefTest()
            {

                MessageBox.Show("fu");
            }
            public void RefStaticTest()
            {

                MessageBox.Show("fu");
            }
          
            private void button4_Click(object sender, EventArgs e)
            {
                Assembly asm = Assembly.Load("ExcelTOXML");

                Type tp = asm.GetType("ExcelTOXML.Form1");

             // var q = tp.GetMembers();
                System.Reflection.MethodInfo method = tp.GetMethod("RefTest");//方法的名称

                  object obj = asm.CreateInstance("ExcelTOXML.Form1");
                  method.Invoke(obj, null);//调用方法

             }

    -------------------------

    ----------------------

    public class HelloWorld : MarshalByRefObject

    {
        public HelloWorld()
        {
           
        }

        public void Task1(string s)
        {
        Console.WriteLine("Task1 " + s);
        }
    }

    // File: Invoke.cs

    using System;
    using System.Reflection;
    using System.Runtime.Remoting;

    public class InvokeMethod
    {

    public static void Main( String[] argv )

    {

    AppDomainSetup info = new AppDomainSetup();
    info.ApplicationBase = "http://www.cnblogs.com/qq4004229/admin/file:///" + System.Environment.CurrentDirectory;
    AppDomain dom = AppDomain.CreateDomain("RemoteDomain", null, info);
    Assembly asm =Assembly.Load("HelloWorld2");
    Object obj=asm.CreateInstance("HelloWorld");
    MethodInfo minfo=asm.GetType("HelloWorld").GetMethod("Task1") ;
    minfo.Invoke(obj,new string []{"Task 1"});
    AppDomain.Unload(dom);

    }

    }

    ---------------------------------------------------------------------

  • 相关阅读:
    java学习之—栈
    java中的a++与++a的区别
    java学习之—数组的曾删改查
    Mybatis #{ } 和 ${ } 区别
    详解Windows不重启使环境变量修改生效(经典)
    laravel artisan常用命令
    Laravel 出现 No application encryption key has been specified.
    springboot的几种启动方式
    Angular 服务的简单使用
    Angular-1.6 路由 简单使用
  • 原文地址:https://www.cnblogs.com/qq4004229/p/2523737.html
Copyright © 2011-2022 走看看