#pragma warning disable 1998 /// <summary> /// Validates the response and does a new search with the updated parameters. /// </summary> /// <param name="response">The response from the user.</param> /// <param name="spaceshipState">The current state of the form (what details we have gathered to our spaceship).</param> /// <param name="propertyName">The name of the property queried.</param> /// <returns>The validation result.</returns> private static async Task <ValidateResult> ValidateResponseAsync( object response, Spaceship spaceshipState, string propertyName) { Spaceship spaceshipSearchFilter = new Spaceship(spaceshipState); object value = Spaceship.VerifyPropertyValue(response, propertyName); SpaceshipData spaceshipData = SpaceshipData.Instance; IList <Spaceship> matches = null; if (spaceshipSearchFilter.SetPropertyValue(value, propertyName)) { matches = spaceshipData.SearchForPartialMatches(spaceshipSearchFilter); } bool isValid = (matches != null && matches.Count > 0); ValidateResult validateResult = new ValidateResult { IsValid = (isValid && value != null), Value = value }; string feedbackMessage = string.Empty; if (!isValid) { // Since this was an invalid option, undo the change spaceshipState.ClearPropertyValue(propertyName); string valueAsString = ValueToString(value); System.Diagnostics.Debug.WriteLine($"Value {valueAsString} for property {propertyName} is invalid"); feedbackMessage = $"\"{valueAsString}\" is not a valid option"; } else { // Store the search spaceshipData.LastSearchResults = matches; } if (matches != null && matches.Count > 5) { feedbackMessage = $"Still {matches.Count} options matching your criteria. Let's get some more details!"; } if (!string.IsNullOrEmpty(feedbackMessage)) { System.Diagnostics.Debug.WriteLine(feedbackMessage); validateResult.Feedback = feedbackMessage; } return(validateResult); }