Exemple #1
0
        public static void MethodOfOpenGenericBoolean(ExpressionType type, bool useInterpreter)
        {
            GenericClassWithNonGenericMethod <bool> value = new GenericClassWithNonGenericMethod <bool>();
            ConstantExpression left  = Expression.Constant(value);
            ConstantExpression right = Expression.Constant(new GenericClassWithNonGenericMethod <bool>());
            var        genType       = typeof(GenericClassWithNonGenericMethod <>);
            MethodInfo method        = genType.GetMethod(nameof(GenericClassWithNonGenericMethod <bool> .DoBooleanStuff));

            AssertExtensions.Throws <ArgumentException>("method", () => Expression.MakeBinary(type, left, right, false, method));
            method = genType.MakeGenericType(genType).GetMethod(nameof(GenericClassWithNonGenericMethod <int> .DoIntStuff));
            AssertExtensions.Throws <ArgumentException>("method", () => Expression.MakeBinary(type, left, right, false, method));

            // Confirm does work when closed.
            var validType = typeof(GenericClassWithNonGenericMethod <bool>);

            method = validType.GetMethod(nameof(GenericClassWithNonGenericMethod <bool> .DoBooleanStuff));
            Expression exp = Expression.MakeBinary(type, left, right, false, method);
            Func <GenericClassWithNonGenericMethod <bool> > f = Expression.Lambda <Func <GenericClassWithNonGenericMethod <bool> > >(exp).Compile(useInterpreter);

            Assert.Same(value, f());
        }
Exemple #2
0
 public static GenericClassWithNonGenericMethod <TClassType> DoBooleanStuff(GenericClassWithNonGenericMethod <TClassType> x, GenericClassWithNonGenericMethod <TClassType> y) => x;