public Task <ITypeParserResult <Enum> > ParseAsync(string value, IParameter parameter, CommandContext context) { if (string.IsNullOrWhiteSpace(value)) { ITypeParserResult <Enum> result = new TypeParserFailResult <Enum>(); return(Task.FromResult(result)); } var config = context.CommandServices.GetRequiredService <IOptions <MariCommandsOptions> >().Value; var ignoreCase = IsIgnoreCase(config.Comparison); if (Enum.TryParse(parameter.ParameterInfo.ParameterType, value, ignoreCase, out var parseResult)) { ITypeParserResult <Enum> result = TypeParserSuccessResult <Enum> .FromValue(parseResult as Enum); return(Task.FromResult(result)); } else { ITypeParserResult <Enum> result = new TypeParserFailResult <Enum>(); return(Task.FromResult(result)); } }
/// <summary> /// Creates a new instance of <see cref="NullableTypeParserResult{T}" /> with the specified /// result. /// </summary> /// <param name="result">The original type parser result.</param> public NullableTypeParserResult(ITypeParserResult <T> result) { RealResult = result; Value = result.Value; Success = result.Success; Reason = result.Reason; Exception = result.Exception; }
public Task <ITypeParserResult <string> > ParseAsync(string value, IParameter parameter, CommandContext context) { if (string.IsNullOrWhiteSpace(value)) { ITypeParserResult <string> result = new TypeParserFailResult <string>(); return(Task.FromResult(result)); } else { ITypeParserResult <string> result = TypeParserSuccessResult <string> .FromValue(value); return(Task.FromResult(result)); } }
public Task <ITypeParserResult <T> > ParseAsync(string value, IParameter parameter, CommandContext context) { if (_tryParseDelegate(value, out var parseResult)) { ITypeParserResult <T> result = TypeParserSuccessResult <T> .FromValue(parseResult); return(Task.FromResult(result)); } else { ITypeParserResult <T> result = new TypeParserFailResult <T>(); return(Task.FromResult(result)); } }
/// <summary> /// Creates a new instance of <see cref="NullableTypeParserResult{T}" /> with the specified /// result. /// </summary> /// <param name="result">The original type parser result.</param> /// <returns>A <see cref="NullableTypeParserResult{T}" />.</returns> public static NullableTypeParserResult <T> FromResult(ITypeParserResult <T> result) => new NullableTypeParserResult <T>(result);
/// <summary> /// Creates a new instance of<see cref= "ArgumentTypeParserFailResult" /> with the specified /// <see cref="ITypeParserResult" />. /// </summary> /// <param name="typeParserResult">The result returned from the type parser.</param> /// <returns>A <see cref="ArgumentTypeParserFailResult" />.</returns> public static ArgumentTypeParserFailResult FromTypeParserResult(ITypeParserResult typeParserResult) => new ArgumentTypeParserFailResult(typeParserResult);
/// <summary> /// Creates a new instance of <see cref="ArgumentTypeParserFailResult" /> with the specified /// <see cref="ITypeParserResult" />. /// </summary> /// <param name="typeParserResult">The result returned from the type parser.</param> public ArgumentTypeParserFailResult(ITypeParserResult typeParserResult) { TypeParserResult = typeParserResult; }