public FormatterResult <double> GetDouble(string input) { FormatterResult <double> res = new FormatterResult <double>(); FormatterError formatterError = new FormatterError(); if (input == null) { res.Errors.Add(formatterError.Create("String is null")); return(res); } if (input.Length == 0) { res.Errors.Add(formatterError.Create("String is empty")); return(res); } double val = 0; if (!double.TryParse(input, out val)) { res.Errors.Add(formatterError.Create("Cant transform the string")); } res.Value = val; return(res); }
private static double GetDouble() { FormatterResult <double> res = null; StringFormatter stringFormatter = new StringFormatter(); do { string input = Console.ReadLine(); res = stringFormatter.GetDouble(input); if (res.IsValid) { Console.WriteLine("All right"); } else { Console.WriteLine("Errors:"); string s = string.Join("\n", res.Errors.Select(str => str.ErrorMessage)); Console.WriteLine(s); } }while (!res.IsValid); return(res.Value.Value); }