static bool RunValidateProperty(int x) { var m = new MenuOption(); var context = new ValidationContext(m) { MemberName = "x" }; var result = new List <ValidationResult>(); var isValid = Validator.TryValidateObject(x, context, result); return(isValid); //if (result.Any()) //{ // Console.WriteLine(result[0].ErrorMessage); //} }
public void Input() { Calculation c = new Calculation(); Arrays a = new Arrays(); Intro i = new Intro(); Console.Clear(); i.MiniScreenBB(); Console.WriteLine(""); Console.WriteLine("Enter a number between 1 and 10:"); Console.Write(":>"); try { MenuOption m = new MenuOption(); var p = new Program(); m.x = Convert.ToInt32(Console.ReadLine()); if (RunValidateProperty(m.x)) { c.BisectionSearch(Arrays.baseArray, m.x); } //var context = new ValidationContext(m.x); //var result = new List<ValidationResult>(); //var isValid = Validator.TryValidateObject(m.x, context, result); //if (result.Any()) //{ // Console.WriteLine(result[0].ErrorMessage); //} //if (m.x < 0 || m.x > 10) //{ Console.WriteLine("Invalid entry."); Console.ReadLine(); Console.Clear(); i.IntroScreen(); Start(); //} Console.ReadLine(); } catch (Exception e) { Console.WriteLine($"Something went wrong... {e}"); Console.ReadLine(); Start(); } }