예제 #1
0
 internal ISet(HashFunction <_type> aFunction, EqualityFunction <_type> aEquality)
 {
     mFunction = aFunction;
     mEquality = aEquality;
     mModulo   = Capacity - 1;
     mBuckets  = new Bucket[Capacity];
 }
예제 #2
0
파일: FileMode.cs 프로젝트: kkl713/GitSharp
 public override int GetHashCode()
 {
     unchecked
     {
         return((EqualityFunction.GetHashCode() * 397) ^ ObjectType.GetHashCode());
     }
 }
예제 #3
0
파일: IDictionary.cs 프로젝트: vdt/AtomOS
 internal IDictionary(HashFunction <_key> aFunction, EqualityFunction <_key> aEquality)
 {
     mFunction = aFunction;
     mEquality = aEquality;
     mModulo   = Capacity - 1;
     mBuckets  = new Bucket[Capacity];
 }
예제 #4
0
        private static bool TryGenerateForEnumerable(Type type, ref EqualityFunction <T> result)
        {
            if (type.CustomAttributes.OfType <NotEnumerableComparisonAttribute>().Any())
            {
                return(false);
            }

            Type enumerableInterface =
                type.GetInterfaces()
                .Concat(new[] { type })//this one handles the case where type is IEnumerable itself
                .Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                .FirstOrDefault();

            if (enumerableInterface == null)
            {
                return(false);
            }

            Type itemType = enumerableInterface.GetGenericArguments().Single();

            ParameterExpression left  = Expression.Parameter(type, "x");
            ParameterExpression right = Expression.Parameter(type, "y");

            result = Expression.Lambda <EqualityFunction <T> >(
                Expression.Call(
                    instance: null,
                    method: NotEquals.GetSequenceNotEqualMethod(itemType, type),
                    arguments: new[] { left, right }
                    ),
                left,
                right
                ).Compile();
            return(true);
        }
예제 #5
0
        private static bool TryGenerateForIEquatable(Type type, ref EqualityFunction <T> result)
        {
            Type equatableInterface = typeof(IEquatable <>).MakeGenericType(type);
            bool implements         = type.GetInterfaces().Any(x => x == equatableInterface);

            if (!implements)
            {
                return(false);
            }

            if (type.GetCustomAttributes <EquatableDependsOnLazyComparisonAttribute>().Any())
            {
                return(false);
            }

            ParameterExpression left  = Expression.Parameter(type, "x");
            ParameterExpression right = Expression.Parameter(type, "y");

            MethodInfo compareMethod = NotEquals.GetEquatableCompareMethod(type);

            result = Expression.Lambda <EqualityFunction <T> >(
                Expression.Call(
                    instance: null,
                    method: NotEquals.GetEquatableCompareMethod(type),
                    arguments: new[] { left, right }
                    ),
                parameters: new[] { left, right }
                ).Compile();

            return(true);
        }
예제 #6
0
        private static EqualityFunction <T> GenerateNotEqualsFunction(Type type)
        {
            EqualityFunction <T> result = null;

            if (!(
                    TryGenerateForPrimitive(type, ref result) ||
                    TryGenerateForIEquatable(type, ref result) ||
                    TryGenerateForEnumerable(type, ref result) ||
                    TryGenerateForOldEnumerable(type, ref result) ||
                    TryGenerateMemberwise(type, ref result)
                    ))
            {
                throw new NotImplementedException("Could not handle lazy comparison.");
            }

            return(result);
        }
예제 #7
0
        private static bool TryGenerateMemberwise(Type type, ref EqualityFunction <T> result)
        {
            PropertyInfo[] properties = type.GetNonEqualityExcludedProperties();
            FieldInfo[]    fields     = type.GetEqualityIncludedFields();

            ParameterExpression left  = Expression.Parameter(type, nameof(left));
            ParameterExpression right = Expression.Parameter(type, nameof(right));

            result = Expression.Lambda <EqualityFunction <T> >(
                properties.Aggregate(
                    fields.Aggregate(
                        Expression.Constant(false) as Expression,
                        (expression, field) =>
                        Expression.OrElse(
                            expression,
                            Expression.Call(
                                instance: null,
                                method: GetNotEqualMethod(field.FieldType),
                                arguments: new[] {
                Expression.Field(left, field),
                Expression.Field(right, field)
            }
                                )
                            )
                        ),
                    (expression, property) =>
                    Expression.OrElse(
                        expression,
                        Expression.Call(
                            instance: null,
                            method: GetNotEqualMethod(property.PropertyType),
                            arguments: new[] {
                Expression.Property(left, property),
                Expression.Property(right, property)
            }
                            )
                        )
                    ),
                parameters: new[] { left, right }
                ).Compile();

            return(true);
        }
예제 #8
0
 private static bool TryGenerateForPrimitive(Type type, ref EqualityFunction <T> result)
 {
     result = DefaultNotEquals;
     return(type.PrimitivelyComparable());
 }