Esempio n. 1
0
        public void AddMatch(string name, AssignmentMember readMember, AssignmentMember writeMember)
        {
            if (AutoMappingUtils.ShouldIgnoreMapping(readMember.Type, writeMember.Type))
            {
                return;
            }

            // Ignore mapping collections if Element Types are ignored
            if (typeof(IEnumerable).IsAssignableFrom(readMember.Type) && typeof(IEnumerable).IsAssignableFrom(writeMember.Type))
            {
                var fromGenericDef = readMember.Type.GetTypeWithGenericTypeDefinitionOf(typeof(IDictionary <,>));
                var toGenericDef   = writeMember.Type.GetTypeWithGenericTypeDefinitionOf(typeof(IDictionary <,>));
                if (fromGenericDef != null && toGenericDef != null)
                {
                    // Check if to/from Key or Value Types are ignored
                    var fromArgs = fromGenericDef.GetGenericArguments();
                    var toArgs   = toGenericDef.GetGenericArguments();
                    if (AutoMappingUtils.ShouldIgnoreMapping(fromArgs[0], toArgs[0]))
                    {
                        return;
                    }
                    if (AutoMappingUtils.ShouldIgnoreMapping(fromArgs[1], toArgs[1]))
                    {
                        return;
                    }
                }
                else if (readMember.Type != typeof(string) && writeMember.Type != typeof(string))
                {
                    var elFromType = readMember.Type.GetCollectionType();
                    var elToType   = writeMember.Type.GetCollectionType();

                    if (AutoMappingUtils.ShouldIgnoreMapping(elFromType, elToType))
                    {
                        return;
                    }
                }
            }

            this.AssignmentMemberMap[name] = new AssignmentEntry(name, readMember, writeMember);
        }