Exemplo n.º 1
0
        public static Expression CreateKeyConversionExpression(
            Expression source,
            MemberInfo[] toMembers,
            int[] mapping,
            IKeyInfoHelper from,
            IKeyInfoHelper to)
        {
            int memberCount = mapping.Length;

            Expression[] factoryArgs = new Expression[memberCount];

            for (int i = 0; i < memberCount; i++)
            {
                Type       requestedType = ReflectionHelper.GetMemberType(toMembers[i]);
                Expression arg           = from.CreateKeyMemberSelectorExpression(source, mapping[i]);

                if (arg.Type != requestedType)
                {
                    arg = Expression.Convert(arg, requestedType);
                }

                factoryArgs[i] = arg;
            }

            return(to.CreateKeyFactoryExpression(factoryArgs));
        }
Exemplo n.º 2
0
        public static Expression CreateKeySelector(
            Expression source,
            MemberInfo[] entityMembers,
            IKeyInfoHelper helper)
        {
            Expression[] memberAccess = new Expression[entityMembers.Length];

            for (int i = 0; i < entityMembers.Length; i++)
            {
                memberAccess[i] = Expression.MakeMemberAccess(source, entityMembers[i]);
            }

            Expression body = helper.CreateKeyFactoryExpression(memberAccess);

            return(body);
        }