C# 在不知道其派生类型的情况下检索基类型的类型

C# 在不知道其派生类型的情况下检索基类型的类型,c#,reflection,inheritance,C#,Reflection,Inheritance,我需要在基类型中获取对象的类型。但是我不能使用BaseType,因为我不知道对象有多少级别的类型 class Base { public string Name { get set; } public DoAThing() { Type myType = GetType(); // returns Derived } } class Derived : Base { public int Age { get; set; } p

我需要在基类型中获取对象的类型。但是我不能使用BaseType,因为我不知道对象有多少级别的类型

class Base
{
    public string Name { get set; }

    public DoAThing()
    {
        Type myType = GetType(); // returns Derived
    }
}

class Derived : Base
{
    public int Age { get; set; }

    public void DoSomething()
    {
        DoAThing();
    }
}

有没有可能在myType中加入基本类型?

我刚刚才意识到这是多么简单:)我想我太累了,不能继续了。哈哈-我们都这么做。这就是为什么问问题很重要的原因,不管你认为这些问题多么琐碎。我担心这需要一些复杂的魔法和思考:)无论如何,谢谢。休息一下,明天再看:)现在,我知道,怎么做,但我还是要休息一下:)
public DoAThing()
    {
        Type myType = typeof(Base);
    }