There is a bit of a problem with this idea, since each object (and, indeed, each type) has a common base class Object. What you need to determine is how far you inherit the inheritance chain (regardless of whether they are the same or have the same immediate parent, or one of them is the direct parent of the other, etc.) And checks this way. IsAssignableFrom is useful for determining type compatibility with each other, but will not be fully set if they have the same parent (if that is what you need).
If your strict criteria are that the function should return true if ...
- Types are identical
- One type is the parent (immediate or another) of the other
- Two types have the same immediate parent
you can use
private bool AreSame(Type a, Type b) { if(a == b) return true;
Adam Robinson Apr 02 '09 at 4:28 2009-04-02 04:28
source share