/// <summary> /// Parse a reservation request, passing its information to /// the builder. /// </summary> /// <param name="s">the request</param> public void Parse(String s) { string[] tokens = new Regex(@",\s*").Split(s); for (int i = 0; i < tokens.Length; i += 2) { String type = tokens[i]; String val = tokens[i + 1]; if (String.Compare("date", type, true) == 0) { DateTime d = DateTime.Parse(val); _builder.Date = ReservationBuilder.Futurize(d); } else if (String.Compare("headcount", type, true) == 0) { _builder.Headcount = Int32.Parse(val); } else if (String.Compare("City", type, true) == 0) { _builder.City = val.Trim(); } else if (String.Compare("DollarsPerHead", type, true) == 0) { _builder.DollarsPerHead = (decimal)Double.Parse(val); } else if (String.Compare("HasSite", type, true) == 0) { _builder.HasSite = Boolean.Parse(val); } } }
/// <summary> /// Create a parser that will pass its results to the specified /// builder. /// </summary> /// <param name="builder">the builder to pass parameters to</param> public ReservationParser(ReservationBuilder builder) { _builder = builder; }