views:

25

answers:

1

I need to get type of an object in base type. However I can't use BaseType, because I can't know how many levels of types the object has.

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();
    }
}

Is it possible to have in myType Base type?

A: 
public DoAThing()
    {
        Type myType = typeof(Base);
    }
Preet Sangha
I only just now realized how simple this is :) I guess I'm too tired to continue.
mnn
lol - we all do this. That's why its important to ask questions no matter how trivial you may think they are.
Preet Sangha
I was afraid it would require some mumbo-jumbo magic with Reflection :) Thanks, anyway.
mnn