Example #1
0
        private void Demo2()
        {
            Expression <Func <int, bool> > predicate = GetFilter();

            var injected = Injector2.Inject(predicate,
                                            x => Console.WriteLine($"{x} => YES"),
                                            x => Console.WriteLine($"{x} => NO"));
            var injectedDel = injected.Compile();

            var list     = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var filtered = list
                           .Where(injectedDel)
                           .ToList();
        }
Example #2
0
        public void Injector2TestWithLambdas2()
        {
            var predicate = GetFilter();

            var injected = Injector2.Inject(predicate,
                                            x => PrintTrue(x),
                                            null);
            var injectedDel = (Func <int, bool>)injected.Compile();

            var injectResultTrue = injectedDel(12);

            Assert.IsTrue(injectResultTrue);
            Assert.IsTrue(result);

            var injectResultFalse = injectedDel(5);

            Assert.IsFalse(injectResultFalse);
        }
Example #3
0
        public void Injector2TestWithMethodInfo()
        {
            var miTrue  = this.GetType().GetMethod("PrintTrue");
            var miFalse = this.GetType().GetMethod("PrintFalse");

            var predicate   = GetFilter();
            var injected    = Injector2.Inject(predicate, this, miTrue, miFalse);
            var injectedDel = (Func <int, bool>)injected.Compile();

            var injectResultTrue = injectedDel(12);

            Assert.IsTrue(injectResultTrue);
            Assert.IsTrue(result);

            var injectResultFalse = injectedDel(5);

            Assert.IsFalse(injectResultFalse);
            Assert.IsFalse(result);
        }