public void CreateEqualsExpressions_PassItemType_ProducesValidExpressionFor(
            Type itemType, Type expectedBodyType, Type expectedDelegateType)
        {
            LambdaExpression expression = EqualsExpressions.CreateEqualsExpression(itemType);

            Assert.AreEqual(2, expression.Parameters.Count);
            Assert.IsTrue(expression.Parameters.All(p => p.Type == itemType));
            Assert.AreEqual(typeof(bool), expression.ReturnType);
            Assert.IsTrue(expectedBodyType.IsInstanceOfType(expression.Body));
            Assert.AreEqual(expectedDelegateType, expression.Compile().GetType());
        }
Exemplo n.º 2
0
        static DictionaryEqualityComparer()
        {
            var expressionCompiler = ExpressionCompiler.Default;

            // ReSharper disable MultipleSpaces
            KeyEqualsFunc        = expressionCompiler.Compile((Expression <Func <TKey, TKey, bool> >)EqualsExpressions.CreateEqualsExpression(typeof(TKey) /*,typeof(TKey).IsArray*/));
            KeyGetHashCodeFunc   = expressionCompiler.Compile((Expression <Func <TKey, int> >)HashCodeExpressions.CreateGetHashCodeExpression(typeof(TKey) /*,typeof(TKey).IsArray*/));
            ValueEqualsFunc      = expressionCompiler.Compile((Expression <Func <TValue, TValue, bool> >)EqualsExpressions.CreateEqualsExpression(typeof(TValue) /*,typeof(TKey).IsArray*/));
            ValueGetHashCodeFunc = expressionCompiler.Compile((Expression <Func <TValue, int> >)HashCodeExpressions.CreateGetHashCodeExpression(typeof(TValue) /*,typeof(TKey).IsArray*/));
            IsValueNullFunc      = expressionCompiler.Compile(NullableHelper.GetIsNullExpression <TValue>());
            // ReSharper restore MultipleSpaces
        }