From: Michael D. <mik...@us...> - 2004-09-27 01:48:26
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6879/NHibernate/Util Modified Files: ReflectHelper.cs Log Message: fixed OverridesEquals to actually work. Index: ReflectHelper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Util/ReflectHelper.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ReflectHelper.cs 13 Sep 2004 04:51:05 -0000 1.15 --- ReflectHelper.cs 27 Sep 2004 01:48:16 -0000 1.16 *************** *** 5,9 **** namespace NHibernate.Util { ! public sealed class ReflectHelper { --- 5,11 ---- namespace NHibernate.Util { ! /// <summary> ! /// Helper class for Reflection related code. ! /// </summary> public sealed class ReflectHelper { *************** *** 13,44 **** private static System.Type[] NoClasses = new System.Type[0]; private static System.Type[] Object = new System.Type[] { typeof(object) }; ! private static MethodInfo ObjectEquals; ! ! static ReflectHelper() { - MethodInfo eq; try { ! eq = typeof(object).GetMethod("Equals", BindingFlags.Instance | BindingFlags.Public ); } ! catch (Exception e) { ! throw new AssertionFailure("Could not find Object.Equals()", e); } ! ObjectEquals = eq; ! } ! ! public static bool OverridesEquals(System.Type clazz) ! { ! MethodInfo equals; ! try ! { ! equals = clazz.GetMethod("Equals"); ! } ! catch (Exception) { return false; } ! return !ObjectEquals.Equals(equals); } --- 15,52 ---- private static System.Type[] NoClasses = new System.Type[0]; private static System.Type[] Object = new System.Type[] { typeof(object) }; ! ! /// <summary> ! /// Determine if the specified <see cref="System.Type"/> overrides the ! /// implementation of Equals from <see cref="Object"/> ! /// </summary> ! /// <param name="clazz">The <see cref="System.Type"/> to reflect.</param> ! /// <returns><c>true</c> if any type in the heirarchy overrides Equals(object).</returns> ! public static bool OverridesEquals(System.Type clazz) { try { ! MethodInfo equals = clazz.GetMethod("Equals", new System.Type[] { typeof(object) }); ! if( equals==null ) ! { ! return false; ! } ! else ! { ! // make sure that the DeclaringType is not System.Object - if that is the ! // declaring type then there is no override. ! return !equals.DeclaringType.Equals( typeof(object) ); ! } } ! catch( AmbiguousMatchException ) { ! // an ambigious match means that there is an override and it ! // can't determine which one to use. ! return true; } ! catch (Exception ) { return false; } ! } |