Assembly clientAssembly = Assembly.LoadFrom( Application.StartupPath + @"\BuyerClient.exe" );
Type type=assembly.GetType(FormPurchaseDetail类型的全名);
MethodInfo methodInfo=type.GetMethod("Show");
object instance = Activator.CreateInstance(type,new Object[]{"23320"});
methodInfo.Invoke(instance,new object[]{});
Type type=assembly.GetType(FormPurchaseDetail类型的全名);
MethodInfo methodInfo=type.GetMethod("Show");
object instance = Activator.CreateInstance(type,new Object[]{"23320"});
methodInfo.Invoke(instance,new object[]{});
using System.Reflection;namespace L
{
public class A
{
string _var;
public A()
{
_var="Default";
}
public A(string v)
{
_var=v;
}
public string GetVar()
{
return _var;
}
}
public class L
{
static void Main()
{
Assembly asm=typeof(A).Assembly;
ConstructorInfo ci;
A a; ci=typeof(A).GetConstructor(new Type[0]);
a=ci.Invoke(new object[0]) as A;
Console.WriteLine(a.GetVar()); ci=typeof(A).GetConstructor(new Type[]{typeof(string)});
a=ci.Invoke(new object[]{"TheVar"}) as A;
Console.WriteLine(a.GetVar());
}
}
}
这样也不行的,参数不匹配:(
Type type=clientAssembly.GetType("test1.Form4");
MethodInfo methodInfo=type.GetMethod("Show");
object instance = Activator.CreateInstance(type,new Object[]{"23320"});
methodInfo.Invoke(instance,new object[]{});
/////////////////////////////////////
private string inPurchaseId;
public Form4(string inPurchaseId)
{
InitializeComponent();
MessageBox.Show(inPurchaseId);
}