public IEqualityComparer <T> CreateComparer <T>(IEqualityComparerSource source)
        {
            var nonGenericComparer = new FieldsEqualityComparer(source);
            var genericComparer    = new GenericEqualityComparerAdapter <T>(nonGenericComparer);

            return(genericComparer);
        }
Exemplo n.º 2
0
        public IEqualityComparer <T> CreateComparer <T>(IEqualityComparerSource source)
        {
            var valueType = typeof(T);

            foreach (var implementedInterface in valueType.GetInterfaces())
            {
                if (IsGenericIEquatableInterface(implementedInterface, valueType))
                {
                    var genericComparerType        = typeof(EqualsEqualityComparer <>).MakeGenericType(valueType);
                    var genericComparerConstructor = genericComparerType.GetConstructor(new Type[0]);
                    var genericComparer            = (IEqualityComparer <T>)genericComparerConstructor.Invoke(new object[0]);
                    return(genericComparer);
                }
            }

            if (OverridesEquals(valueType))
            {
                var nonGenericComparer = new EqualsEqualityComparer();
                var genericComparer    = new GenericEqualityComparerAdapter <T>(nonGenericComparer);
                return(genericComparer);
            }

            return(_next.CreateComparer <T>(source));
        }