Given
classA {}
Type typeA = typeof(ClassA);
1) isn't
checkType.IsSubclassOf(typeA)
going to always give the same results as
typeInheritsFrom(checkType, typeA)
given
bool typeInheritsFrom(Type typeToCheck, Type checkAgainst)
{
Type baseType = typeToCheck;
while (baseType != null)
{
if(baseType == checkAgainst)
return true;
baseType = baseType.BaseType;
}
}
2) Wouldn't
if (baseType is checkAgainst)
be a little clearer in C# than
if (baseType == checkAgainst)
even though I think it would work out to the same result.
Daniel Billingsley - 07 May 2004 13:30 GMT
I was trying to write the original message too quickly I think -
I should have included the detail that checkType is always a class.
> Given
> classA {}
[quoted text clipped - 23 lines]
> if (baseType == checkAgainst)
> even though I think it would work out to the same result.
Mattias Sj?gren - 07 May 2004 19:47 GMT
Daniel,
>1) isn't
>
>checkType.IsSubclassOf(typeA)
>
>going to always give the same results as
>typeInheritsFrom(checkType, typeA)
Almost. typeInheritsFrom would return true for
typeInheritsFrom(typeof(ClassA), typeof(ClassA))
but
typeof(ClassA).IsSubclassOf(typeof(ClassA))
returns false.
>2) Wouldn't
>if (baseType is checkAgainst)
>be a little clearer in C# than
>if (baseType == checkAgainst)
>even though I think it would work out to the same result.
if (baseType is checkAgainst)
isn't valid code.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.