【发布时间】:2011-10-10 07:23:37
【问题描述】:
例子:
namespace MyProgram.Testing
{
public class Test1
{
public void TestMethod()
{
String actualType = this.GetType().FullName.ToString();
return;
}
public static String GetInheritedClassName()
{
return System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName;
}
}
public class Test2 : Test1
{
}
public class Test3
{
String test2ClassName = Test2.GetInheritedClassName();
}
}
无论如何,我希望它返回“MyProgram.Testing.Test2”,但 Test2.GetInheritedClassName() 返回“MyProgram.Testing.Test1”。我必须在该静态类中添加什么才能使其返回(如果可能)?
【问题讨论】:
-
我认为这是不可能的,静态成员总是存在于定义它们的基类上。但我相信其他人可以提供更具技术性的答案。
标签: c# reflection static classname