mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-20 13:48:16 +08:00
Add parameter value provider support
Adds support for parameter value providers which makes it possible to set custom values for parameters.
This commit is contained in:

committed by
Phil Scott

parent
d1d94cdebe
commit
1dd1945297
@ -11,19 +11,19 @@ namespace Spectre.Console.Tests.Data
|
||||
{
|
||||
}
|
||||
|
||||
public override ValidationResult Validate(ICommandParameterInfo info, object value)
|
||||
public override ValidationResult Validate(CommandParameterContext context)
|
||||
{
|
||||
if (value is int integer)
|
||||
if (context.Value is int integer)
|
||||
{
|
||||
if (integer % 2 == 0)
|
||||
{
|
||||
return ValidationResult.Success();
|
||||
}
|
||||
|
||||
return ValidationResult.Error($"Number is not even ({info?.PropertyName}).");
|
||||
return ValidationResult.Error($"Number is not even ({context.Parameter.PropertyName}).");
|
||||
}
|
||||
|
||||
throw new InvalidOperationException($"Parameter is not a number ({info?.PropertyName}).");
|
||||
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user