Example #1
0
        internal static object GetComparer(RuntimeTypeHandle t)
        {
            RuntimeTypeHandle comparerType;
            RuntimeTypeHandle openComparerType     = default(RuntimeTypeHandle);
            RuntimeTypeHandle comparerTypeArgument = default(RuntimeTypeHandle);

            if (RuntimeAugments.IsNullable(t))
            {
                RuntimeTypeHandle nullableType = RuntimeAugments.GetNullableType(t);
                if (ImplementsIComparable(nullableType))
                {
                    openComparerType     = typeof(NullableComparer <>).TypeHandle;
                    comparerTypeArgument = nullableType;
                }
            }
            if (EqualityComparerHelpers.IsEnum(t))
            {
                openComparerType     = typeof(EnumComparer <>).TypeHandle;
                comparerTypeArgument = t;
            }

            if (openComparerType.Equals(default(RuntimeTypeHandle)))
            {
                if (ImplementsIComparable(t))
                {
                    openComparerType     = typeof(GenericComparer <>).TypeHandle;
                    comparerTypeArgument = t;
                }
                else
                {
                    openComparerType     = typeof(ObjectComparer <>).TypeHandle;
                    comparerTypeArgument = t;
                }
            }

            bool success = RuntimeAugments.TypeLoaderCallbacks.TryGetConstructedGenericTypeForComponents(openComparerType, new RuntimeTypeHandle[] { comparerTypeArgument }, out comparerType);

            if (!success)
            {
                Environment.FailFast("Unable to create comparer");
            }

            return(RuntimeAugments.NewObject(comparerType));
        }
Example #2
0
 public sealed override bool Equals(T x, T y)
 {
     return(EqualityComparerHelpers.EnumOnlyEquals(x, y));
 }