using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace AAAA
{
class Program
{
static void Main(string[] args)
{
string path = "AAAA";
string ClassName = path + "." + "MethodA";
ITest t = (ITest)Assembly.Load(path).CreateInstance(ClassName);
t.Run();
Console.ReadKey();
}
} public class MethodA : ITest
{
public void Run()
{
Console.WriteLine(this.GetType().ToString());
}
} public class MethodB : ITest
{
public void Run()
{
Console.WriteLine(this.GetType().ToString());
}
} public interface ITest
{
void Run();
}
}Assemble name: AAAA Namespace : AAAA以上可以正常执行,但是如果 Assemble name 和 Namespace 不一样 ,反射就会出错,不知道为什么?请高手们给答案,
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace AAAA
{
class Program
{
static void Main(string[] args)
{
string path = "AAAA";
string ClassName = path + "." + "MethodA";
ITest t = (ITest)Assembly.Load(path).CreateInstance(ClassName);
t.Run();
Console.ReadKey();
}
} public class MethodA : ITest
{
public void Run()
{
Console.WriteLine(this.GetType().ToString());
}
} public class MethodB : ITest
{
public void Run()
{
Console.WriteLine(this.GetType().ToString());
}
} public interface ITest
{
void Run();
}
}Assemble name: AAAA Namespace : AAAA以上可以正常执行,但是如果 Assemble name 和 Namespace 不一样 ,反射就会出错,不知道为什么?请高手们给答案,
ITest _Object = (ITest)System.Activator.CreateInstance(_OjbectType);
Namespace : BBBB Class MethodA你获取到BBBB的Type 问题就解决了.按你的方法..
ITest t = (ITest)Assembly.Load("AAAA").CreateInstance("BBBB.MethodA");
注意子类不是.是 +
ITest _Object = (ITest)System.Activator.CreateInstance(_OjbectType); 这样做有什么优点吗?