Esempio n. 1
0
        public TypeMap(
            Type sourceType,
            Type destinationType,
            ProfileMap profile,
            bool isReverseMap = false
            )
        {
            Types                  = new(sourceType, destinationType);
            Profile                = profile;
            SourceTypeDetails      = profile.CreateTypeDetails(sourceType);
            DestinationTypeDetails = profile.CreateTypeDetails(destinationType);
            var sourceMembers = new List <MemberInfo>();

            foreach (var destinationProperty in DestinationTypeDetails.WriteAccessors)
            {
                sourceMembers.Clear();
                var propertyType = destinationProperty.GetMemberType();
                if (
                    profile.MapDestinationPropertyToSource(
                        SourceTypeDetails,
                        destinationType,
                        propertyType,
                        destinationProperty.Name,
                        sourceMembers,
                        isReverseMap
                        )
                    )
                {
                    AddPropertyMap(destinationProperty, propertyType, sourceMembers);
                }
            }
        }
Esempio n. 2
0
        public static TypeMap CreateTypeMap(Type sourceType, Type destinationType, ProfileMap options, bool isReverseMap = false)
        {
            var sourceTypeInfo = options.CreateTypeDetails(sourceType);
            var destTypeInfo   = options.CreateTypeDetails(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, options);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var resolvers = new LinkedList <MemberInfo>();

                if (options.MapDestinationPropertyToSource(sourceTypeInfo, destProperty.DeclaringType, destProperty.GetMemberType(), destProperty.Name, resolvers, isReverseMap))
                {
                    typeMap.AddPropertyMap(destProperty, resolvers);
                }
            }
            return(typeMap);
        }