Can anyone help me? I can't figure out what I am doing wrong but it seems like there will be a simple solution:
Normally you can use is
like this:
if (theObject is MyClass) ...
but if you want to specify the type it checks for at runtime this doesnt compile
Type theType = ...
if (theObject is theType) ...
I tried doing this:
if (theObject.GetType() == theType) ...
But that only works if theType
is that exact type and doesnt take into account inheritance like the is
statement does
I'm sure a solution exists (probably using generics) but I can't think of one right now (its the kind of thing you suddenly remember how to do the moment you click 'Post')