Ejemplo n.º 1
0
        private List <MappingMemberPath> ParseMappingTypes(TypePair typePair)
        {
            var result = new List <MappingMemberPath>();

            var sourceMembers = GetSourceMembers(typePair.Source);
            var targetMembers = GetTargetMembers(typePair.Target);

            var targetBindings = GetTest(typePair, targetMembers);

            var bindingConfig = _config.GetBindingConfig(typePair);

            foreach (var sourceMember in sourceMembers)
            {
                if (IsIgnore(bindingConfig, typePair, sourceMember))
                {
                    continue;
                }

                var targetNames = GetTargetName(bindingConfig, typePair, sourceMember, targetBindings);

                foreach (var targetName in targetNames)
                {
                    var targetMember = targetMembers.FirstOrDefault(x => _config.NameMatching(targetName, x.Name));
                    if (targetMember.IsNull())
                    {
                        result.AddRange(GetBindMappingMemberPath(typePair, bindingConfig, sourceMember));
                        continue;
                    }

                    var concreteBindingType = bindingConfig.Map(x => x.GetBindType(targetName));
                    if (concreteBindingType.HasValue)
                    {
                        var mappingTypePair = new TypePair(sourceMember.GetMemberType(), concreteBindingType.Value);
                        result.Add(new MappingMemberPath(sourceMember, targetMember, mappingTypePair));
                    }
                    else
                    {
                        result.Add(new MappingMemberPath(sourceMember, targetMember));
                    }

                    result.AddRange(GetBindMappingMemberPath(typePair, bindingConfig, sourceMember));
                }
            }

            return(result);
        }
        private List <MappingMember> ParseMappingTypes(TypePair typePair)
        {
            var result = new List <MappingMember>();

            List <MemberInfo> sourceMembers = GetSourceMembers(typePair.Source);
            List <MemberInfo> targetMembers = GetTargetMembers(typePair.Target);

            Dictionary <string, string> targetBindings = GetTest(typePair, targetMembers);

            Option <BindingConfig> bindingConfig = _config.GetBindingConfig(typePair);

            foreach (MemberInfo sourceMember in sourceMembers)
            {
                if (IsIgnore(bindingConfig, typePair, sourceMember))
                {
                    continue;
                }

                string     targetName   = GetTargetName(bindingConfig, typePair, sourceMember, targetBindings);
                MemberInfo targetMember = targetMembers.FirstOrDefault(x => _config.NameMatching(targetName, x.Name));

                if (targetMember.IsNull())
                {
                    continue;
                }
                var concreteBindingType = bindingConfig.Map(x => x.GetBindType(targetName));
                if (concreteBindingType.HasValue)
                {
                    var mappingTypePair = new TypePair(sourceMember.GetMemberType(), concreteBindingType.Value);
                    result.Add(new MappingMember(sourceMember, targetMember, mappingTypePair));
                }
                else
                {
                    result.Add(new MappingMember(sourceMember, targetMember));
                }
            }
            return(result);
        }