当前位置: 首页>>代码示例>>C#>>正文


C# GraphNode.AddChild方法代码示例

本文整理汇总了C#中GraphNode.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# GraphNode.AddChild方法的具体用法?C# GraphNode.AddChild怎么用?C# GraphNode.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphNode的用法示例。


在下文中一共展示了GraphNode.AddChild方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConstructDependencyGraph

        /// <summary>
        /// Construct a depdenency graph of the <see cref="Character"/>'s <see cref="ModifierSource"/>s.
        /// </summary>
        /// <param name="character">
        /// The <see cref="Character"/> to generate the dependency graph for. This cannot be null.
        /// </param>
        /// <param name="modifierSources">
        /// The already extracted list of <see cref="ModifierSource"/>s to use. This cannot be null.
        /// </param>
        /// <returns>
        /// A <see cref="GraphNode{ModifierSource}"/> that is the root node of a dependency graph. The root
        /// node can be ignored and is not part of the graph itself.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        internal static GraphNode<ModifierSource> ConstructDependencyGraph(Character character, IList<ModifierSource> modifierSources)
        {
            if (character == null)
            {
                throw new ArgumentNullException("character");
            }
            if (modifierSources == null)
            {
                throw new ArgumentNullException("modifierSources");
            }

            GraphNode<ModifierSource> root;
            IEqualityComparer<ModifierSource> comparer;
            Dictionary<ModifierSource, GraphNode<ModifierSource>> graphNodeLookup;

            // Rather than use "EqualityComparer<ModifierSource>.Default", use identity equality.
            // This allows two instances of the same modifier source with the same name to be used
            // within the graph. This can occur frequently with powers.
            comparer = new IdentityEqualityComparer<ModifierSource>();

            // Optimization for GraphNode.Find().
            graphNodeLookup = new Dictionary<ModifierSource, GraphNode<ModifierSource>>();

            // Construct a dependency graph.
            root = new GraphNode<ModifierSource>(new NullModifierSource(), comparer);
            foreach (ModifierSource modifierSource in modifierSources)
            {
                List<KeyValuePair<ModifierSource, ModifierSource>> dependencies;
                GraphNode<ModifierSource> parentGraphNode;
                GraphNode<ModifierSource> childGraphNode;

                // Get the dependencies
                dependencies = modifierSource.GetDependencies(character);

                // For each dependency, find the source ModifierSource and add
                // the destination under it.
                foreach (KeyValuePair<ModifierSource, ModifierSource> dependency in dependencies)
                {
                    // Find the parent of the dependency
                    if (!graphNodeLookup.TryGetValue(dependency.Key, out parentGraphNode))
                    {
                        parentGraphNode = new GraphNode<ModifierSource>(dependency.Key, comparer);
                        root.AddChild(parentGraphNode);
                        graphNodeLookup[dependency.Key] = parentGraphNode;
                    }

                    // Find the child of the dependency
                    if (!graphNodeLookup.TryGetValue(dependency.Value, out childGraphNode))
                    {
                        childGraphNode = new GraphNode<ModifierSource>(dependency.Value, comparer);
                        graphNodeLookup[dependency.Value] = childGraphNode;
                    }

                    // Add the child to the parent
                    parentGraphNode.AddChild(childGraphNode);
                }
            }

            return root;
        }
开发者ID:anthonylangsworth,项目名称:GammaWorldCharacter,代码行数:76,代码来源:ModifierSourceGraphNodeHelper.cs

示例2: Test_AddChild_CircularReferenceOneLevel

 public void Test_AddChild_CircularReferenceOneLevel()
 {
     GraphNode<string> parent = new GraphNode<string>("parent");
     GraphNode<string> child = new GraphNode<string>("child");
     parent.AddChild(child);
     Assert.That(() => child.AddChild(parent),
         Throws.ArgumentException.And.Property("ParamName").EqualTo("graphNode"));
 }
开发者ID:anthonylangsworth,项目名称:GammaWorldCharacter,代码行数:8,代码来源:TestGraphNode.cs

示例3: Test_GetDepthFirstEnumerator

        public void Test_GetDepthFirstEnumerator()
        {
            GraphNode<string> rootGraphNode = new GraphNode<string>("root");
            GraphNode<string> leftParentGraphNode = new GraphNode<string>("leftParent");
            GraphNode<string> leftFirstChildGraphNode = new GraphNode<string>("leftFirstChild");
            GraphNode<string> leftSecondChildGraphNode = new GraphNode<string>("leftSecondChild");
            GraphNode<string> rightParentGraphNode = new GraphNode<string>("rightParent");
            GraphNode<string> rightChildGraphNode = new GraphNode<string>("rightChild");
            GraphNode<string> rightGrandChildGraphNode = new GraphNode<string>("rightGrandChild");

            rootGraphNode.AddChild(leftParentGraphNode);
            leftParentGraphNode.AddChild(leftFirstChildGraphNode);
            leftParentGraphNode.AddChild(leftSecondChildGraphNode);
            rootGraphNode.AddChild(rightParentGraphNode);
            rightParentGraphNode.AddChild(rightChildGraphNode);
            rightChildGraphNode.AddChild(rightGrandChildGraphNode);

            GraphNode<string>[] expected = new[]
            {
                rootGraphNode,
                leftParentGraphNode,
                leftFirstChildGraphNode,
                leftSecondChildGraphNode,
                rightParentGraphNode,
                rightChildGraphNode,
                rightGrandChildGraphNode
            };

            Assert.That(expected.Zip(rootGraphNode.GetDepthFirstEnumerator(), (x, y) => x.Equals(y)).All(x => x), Is.True);
        }
开发者ID:anthonylangsworth,项目名称:GammaWorldCharacter,代码行数:30,代码来源:TestGraphNode.cs

示例4: Test_AddChild_Self

 public void Test_AddChild_Self()
 {
     GraphNode<string> graphNode = new GraphNode<string>(string.Empty);
     Assert.That(() => graphNode.AddChild(graphNode),
         Throws.ArgumentException.And.Property("ParamName").EqualTo("graphNode"));
 }
开发者ID:anthonylangsworth,项目名称:GammaWorldCharacter,代码行数:6,代码来源:TestGraphNode.cs

示例5: Test_IsParent_ChildsParent

        public void Test_IsParent_ChildsParent()
        {
            GraphNode<string> parentGraphNode = new GraphNode<string>("parent");
            GraphNode<string> childGraphNode = new GraphNode<string>("child");
            parentGraphNode.AddChild(childGraphNode);

            Assert.That(childGraphNode.IsParent(parentGraphNode));
        }
开发者ID:anthonylangsworth,项目名称:GammaWorldCharacter,代码行数:8,代码来源:TestGraphNode.cs


注:本文中的GraphNode.AddChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。