Esempio n. 1
0
 public TypeMap(TypeDetails sourceType, TypeDetails destinationType, MemberList memberList)
 {
     _sourceType = sourceType;
     _destinationType = destinationType;
     Types = new TypePair(sourceType.Type, destinationType.Type);
     Profile = ConfigurationStore.DefaultProfileName;
     ConfiguredMemberList = memberList;
 }
Esempio n. 2
0
        private IMappingExpression <TSource, TDestination> Ignore <TSource, TDestination>(
            IMappingExpression <TSource, TDestination> mappingExp, Type destinationType)
        {
            var destInfo = new TypeDetails(destinationType, ShouldMapProperty, ShouldMapField);

            foreach (var destProperty in destInfo.PublicWriteAccessors)
            {
                var attrs = destProperty.GetCustomAttributes(true);
                if (attrs.Any(x => x is IgnoreMapAttribute))
                {
                    mappingExp = mappingExp.ForMember(destProperty.Name, y => y.Ignore());
                }
                if (_globalIgnore.Contains(destProperty.Name))
                {
                    mappingExp = mappingExp.ForMember(destProperty.Name, y => y.Ignore());
                }
            }
            return(mappingExp);
        }
Esempio n. 3
0
 private bool MapDestinationPropertyToSource(IProfileConfiguration options, TypeDetails sourceTypeInfo,
     Type destType, string destMemberInfo, LinkedList<MemberInfo> members)
 {
     return
         options.MemberConfigurations.Any(
             _ => _.MapDestinationPropertyToSource(options, sourceTypeInfo, destType, destMemberInfo, members));
 }
Esempio n. 4
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo,
            IProfileConfiguration options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var members = new LinkedList<MemberInfo>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(),
                    parameter.Name, members);

                var resolvers = members.Select(mi => ReflectionHelper.ToMemberGetter(mi));

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
Esempio n. 5
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo,
                                                IProfileConfiguration options)
        {
            var parameters     = new List <ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
            {
                return(false);
            }

            foreach (var parameter in ctorParameters)
            {
                var members = new LinkedList <MemberInfo>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(),
                                                                parameter.Name, members);

                var resolvers = members.Select(mi => ReflectionHelper.ToMemberGetter(mi));

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return(true);
        }