コード例 #1
0
        //migrate to PropertyMapFactory
        private static PropertyMap CreatePropertyMap <TSrc, TDest>(string srcPropertyName, string destPropertyName)
        {
            var factory = new TypeMapFactory();

            PropertyMap propertyMap = new PropertyMap(
                typeof(TDest).GetProperty(destPropertyName),
                factory.CreateTypeMap(typeof(TSrc), typeof(TDest),
                                      new MapperConfigurationExpression()));

            propertyMap.ChainMembers(new[] { typeof(TSrc).GetProperty(srcPropertyName) });
            return(propertyMap);
        }
コード例 #2
0
        public void Should_map_properties_with_same_name()
        {
            var mappingOptions = new TestProfile();
            //mappingOptions.SourceMemberNamingConvention = new PascalCaseNamingConvention();
            //mappingOptions.DestinationMemberNamingConvention = new PascalCaseNamingConvention();

            var typeMap = _factory.CreateTypeMap(typeof(Source), typeof(Destination), mappingOptions, MemberList.Destination);

            var propertyMaps = typeMap.GetPropertyMaps();

            propertyMaps.Count().ShouldEqual(2);
        }
コード例 #3
0
        public void Should_map_properties_with_same_name()
        {
            var mappingOptions = new TestProfile();
            //mappingOptions.SourceMemberNamingConvention = new PascalCaseNamingConvention();
            //mappingOptions.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
            var profile = new ProfileMap(mappingOptions);

            var typeMap = TypeMapFactory.CreateTypeMap(typeof(Source), typeof(Destination), profile);

            var propertyMaps = typeMap.PropertyMaps;

            propertyMaps.Count().ShouldBe(2);
        }
コード例 #4
0
        public static PropertyMap CreateReal(Type srcType, Type destType,
                                             string srcPropertyName, string destPropertyName, MapperConfigurationExpression options)
        {
            var factory = new TypeMapFactory();

            var typeMap = factory.CreateTypeMap(srcType, destType, options);

            PropertyMap propertyMap = new PropertyMap(destType.GetProperty(destPropertyName), typeMap);

            propertyMap.ChainMembers(new[] { srcType.GetProperty(srcPropertyName) });

            return(propertyMap);
        }
コード例 #5
0
        public void Should_map_properties_with_different_names()
        {
            var mappingOptions = new StubMappingOptions();

            mappingOptions.ReplaceMemberName("Ä", "A");
            mappingOptions.ReplaceMemberName("í", "i");
            mappingOptions.ReplaceMemberName("Airlina", "Airline");

            var typeMap = _factory.CreateTypeMap(typeof(Source), typeof(Destination), mappingOptions, MemberList.Destination);

            var propertyMaps = typeMap.GetPropertyMaps();

            propertyMaps.Count().ShouldEqual(3);
        }
コード例 #6
0
        public void Should_map_properties_with_same_name()
        {
            var mappingOptions = CreateStub <IMappingOptions>();

            mappingOptions.SourceMemberNamingConvention      = new PascalCaseNamingConvention();
            mappingOptions.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
            mappingOptions.SourceMemberNameTransformer       = s => s;
            mappingOptions.DestinationMemberNameTransformer  = s => s;

            var typeMap = _factory.CreateTypeMap(typeof(Source), typeof(Destination), mappingOptions);

            var propertyMaps = typeMap.GetPropertyMaps();

            propertyMaps.Count().ShouldEqual(2);
        }
コード例 #7
0
        private TypeMap GetTypeMap(TypePair typePair)
        {
            TypeMap nodeMap;

            //typepair explicitly mapped by user
            ExplicitTypeMaps.TryGetValue(typePair, out nodeMap);

            if (nodeMap == null)
            {
                if (!ImplicitTypeMaps.TryGetValue(typePair, out nodeMap))
                {
                    //create implicit map
                    nodeMap = TypeMapFactory.CreateTypeMap(typePair.SourceType, typePair.DestinationType, Options);
                    ImplicitTypeMaps.AddIfNotExist(nodeMap);
                }
            }
            return(nodeMap);
        }
コード例 #8
0
            public override QueryExpressions GetSubQueryExpression(ExpressionBuilder builder, Expression projection, TypeMap typeMap, ExpressionRequest request, Expression instanceParameter, TypePairCount typePairCount)
            {
                var letMapInfos = _savedPaths.Select(path =>
                                                     new {
                    path.LetExpression,
                    MapFromSource = path.GetSourceExpression(instanceParameter),
                    Property      = path.GetPropertyDescription(),
                    path.Marker
                }).ToArray();

                var properties = letMapInfos.Select(m => m.Property).Concat(GetMemberAccessesVisitor.Retrieve(projection, instanceParameter));

                var     letType = ProxyGenerator.GetSimilarType(typeof(object), properties);
                TypeMap letTypeMap;

                lock (ConfigurationProvider)
                {
                    letTypeMap = TypeMapFactory.CreateTypeMap(request.SourceType, letType, typeMap.Profile);
                }
                var secondParameter = Parameter(letType, "dtoLet");

                ReplaceSubQueries();

                var firstExpression = builder.CreateMapExpressionCore(request, instanceParameter, typePairCount, letTypeMap, base.New());

                return(new QueryExpressions(firstExpression, projection, secondParameter));

                void ReplaceSubQueries()
                {
                    foreach (var letMapInfo in letMapInfos)
                    {
                        var letProperty    = letType.GetProperty(letMapInfo.Property.Name);
                        var letPropertyMap = letTypeMap.FindOrCreatePropertyMapFor(letProperty);
                        letPropertyMap.CustomMapExpression = Lambda(letMapInfo.LetExpression.ReplaceParameters(letMapInfo.MapFromSource), secondParameter);
                        projection = projection.Replace(letMapInfo.Marker, MakeMemberAccess(secondParameter, letProperty));
                    }
                    projection = new ReplaceMemberAccessesVisitor(instanceParameter, secondParameter).Visit(projection);
                }
            }
コード例 #9
0
 protected override void Because_of()
 {
     _map = TypeMapFactory.CreateTypeMap(typeof(Source), typeof(Destination), _mappingOptions);
 }
コード例 #10
0
 protected override void Because_of()
 {
     _map = _factory.CreateTypeMap(typeof(Source), typeof(Destination), _mappingOptions, MemberList.Destination);
 }