关于反射

  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);

}

}

 

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

 

posted @ 2012-05-29 11:48  咸鱼公子  Views(188)  Comments(0Edit  收藏  举报