public static bool TryParse(string s, out PersonalInfo info) { info = new PersonalInfo(); WordParser parser = new WordParser(s, SepChar); info.GivenNames = parser.NextWord(); info.Surname = parser.NextWord(); DateTime dob; if (!DateTime.TryParse(parser.NextWord(), out dob)) { info = null; return(false); } info.DateOfBirth = dob; info.PRI = parser.NextWord(); info.Group = parser.NextWord(); info.Level = parser.NextWord(); info.WorkAddress = parser.NextWord(); info.HomeAddress = parser.NextWord(); info.WorkPhoneNumber = parser.NextWord(); info.HomePhoneNumber = parser.NextWord(); return(true); }
public static bool TryParse(string s, out work_period result) { WordParser scanner = new WordParser(s, ','); DateTime fixedDate; DateTime start; DateTime end; TimeSpan ot; TimeSpan premium; TimeSpan wash; TimeSpan cmMins; bool cmOT; string comment; bool check = true; check = DateTime.TryParse(scanner.NextWord(), out fixedDate) ? check : false; check = DateTime.TryParse(scanner.NextWord(), out start) ? check : false; check = DateTime.TryParse(scanner.NextWord(), out end) ? check : false; check = TimeSpan.TryParse(scanner.NextWord(), out ot) ? check : false; check = TimeSpan.TryParse(scanner.NextWord(), out premium) ? check : false; check = TimeSpan.TryParse(scanner.NextWord(), out wash) ? check : false; string str = scanner.NextWord(); if (TimeSpan.TryParse(str, out cmMins) && bool.TryParse(scanner.NextWord(), out cmOT)) { comment = scanner.NextWord(); } else { comment = str; cmMins = TimeSpan.Zero; cmOT = false; } if (!check) { Debug.WriteLine("Parse Fail"); result = null; return(false); } //Need another constructor to handle extra mins work_period period = new work_period(fixedDate, start, end, ot, premium, wash, cmMins, cmOT, comment); result = period; return(true); }