-
is it possible to validate a value of a text prompt based on another variable? var oldWage = 12.5
var newWage = AnsiConsole.Prompt(
new TextPrompt<double>("Enter the workers new hourly wage")
.Validate(newWage =>
{
return newWage switch
{
< oldWage => ValidationResult.Error("[yellow]New wage cannot be less than current wage[/]"),
_ => ValidationResult.Success(),
};
})); |
Beta Was this translation helpful? Give feedback.
Answered by
nils-a
Nov 24, 2021
Replies: 1 comment 1 reply
-
I'm guessing your question is related to the error your code produces:
The reason for this is not really dependent on spectre.console but rather on the C# specs for the return newWage switch
{
var x when x < oldWage => ValidationResult.Error("[yellow]New wage cannot be less than current wage[/]"),
_ => ValidationResult.Success(),
}; alternatively you can always use an |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nils-a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm guessing your question is related to the error your code produces:
The reason for this is not really dependent on spectre.console but rather on the C# specs for the
switch
.You would need to change your switch to a
var
pattern like this:alternatively you can always use an
if
- which in this case would (in my opinion) be much, much clearer.