public void Visitor_Test() { var structure = new Structure(); var e1 = new Element01() { State = 0 }; var e2 = new Element02() { State = 1 }; var v1 = new VisitorA(); var v2 = new VisitorB(); structure.Elements.Add(e1); structure.Elements.Add(e2); structure.Accept(v1); Assert.IsTrue(e1.State == 2 && e2.State == 3); structure.Accept(v2); Assert.IsTrue(e1.State == 12 && e2.State == 13); }
private static void Main() { var structure = new Structure(); structure.Add(new Person { Name = "TestPerson", Number = "123456" }); structure.Add(new Company { Name = "TestCompany", Number = "09876", RegNumber = "123098" }); structure.Add(new Company { Name = "TestCompany2", Number = "1209876", RegNumber = "12123098" }); structure.Accept(new DictionaryVisitor()); structure.Accept(new ListVisitor()); }