GetType() of base class

Z

Zeng

I'm just wondering if there is way to detect if an object (Object type)
points to an instance of a a derived class of a given base class. For
example,

class Base{...}

class DerivedA : Base{...}
class DerivedB : Base(...}
class DerivedAA : DerivedA{...}

class X{}
bool IsTypeBase( Object obj )
{
//return true if obj is type DerivedA, DerivedB, DerivedAA, return false
if X
}

I need to do this because in my code before assigning an object to datarow's
int field, if the object is an enum I need to convert enum to int (otherwise
it won't work) but Object.GetType() would return the exact type of specific
enum and there can be many enum types around.

Anyone knows how to do this?
Thanks!
 
L

lugi

you can just write: xxx is Base


bool IsTypeBase( Object obj )
{
return (obj is Base);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top