示例#1
0
        private void AssertResultMatchesExpectedTokens(string code, List <TokenBase> expectedTokens)
        {
            Lexer            lexer  = new Lexer();
            List <TokenBase> tokens = lexer.Lex(code);
            bool             equal  = tokens.SequenceEqual(expectedTokens, LambdaEqualityComparer <TokenBase> .Create(
                                                               (a, b) => a.GetType() == b.GetType() && a.Contents == b.Contents
                                                               ));

            Assert.True(equal, "Token sequence did not match.");
        }
示例#2
0
        public static IEnumerable <T> Except <T>(this IEnumerable <T> first, IEnumerable <T> second, Func <T, T, bool> comparer, Func <T, int> hasher)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            if (hasher == null)
            {
                throw new ArgumentNullException("hasher");
            }

            return(first.Except(second, LambdaEqualityComparer.Create(comparer, hasher)));
        }
示例#3
0
        public static HashSet <T> ToHashSet <T>(this IEnumerable <T> source, Func <T, T, bool> comparer, Func <T, int> hasher)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            return(new HashSet <T>(source, LambdaEqualityComparer.Create(comparer, hasher)));
        }
示例#4
0
        public static IEnumerable <T> Distinct <T>(this IEnumerable <T> source, Func <T, T, bool> comparer, Func <T, int> hasher)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            if (hasher == null)
            {
                throw new ArgumentNullException("hasher");
            }

            return(source.Distinct(LambdaEqualityComparer.Create(comparer, hasher)));
        }
示例#5
0
        public static bool HasDuplicates <T>(this IEnumerable <T> source, Func <T, T, bool> comparer, Func <T, int> hasher)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            if (hasher == null)
            {
                throw new ArgumentNullException("hasher");
            }

            return(source.HasDuplicates(LambdaEqualityComparer.Create(comparer, hasher)));
        }
示例#6
0
        public static bool ContainsAny <T>(this IEnumerable <T> source, Func <T, T, bool> comparer, Func <T, int> hasher, params T[] values)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            if (hasher == null)
            {
                throw new ArgumentNullException("hasher");
            }

            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            bool result = false;

            LambdaEqualityComparer <T> lambdaEqualityComparer = LambdaEqualityComparer.Create(comparer, hasher);

            foreach (T value in values)
            {
                if (source.Contains(value, lambdaEqualityComparer))
                {
                    result = true;
                    break;
                }
            }

            return(result);
        }
示例#7
0
        public static IEnumerable <TResult> LeftJoin <TLeft, TRight, TKey, TResult>(this IEnumerable <TLeft> left, IEnumerable <TRight> right, Func <TLeft, TKey> leftKeySelector, Func <TRight, TKey> rightKeySelector, Func <TLeft, TRight, TResult> resultSelector, Func <TKey, TKey, bool> comparer, Func <TKey, int> hasher)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            if (hasher == null)
            {
                throw new ArgumentNullException("hasher");
            }

            var groupJoin = left.GroupJoin(right, leftKeySelector, rightKeySelector, (leftElement, rightElements) => new { LeftElement = leftElement, RightElements = rightElements }, LambdaEqualityComparer.Create(comparer, hasher));

            return(groupJoin.SelectMany(joinedElement => joinedElement.RightElements.DefaultIfEmpty(), (joinedElement, rightElement) => resultSelector(joinedElement.LeftElement, rightElement)));
        }
示例#8
0
        public static IEnumerable <TResult> Join <TOuter, TInner, TKey, TResult>(this IEnumerable <TOuter> outer, IEnumerable <TInner> inner, Func <TOuter, TKey> outerKeySelector, Func <TInner, TKey> innerKeySelector, Func <TOuter, TInner, TResult> resultSelector, Func <TKey, TKey, bool> comparer, Func <TKey, int> hasher)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            if (hasher == null)
            {
                throw new ArgumentNullException("hasher");
            }

            return(outer.Join(inner, outerKeySelector, innerKeySelector, resultSelector, LambdaEqualityComparer.Create(comparer, hasher)));
        }