例子:C#類名檢索在靜態方法
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」。我必須把這個靜態類放到哪裏才能返回(如果可能的話)?
我不認爲這是可能的,靜態成員總是活在定義它們的基類上。但我相信別人可以提供更多技術性的答案。 – CodingGorilla