GetType() of base class

  • Thread starter Thread starter Zeng
  • Start date Start date
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!
 
Back
Top