예제 #1
0
        public void TestSubLambda2y()
        {
            ParameterExpression parameterB = Expression.Parameter(typeof(TestStructB));
            TestStructA         aaa        = default(TestStructA);
            Expression <Func <TestStructB, bool> > predicate = Expression.Lambda <Func <TestStructB, bool> >(Expression.Equal(Expression.MakeMemberAccess(parameterB, typeof(TestStructB).GetProperty("Y")), Expression.MakeMemberAccess(Expression.Constant(aaa), typeof(TestStructA).GetProperty("Y"))), parameterB);

            ParameterExpression parameterA             = Expression.Parameter(typeof(TestStructA));
            Expression          any                    = Expression.Call(anyWithPredicateMethod.MakeGenericMethod(typeof(TestStructB)), Expression.MakeMemberAccess(parameterA, typeof(TestStructA).GetProperty("ArrayB")), predicate);
            Expression <Func <TestStructA, bool> > exp = Expression.Lambda <Func <TestStructA, bool> >(any, parameterA);
            var f = Compile(exp, CompilerOptions.All);

            aaa.Y = 1;
            Assert.IsFalse(f(new TestStructA {
                ArrayB = new[] { new TestStructB {
                                     Y = 1
                                 }, }
            }));
        }
예제 #2
0
        private static WeakReference DoTestConstsAreFreedAfterGarbageCollecting2()
        {
            var a = new TestClassA {
                S = "qxx"
            };
            var result = new WeakReference(a);
            var aa     = new TestStructA {
                A = a
            };
            Expression <Func <TestClassA, string> > path = o => o.S;
            var exp = Expression.Lambda <Func <TestClassA, bool> >(Expression.Equal(path.Body, Expression.MakeMemberAccess(Expression.MakeMemberAccess(Expression.Constant(aa), typeof(TestStructA).GetProperty("A")), typeof(TestClassA).GetProperty("S"))), path.Parameters);
            var f   = LambdaCompiler.Compile(exp, CompilerOptions.All);

            Assert.IsTrue(f(new TestClassA {
                S = "qxx"
            }));
            Assert.IsFalse(f(new TestClassA {
                S = "qzz"
            }));
            return(result);
        }
예제 #3
0
 private static void Qzz2(TestClassA a, TestStructA aa)
 {
     a.StructAArray[1] = aa;
 }