本文整理汇总了C#中Composite.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Composite.Add方法的具体用法?C# Composite.Add怎么用?C# Composite.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composite
的用法示例。
在下文中一共展示了Composite.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// Entry point into console application.
static void Main()
{
// Create a tree structure
Composite root = new Composite("root");
root.Add(new Leaf("Leaf A"));
root.Add(new Leaf("Leaf B"));
Composite comp1 = new Composite("Composite X");
comp1.Add(new Leaf("Leaf XA"));
comp1.Add(new Leaf("Leaf XB"));
root.Add(comp1);
Composite comp2 = new Composite("Composite Y");
comp2.Add(new Leaf("Leaf YA"));
comp2.Add(new Leaf("Leaf YB"));
root.Add(comp2);
Composite comp3 = new Composite("Composite Z");
comp3.Add(new Leaf("Leaf ZA"));
comp3.Add(new Leaf("Leaf ZB"));
comp2.Add(comp3);
root.Add(new Leaf("Leaf C"));
// Add and remove a leaf
Leaf leaf = new Leaf("Leaf D");
root.Add(leaf);
root.Remove(leaf);
// Recursively display tree
root.Display(1);
// Wait for user
Console.ReadKey();
}
示例2: Main
private static void Main()
{
// Create a tree structure
Composite root = new Composite("root");
root.Add(new Leaf("Leaf A"));
root.Add(new Leaf("Leaf B"));
Composite comp = new Composite("Composite X");
comp.Add(new Leaf("Leaf XA"));
comp.Add(new Leaf("Leaf XB"));
root.Add(comp);
root.Add(new Leaf("Leaf C"));
// Add and remove a leaf
Leaf leaf = new Leaf("Leaf D");
root.Add(leaf);
root.Remove(leaf);
// Recursively display tree
root.Display(1);
// Wait for user
Console.Read();
}
示例3: UnitTest
//
void UnitTest () {
// 根節點
IComponent theRoot = new Composite("Root");
// 加入兩個最終節點
theRoot.Add ( new Leaf("Leaf1"));
theRoot.Add ( new Leaf("Leaf2"));
// 子節點1
IComponent theChild1 = new Composite("Child1");
// 加入兩個最終節點
theChild1.Add ( new Leaf("Child1.Leaf1"));
theChild1.Add ( new Leaf("Child1.Leaf2"));
theRoot.Add (theChild1);
// 子節點2
// 加入3個最終節點
IComponent theChild2 = new Composite("Child2");
theChild2.Add ( new Leaf("Child2.Leaf1"));
theChild2.Add ( new Leaf("Child2.Leaf2"));
theChild2.Add ( new Leaf("Child2.Leaf3"));
theRoot.Add (theChild2);
// 顯示
theRoot.Operation();
}
示例4: Test
public static void Test()
{
var root = new Composite<Component> { Node = new Component("Component A") };
root.Add(new Component("Component A - 1"));
root.Add(new Component("Component A - 2"));
root.Add(new Component("Component A - 3"));
}
示例5: Demo
public static void Demo()
{
// Create a tree structure
Composite root = new Composite("root");
root.Add(new Leaf("Leaf A"));
root.Add(new Leaf("Leaf B"));
Composite comp = new Composite("Composite X");
comp.Add(new Leaf("Leaf XA"));
comp.Add(new Leaf("Leaf XB"));
root.Add(comp);
root.Add(new Leaf("Leaf C"));
// Add and remove a leaf
Leaf leaf = new Leaf("Leaf D");
root.Add(leaf);
root.Remove(leaf);
// Recursively display tree
root.Display(1);
}
示例6: Main
public static void Main( string[] args )
{
// Create a tree structure
Composite root = new Composite( "root" );
root.Add( new Leaf( "Leaf A" ));
root.Add( new Leaf( "Leaf B" ));
Composite comp = new Composite( "Composite X" );
comp.Add( new Leaf( "Leaf XA" ) );
comp.Add( new Leaf( "Leaf XB" ) );
root.Add( comp );
root.Add( new Leaf( "Leaf C" ));
// Add and remove a leaf
Leaf l = new Leaf( "Leaf D" );
root.Add( l );
root.Remove( l );
// Recursively display nodes
root.Display( 1 );
}
示例7: Composite
public static void Composite()
{
IComponent root = new Composite("root");
root.Add(new Leaf("Leaf A"));
root.Add(new Leaf("Leaf B"));
root.Add(new Leaf("Leaf C"));
Composite comp = new Composite("Composite X");
comp.Add(new Leaf("Leaf XA"));
comp.Add(new Leaf("Leaf XB"));
comp.Add(new Leaf("Leaf XC"));
root.Add(comp);
root.Add(new Leaf("Leaf D"));
Leaf leaf = new Leaf("Leaf Remove");
root.Add(leaf);
root.Remove(leaf);
root.Display(1);
}