Exemple #1
0
        public ConfigInheritanceTree(TypeMapping root)
        {
            var typePair = new TypePair(root.Source.EntryType, root.Target.EntryType);

            _nodeDictionary.Add(typePair, new ConfigInheritanceNode(root));

            this.Root = new ConfigInheritanceNode(root);
        }
Exemple #2
0
        private ConfigInheritanceNode AddInternal(ConfigInheritanceNode initialNode, TypeMapping newElement)
        {
            //if( initialNode.Item.TypePair == newElement.TypePair )
            //    return;

            //root swap
            if (initialNode == this.Root && IsParentChildRelation(newElement, initialNode.Item))
            {
                this.Root = new ConfigInheritanceNode(newElement)
                {
                    Parent = initialNode.Parent,
                };

                this.Root.Children.Add(initialNode);
                initialNode.Parent = this.Root;

                return(this.Root);
            }

            foreach (var node in initialNode.Children)
            {
                if (IsParentChildRelation(node.Item, newElement))
                {
                    return(this.AddInternal(node, newElement));
                }
            }

            var toRemove = new List <ConfigInheritanceNode>();

            foreach (var node in initialNode.Children)
            {
                if (IsParentChildRelation(newElement, node.Item))
                {
                    toRemove.Add(node);
                }
            }

            var newNode = new ConfigInheritanceNode(newElement)
            {
                Parent = initialNode
            };

            foreach (var tr in toRemove)
            {
                initialNode.Children.Remove(tr);
                newNode.Children.Add(tr);
                tr.Parent = newNode;
            }

            initialNode.Children.Add(newNode);
            return(newNode);
        }
Exemple #3
0
        private void ToStringInternal(StringBuilder stringBuilder, int indentationLevel,
                                      ConfigInheritanceNode initialNode, bool includeMembers, bool includeOptions)
        {
            string sourceTypeName = initialNode.Item.Source.EntryType.GetPrettifiedName();
            string targetTypeName = initialNode.Item.Target.EntryType.GetPrettifiedName();

            StringBuilder options = new StringBuilder();

            if (includeOptions)
            {
                options.Append($"{nameof( IMappingOptions.ReferenceBehavior )}: {initialNode.Item.ReferenceBehavior}, ");
                options.Append($"{nameof( IMappingOptions.CollectionBehavior )}: {initialNode.Item.CollectionBehavior}");

                if (initialNode.Item.CustomTargetConstructor != null)
                {
                    options.Append($" ,{nameof( IMappingOptions.CustomTargetConstructor )}: PROVIDED");
                }

                if (initialNode.Item.CustomConverter != null)
                {
                    options.Append($" ,{nameof( IMappingOptions.CustomConverter )}: PROVIDED");
                }

                if (initialNode.Item.CollectionItemEqualityComparer != null)
                {
                    options.Append($" ,{nameof( IMappingOptions.CollectionItemEqualityComparer )}: PROVIDED");
                }
            }

            stringBuilder.Append(new String('\t', indentationLevel++));
            stringBuilder.AppendLine($"[{sourceTypeName} -> {targetTypeName}] ({options})");

            if (includeMembers)
            {
                var           indent        = new String('\t', indentationLevel++);
                StringBuilder memberOptions = new StringBuilder();

                foreach (var item in initialNode.Item.MemberToMemberMappings.Values)
                {
                    if (includeOptions)
                    {
                        memberOptions.Append($"{nameof( IMappingOptions.ReferenceBehavior )}: {item.ReferenceBehavior}, ");
                        memberOptions.Append($"{nameof( IMappingOptions.CollectionBehavior )}: {item.CollectionBehavior}");

                        if (item.CustomTargetConstructor != null)
                        {
                            memberOptions.Append($" ,{nameof( IMappingOptions.CustomTargetConstructor )}: PROVIDED");
                        }

                        if (item.CustomConverter != null)
                        {
                            memberOptions.Append($" ,{nameof( IMappingOptions.CustomConverter )}: PROVIDED");
                        }

                        if (item.CollectionItemEqualityComparer != null)
                        {
                            memberOptions.Append($" ,{nameof( IMappingOptions.CollectionItemEqualityComparer )}: PROVIDED");
                        }
                    }

                    stringBuilder.AppendLine($"{indent}{item} ({memberOptions})");
                    memberOptions.Clear();
                }

                indentationLevel--;
            }

            foreach (var node in initialNode.Children)
            {
                this.ToStringInternal(stringBuilder, indentationLevel, node, includeMembers, includeOptions);
            }
        }
Exemple #4
0
        //public bool ContainsKey( Type sourceType, Type targetType )
        //{
        //    var key = new TypePair( sourceType, targetType );
        //    return _nodeDictionary.ContainsKey( key );
        //}

        public bool TryGetValue(Type sourceType, Type targetType, out ConfigInheritanceNode value)
        {
            var key = new TypePair(sourceType, targetType);

            return(_nodeDictionary.TryGetValue(key, out value));
        }