public void AnonymousTypeKeyInfoHelper_KeyMemberSelector() { var key = new { Key1 = 1, Key2 = "2" }; AnonymousTypeKeyInfoHelper builder = new AnonymousTypeKeyInfoHelper(key.GetType()); Expression source = Expression.Constant(key); 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); }
public void AnonymousTypeKeyInfoHelper_KeyFactory() { var key = new { Key1 = 1, Key2 = "2" }; AnonymousTypeKeyInfoHelper builder = new AnonymousTypeKeyInfoHelper(key.GetType()); Expression factory = builder.CreateKeyFactoryExpression( Expression.Constant(1, typeof(int)), Expression.Constant("2", typeof(string))); dynamic result = Expression.Lambda(factory).Compile().DynamicInvoke(); Assert.AreEqual(1, result.Key1); Assert.AreEqual("2", result.Key2); }