Esempio n. 1
0
        private Expression BuildToNullableExpression(Expression sourceLocalName, Type sourceType, Type resultType)
        {
            var resultElementType = resultType.GetNullableElementType();
            var resultValue       = _ctx.CreateExpression(sourceLocalName, sourceType, resultElementType);

            return(Expression.TypeAs(resultValue, resultType));
        }
Esempio n. 2
0
        private MethodCallExpression BuildResultCollectionExpression(Expression sourceLocalName, Type sourceType, Type resultType)
        {
            var sourceElementType = sourceType.GetCollectionElementType();
            var resultElementType = resultType.GetCollectionElementType();

            var methodInfo = SelectMethodInfo.MakeGenericMethod(sourceElementType, resultElementType);
            var selector   = _ctx.CreateExpression(sourceElementType, resultElementType);

            return(Expression.Call(methodInfo, sourceLocalName, selector));
        }
Esempio n. 3
0
        private IEnumerable <MemberBinding> BuildMemberInitList(Expression sourceLocalName, IEnumerable <ITypeMemberInfo> sourceMembers, IEnumerable <ITypeMemberInfo> resultMembers)
        {
            var sourceMemberNames = sourceMembers.Select(p => p.Name);
            var resultMemberNames = resultMembers.Select(p => p.Name);
            var commonMemberNames = resultMemberNames.Intersect(sourceMemberNames);

            foreach (var memberName in commonMemberNames)
            {
                var sourceMemberInfo = sourceMembers.First(p => p.Name == memberName);
                var sourceMemberExpr = ResolveSourceMemberExpression(sourceLocalName, sourceMemberInfo);

                var resultMemberInfo = resultMembers.First(p => p.Name == memberName);
                var resultValueExpr  = _ctx.CreateExpression(sourceMemberExpr, sourceMemberInfo.Type, resultMemberInfo.Type);

                yield return(Expression.Bind(resultMemberInfo.OriginalInfo, resultValueExpr));
            }
        }