public static Type GetRootType(this Type type)
{
// Recurse through types until you reach a base type of "System.Object" or "System.MarshalByRef".
#if MONO
// TODO: Test with Mono to see if type comparison now works as expected
if ((object)type.BaseType == null || type.BaseType.FullName.Equals("System.Object", StringComparison.Ordinal) || type.BaseType.FullName.Equals("System.MarshalByRefObject", StringComparison.Ordinal))
#else
if ((object)type.BaseType == null || type.BaseType == typeof(object) || type.BaseType == typeof(MarshalByRefObject))
#endif
return type;
return GetRootType(type.BaseType);
}
}