public void TupleKeyInfoHelper_KeyMemberSelectorLarge2() { var tuple = new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int, int, int, int, int, Tuple<int, int>>>( 1, 2, 3, 4, 5, 6, 7, new Tuple<int, int, int, int, int, int, int, Tuple<int, int>>( 8, 9, 10, 11, 12, 13, 14, Tuple.Create(15, 16))); TupleKeyInfoHelper builder = new TupleKeyInfoHelper(tuple.GetType()); Expression source = Expression.Constant(tuple); Expression selector = builder.CreateKeyMemberSelectorExpression(source, 15); int result = (int)Expression.Lambda(selector).Compile().DynamicInvoke(); Assert.AreEqual(16, result); }
public void TupleKeyInfoHelper_KeyMemberSelector() { TupleKeyInfoHelper builder = new TupleKeyInfoHelper(typeof(Tuple<int, string>)); Expression source = Expression.Constant(Tuple.Create(1, "2")); Expression selector1 = builder.CreateKeyMemberSelectorExpression(source, 0); Expression selector2 = builder.CreateKeyMemberSelectorExpression(source, 1); int result1 = (int)Expression.Lambda(selector1).Compile().DynamicInvoke(); string result2 = (string)Expression.Lambda(selector2).Compile().DynamicInvoke(); Assert.AreEqual(1, result1); Assert.AreEqual("2", result2); }