static void Main(string[] args) { Bank bank = new Bank(); bank.Add(new Person { Name = "Alex", AccNumber = "21551235317" }); bank.Add(new Person { Name = "Sam", AccNumber = "42316421449" }); bank.Add(new Person { Name = "Jessie", AccNumber = "1541255215" }); bank.Add(new Company { Name = "Microsoft", RegNumber = "13684", AccNumber = "69254638726" }); IVisitor vis = new HtmlVisitor(); bank.Accept(vis); vis = new XmlVisitor(); bank.Accept(vis); Console.ReadLine(); }
static void Main(string[] args) { Document doc = new Document(); doc.Parts.Add(new Title() { Text = "titolo del documento" }); doc.Parts.Add(new PlainText() { Text = "testo 1" }); doc.Parts.Add(new Hyperlink() { Url = "http://www.antoniopelleriti.it", Text = "testo" }); doc.Parts.Add(new PlainText() { Text = "testo 2" }); doc.Parts.Add(new EmbeddedImage() { UrlImage = "image.jpg" }); HtmlVisitor visitor = new HtmlVisitor(); doc.Accept(visitor); Console.WriteLine(visitor.Html); }
static void Main(string[] args) { Patient patient = new Patient { FirstName = "Ryszard", }; Visit visit = new Visit { Patient = patient, VisitDate = DateTime.Now, Duration = TimeSpan.FromHours(1), TotalAmount = 150, Medicals = new List <Product> { new Product { Name = "Medical 1" }, new Product { Name = "Medical 2" }, new Product { Name = "Medical 3" } } }; IVisitor visitor = new HtmlVisitor(); VisitHelper.Build(visitor, visit); Console.WriteLine(visitor.Output); }
static void Main(string[] args) { /* * More info: https://manski.net/2013/05/the-visitor-pattern-explained * What problems can the Visitor design pattern solve? * * It should be possible to define a new operation for (some) classe * s of an object structure without changing the classes. * * When new operations are needed frequently and the object structure consists of many unrelated classes, * it's inflexible to add new subclasses each time a new operation is required because "[..] distributing * all these operations across the various node classes leads to a system that's hard to understand, maintain, and change." * */ var doc = new Document(new PlainText { Text = "Plain" }, new Hyperlink { Text = "Hyper", Url = "Link" }); var visitor = new HtmlVisitor(); doc.Accept(visitor); Console.WriteLine($"Plain text plus Hyperlink {visitor.Output}"); var doc2 = new Document(new PlainText { Text = "Plain" }, new Hyperlink { Text = "Hyper", Url = "Link" }); var visitor2 = new LatexVisitor(); doc.Accept(visitor); Console.WriteLine($"Plain text plus Hyperlink {visitor.Output}"); }
static void Main(string[] args) { // Create a new document. var document = new Document(); // Add some elements to the document. document.Elements.Add(new Text("This is plain text.")); document.Elements.Add(new Hyperlink("Hyperlink to Airbrake.io", "http://airbrake.io")); document.Elements.Add(new Paragraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")); document.Elements.Add(new BoldText("Important text to bold!")); // Create a few visitors. var html = new HtmlVisitor(); var markdown = new MarkdownVisitor(); var bbCode = new BbVisitor(); // Force document to accept passed visitors, // which will each uniquely alter output. document.Accept(html); document.Accept(markdown); document.Accept(bbCode); // Log each visitor's output. Logging.LineSeparator("HTML"); Logging.LineSeparator(html.ToString()); Logging.LineSeparator("Markdown"); Logging.LineSeparator(markdown.ToString()); Logging.LineSeparator("BBCode"); Logging.LineSeparator(bbCode.ToString()); }
static void Main(string[] args) { IVisit visit = new HtmlVisitor(); Room hotel = new HotelRoom(300, 1, "hotel"); Room hostel = new HostelRoom(120, 4, "hostel"); Console.WriteLine(hostel.Updateformat(visit)); Console.WriteLine(hotel.Updateformat(visit)); Console.ReadKey(); }