示例#1
0
        private static Expression GetEnumerableIndexAccess(Expression parentContextAccess, IMemberMapperData mapperData)
        {
            if (parentContextAccess == null)
            {
                while (!mapperData.TargetMemberIsEnumerableElement())
                {
                    mapperData = mapperData.Parent;
                }

                if (!mapperData.IsEntryPoint)
                {
                    return(mapperData.Parent.EnumerablePopulationBuilder.Counter);
                }

                parentContextAccess = mapperData.MappingDataObject;
            }

            var mappingDataType = typeof(IMappingData <,>)
                                  .MakeGenericType(parentContextAccess.Type.GetGenericTypeArguments());

            var enumerableIndexProperty = mappingDataType.GetPublicInstanceProperty("EnumerableIndex");

            // ReSharper disable once AssignNullToNotNullAttribute
            return(Expression.Property(parentContextAccess, enumerableIndexProperty));
        }
        private static bool DoNotApplyFilter(
            IQualifiedMember sourceMember,
            IDataSource dataSource,
            IMemberMapperData mapperData)
        {
            if (!dataSource.IsValid)
            {
                return(true);
            }

            // Non-simple enumerable elements will be filtered out elsewhere,
            // unless they're being runtime-typed:
            return(!sourceMember.IsSimple && !mapperData.IsEntryPoint &&
                   mapperData.TargetMemberIsEnumerableElement());
        }
        private static bool SourceObjectCouldBeNull(IMemberMapperData mapperData)
        {
            if (mapperData.Context.IsForDerivedType)
            {
                return(false);
            }

            if (mapperData.SourceType.IsValueType())
            {
                return(false);
            }

            if (mapperData.RuleSet.Settings.SourceElementsCouldBeNull && mapperData.TargetMemberIsEnumerableElement())
            {
                return(!mapperData.HasSameSourceAsParent());
            }

            return(false);
        }
        private static MappingContextInfo GetSimpleTypesMappingContextInfo(SwapArgs swapArgs)
        {
            var mapperData = swapArgs.MapperData;
            IMemberMapperData contextMapperData = mapperData.Parent;

            IQualifiedMember targetMember;

            while (true)
            {
                if (contextMapperData.TargetMemberIsEnumerableElement())
                {
                    targetMember = mapperData.TargetMember.RelativeTo(contextMapperData.TargetMember);
                    break;
                }

                if (!contextMapperData.IsRoot)
                {
                    contextMapperData = contextMapperData.Parent;
                    continue;
                }

                targetMember = mapperData.TargetMember;

                contextMapperData = mapperData.GetAppropriateMappingContext(
                    mapperData.SourceMember.RootType,
                    targetMember.RootType);

                break;
            }

            return(new MappingContextInfo(
                       swapArgs,
                       mapperData.MappingDataObject,
                       mapperData.SourceMember.GetQualifiedAccess(contextMapperData.SourceObject),
                       targetMember.GetQualifiedAccess(contextMapperData.TargetInstance)));
        }