Ejemplo n.º 1
0
        internal TypeAdapterSettings GetMergedSettings(TypeTuple tuple, MapType mapType)
        {
            var arg = new PreCompileArgument
            {
                SourceType      = tuple.Source,
                DestinationType = tuple.Destination,
                MapType         = mapType,
                ExplicitMapping = this.RuleMap.ContainsKey(tuple),
            };
            var settings = (from rule in this.Rules.Reverse <TypeAdapterRule>()
                            let priority = rule.Priority(arg)
                                           where priority != null
                                           orderby priority.Value descending
                                           select rule.Settings).ToList();
            var result = new TypeAdapterSettings();

            foreach (var setting in settings)
            {
                result.Apply(setting);
            }

            //remove recursive include types
            if (mapType == MapType.MapToTarget)
            {
                result.Includes.Remove(tuple);
            }
            else
            {
                result.Includes.RemoveAll(t => t.Source == tuple.Source);
            }
            return(result);
        }
Ejemplo n.º 2
0
        internal TypeAdapterSettings GetMergedSettings(TypeTuple tuple, MapType mapType)
        {
            var arg = new PreCompileArgument
            {
                SourceType      = tuple.Source,
                DestinationType = tuple.Destination,
                MapType         = mapType,
                ExplicitMapping = this.RuleMap.ContainsKey(tuple),
            };

            //auto add setting if there is attr setting
            var attrSettings = GetAttributeSettings(tuple, mapType).ToList();

            if (!arg.ExplicitMapping && attrSettings.Any(rule => rule.Priority(arg) == 100))
            {
                GetSettings(tuple);
                arg.ExplicitMapping = true;
            }

            var result = new TypeAdapterSettings();

            lock (this.Rules)
            {
                var rules    = this.Rules.Reverse <TypeAdapterRule>().Concat(attrSettings);
                var settings = from rule in rules
                               let priority = rule.Priority(arg)
                                              where priority != null
                                              orderby priority.Value descending
                                              select rule.Settings;
                foreach (var setting in settings)
                {
                    result.Apply(setting);
                }
            }

            //remove recursive include types
            if (mapType == MapType.MapToTarget)
            {
                result.Includes.Remove(tuple);
            }
            else
            {
                result.Includes.RemoveAll(t => t.Source == tuple.Source);
            }
            return(result);
        }