public void TupleKeyInfoHelper_KeyFactoryLarge()
        {
            TupleKeyInfoHelper builder =
                new TupleKeyInfoHelper(typeof(Tuple<int, int, int, int, int, int, int, Tuple<int, int>>));

            Expression factory = builder.CreateKeyFactoryExpression(
                Enumerable
                    .Range(1, 9)
                    .Select(x => Expression.Constant(x, typeof(int)))
                    .ToArray());

            var result = Expression.Lambda(factory).Compile().DynamicInvoke()
                as Tuple<int, int, int, int, int, int, int, Tuple<int, int>>;

            Assert.IsNotNull(result);

            Assert.AreEqual(1, result.Item1);
            Assert.AreEqual(2, result.Item2);
            Assert.AreEqual(8, result.Rest.Item1);
            Assert.AreEqual(9, result.Rest.Item2);
        }
Пример #2
0
        private static Expression CreateTupleSelector(
            Expression body, 
            Expression[] memberSelectors)
        {
            Type[] memberTypes = memberSelectors.Select(e => e.Type).ToArray();

            Type tupleType = TupleTypeHelper.CreateTupleType(memberTypes);

            var helper = new TupleKeyInfoHelper(tupleType);
            body = helper.CreateKeyFactoryExpression(memberSelectors);
            return body;
        }
        public void TupleKeyInfoHelper_KeyFactory()
        {
            TupleKeyInfoHelper builder = new TupleKeyInfoHelper(typeof(Tuple<int, string>));

            Expression factory = builder.CreateKeyFactoryExpression(
                Expression.Constant(1, typeof(int)), 
                Expression.Constant("2", typeof(string)));

            var result = Expression.Lambda(factory).Compile().DynamicInvoke() as Tuple<int, string>;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Item1);
            Assert.AreEqual("2", result.Item2);
        }