J
james
AssumeSomeFunctionExists ( Type someType, Type someOtherType)
{
// I want to know
// 1. Are the two the same Type
// 2. Are they members of the same Inheritance branch
// a) Is someType a subclassof someOtherType or
// b) Is someOtherType a subclass of someType
// This code does work but...
if ( someType.Equals(someOtherType) ||
someType.IsSubclassOf(someOtherType) || someOtherType.IsSubclassOf (
someType) )
// ... doSomething
}
Now I know about the "is" operator but that only works with an object
instance like
if ( anObject is SomeClass )
which does exactly what I want but I cannot use the "is" operator to compare
two Type objects
And I know about IsSubclass() but that does not return 'true' when the two
are exactly the same. So I
do what I show in the above code which takes three comparisons. Am I
missing a shortcut way to do this?
Thanks a lot in advance
JIM
{
// I want to know
// 1. Are the two the same Type
// 2. Are they members of the same Inheritance branch
// a) Is someType a subclassof someOtherType or
// b) Is someOtherType a subclass of someType
// This code does work but...
if ( someType.Equals(someOtherType) ||
someType.IsSubclassOf(someOtherType) || someOtherType.IsSubclassOf (
someType) )
// ... doSomething
}
Now I know about the "is" operator but that only works with an object
instance like
if ( anObject is SomeClass )
which does exactly what I want but I cannot use the "is" operator to compare
two Type objects
And I know about IsSubclass() but that does not return 'true' when the two
are exactly the same. So I
do what I show in the above code which takes three comparisons. Am I
missing a shortcut way to do this?
Thanks a lot in advance
JIM