问题:当我用Customer testAssembly = new Customer();反射Customer类信息时没有问题;
当我把Customer类生成一个类库Test.dll,用Assembly testAssembly = Assembly.LoadFile("Test.dll");时,
得到的method为空,这是为什么? static void Main(string[] args)
{
//Assembly testAssembly = Assembly.LoadFile("Test.dll"); Customer testAssembly = new Customer(); Type t = testAssembly.GetType(); MethodInfo method = t.GetMethod("DoSomething");
if (method != null)
{
Console.WriteLine("Abstract: {0}, Visible to Assembly: {1}, Constructor: {2}, Sealed: {3}",
method.IsAbstract,
method.IsAssembly,
method.IsConstructor,
method.IsFinal);
}
}
} class Customer
{
private int privData = 12; public int PubData
{
get { return privData; }
set { privData = value; }
} public void DoSomething()
{
int z = 21;
string localString = "local";
}
}
当我把Customer类生成一个类库Test.dll,用Assembly testAssembly = Assembly.LoadFile("Test.dll");时,
得到的method为空,这是为什么? static void Main(string[] args)
{
//Assembly testAssembly = Assembly.LoadFile("Test.dll"); Customer testAssembly = new Customer(); Type t = testAssembly.GetType(); MethodInfo method = t.GetMethod("DoSomething");
if (method != null)
{
Console.WriteLine("Abstract: {0}, Visible to Assembly: {1}, Constructor: {2}, Sealed: {3}",
method.IsAbstract,
method.IsAssembly,
method.IsConstructor,
method.IsFinal);
}
}
} class Customer
{
private int privData = 12; public int PubData
{
get { return privData; }
set { privData = value; }
} public void DoSomething()
{
int z = 21;
string localString = "local";
}
}
if (method != null)
{
Console.WriteLine("Abstract: {0}, Visible to Assembly: {1}, Constructor: {2}, Sealed: {3}",
method.IsAbstract,
method.IsAssembly,
method.IsConstructor,
method.IsFinal);
}
这里需要绝对路径