static void Main(string[] args) { IPrintVisitor consoleVisitor = new ConsolePrintVisitor(); Country usa = new Country("USA", "RedWhiteBlue"); State california = new State("California", "Sacramento"); City newYork = new City("New York", "Bill de Blasio"); usa.Accept(consoleVisitor); california.Accept(consoleVisitor); newYork.Accept(consoleVisitor); usa.Accept(new FilePrintVisitor()); california.Accept(new FilePrintVisitor()); newYork.Accept(new FilePrintVisitor()); }
static void Main(string[] args) { var city = new City(); var monument = new Monument() { Name = "monument named after Pushkin", DateOfCreate = DateTime.Now, }; var restaurant = new Restaurant() { Title = "Povoreshkin", CountOfTables = 10, }; var theatre = new Theatre() { Title = "Vakhtangov theater", CountOfAttractions = 5, }; city.Add(monument); city.Add(restaurant); city.Add(theatre); Console.WriteLine("XML graphic:"); Console.WriteLine(); city.Accept(new XmlVisitor()); Console.WriteLine("Html graphic:"); Console.WriteLine(); city.Accept(new HtmlVisitor()); Console.ReadLine(); }
public void VisitUser(User obj, JToken data) { obj.Id = data.SafeGetValue <String>("id"); obj.FirstName = data.SafeGetValue <String>("first_name"); obj.LastName = data.SafeGetValue <String>("last_name"); obj.ScreenName = data.SafeGetValue <String>("screen_name"); obj.Photo50 = data.SafeGetValue <String>("photo_50"); obj.Photo100 = data.SafeGetValue <String>("photo_100"); obj.Online = data.SafeGetValue <Boolean?>("online"); var cityData = data["city"]; if (cityData != null) { var city = new City(); city.Accept(this, data["city"]); obj.City = city; } var userSex = data.SafeGetValue <String>("sex"); if (!String.IsNullOrEmpty(userSex)) { switch (userSex) { case "1": obj.Sex = UserSex.Female; break; case "2": obj.Sex = UserSex.Male; break; } } try { var bData = data.SafeGetValue <String>("bdate"); if (!String.IsNullOrEmpty(bData)) { // Формат DD.MM if (bData.Length == 5) { var tokens = bData.Split('.'); var month = Int32.Parse(tokens[1]); var day = Int32.Parse(tokens[0]); obj.BirthDay = new DateTime(User.DefaultYear, month, day); } // Формат DD.MM.YYYY if (bData.Length == 10) { var tokens = bData.Split('.'); var year = Int32.Parse(tokens[2]); var month = Int32.Parse(tokens[1]); var day = Int32.Parse(tokens[0]); obj.BirthDay = new DateTime(year, month, day); } } } catch (Exception ex) { // залогировать } }