private static bool IsObjectEqualsMethod(MethodInfo m)
{
return m.Name == "Equals"
&& m.GetBaseDefinition().DeclaringType.Equals(typeof(object));
}
public static bool OverridesEqualsMethod(this Type type)
{
var equalsMethod = type.GetMethods()
.Single(IsObjectEqualsMethod);
return !equalsMethod.DeclaringType.Equals(typeof(object));
}
Note that this indicates whether the object.Equalsinheritance hierarchy has been overridden anywhere type. To determine if an override is declared for the type itself, you can change the condition to
equalsMethod.DeclaringType.Equals(type)
EDIT: Clean up the method IsObjectEqualsMethod.
source
share