Example #1
0
        public void Test026()
        {
            var xgr        = new ExpressionGenerator();
            var intArgs    = GetIntArgs(4);
            var stringArgs = GetStringArgs(4);
            var args       = intArgs.Zip(stringArgs, (a, b) => new { a = (Expression)a.Body, b = (Expression)b.Body }).SelectMany(a => new[] { a.a, a.b }).Concat(new[] { intArgs.Length != stringArgs.Length ? intArgs.Last().Body : null }).Where(a => a != null);

            var actual = xgr.FromAction(
                intArgs[0], stringArgs[0], intArgs[1], stringArgs[1], intArgs[2], stringArgs[2], intArgs[3], stringArgs[3],
                (a, b, c, d, e, f, g, h) => interleaveFunc(a, b, c, d, e, f, g, h));

            var expected = Expression.Call(
                null,
                typeof(ExpressionGeneratorFromActionTests).GetMethod("interleaveFunc"),
                Expression.NewArrayInit(typeof(object), args.Select(a => a.Type == typeof(string) ? a : Expression.Convert(a, typeof(object))).ToArray())
                );

            var comparer = new ExpressionComparer();

            Assert.IsTrue(comparer.AreEqual(expected, actual));
        }