Action IRunnerRepository.FindRunner(IParseResult inResult, ConsoleLogEventHandler inEvent) { Action <IParseResult, ConsoleLogEventHandler> act; if (mLookups.TryGetValue(inResult.GetType(), out act)) { return(() => { act(inResult, inEvent); }); } throw new NotSupportedException(inResult.GetType().ToString()); }
public virtual Task SetResult(ModelBindingContext context, IParseResult result, string parameterName, JsonRpcBindingContext jsonRpcBindingContext) { log.LogTrace($"Binding parameter [{parameterName}]"); switch (result) { case SuccessParseResult successBindResult: return(SetResultSafe(context, parameterName, successBindResult, jsonRpcBindingContext.Serializer.Serializer)); case ErrorParseResult errorBindResult: return(SetError(context, parameterName, errorBindResult)); case NoParseResult noParseResult when jsonRpcBindingContext.ParameterMetadata.IsOptional: // key was not in json but is optional parameter return(SetNoResult(context, parameterName, noParseResult)); case NoParseResult noBindResult: // key was not in json and is required return(SetError(context, parameterName, noBindResult)); case NullParseResult nullParseResult when context.ModelMetadata.IsReferenceOrNullableType: // json value was null and type can be null return(SetNullResult(context, parameterName, nullParseResult)); case NullParseResult nullParseResult: // json value was null and type can not be null var error = new ErrorParseResult($"Can not bind null json value to non-nullable parameter of type [{context.ModelMetadata.ModelType.Name}]", nullParseResult.Key); return(SetError(context, parameterName, error)); default: throw new ArgumentOutOfRangeException(nameof(result), result?.GetType().Name); } }
public void Test_ParseObject_ReturnsResult(JObject jObject, string property, BindingStyle style, IParseResult expected) { var result = paramsParserMock.Object.ParseObject(jObject, property, style); result.Should().BeOfType(expected.GetType()); result.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.Type == typeof(ErrorParseResult) && x.Name == nameof(ErrorParseResult.Message)) ); paramsParserMock.Verify(x => x.ParseObject(jObject, property, style)); paramsParserMock.VerifyNoOtherCalls(); }
public void Test_ParseArray_ReturnsResult(JArray jArray, int index, BindingStyle style, IParseResult expected) { var result = paramsParserMock.Object.ParseArray(jArray, index, style); result.Should().BeOfType(expected.GetType()); result.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.RuntimeType == typeof(ErrorParseResult) && x.SelectedMemberInfo.Name == nameof(ErrorParseResult.Message)) ); paramsParserMock.Verify(x => x.ParseArray(jArray, index, style)); paramsParserMock.VerifyNoOtherCalls(); }
private void ProcessExpression(int index) { string toParse = _expression[index]; IParseResult tokenParseResult = TokenParser.Parse(toParse); Type resultType = tokenParseResult.GetType(); ITokenProcessor <IParseResult> processor = _tokenProcessorDictionary[resultType]; Action result = processor.ProcessToken(tokenParseResult, _resultTokens, OutputProcessor); if (result != null) { result.Invoke(); } }
public override Action ProcessToken(IParseResult token, Stack <IParseResult> resultTokens, IOutputProcessor outputProcessor) { ProcessedTokenCount++; //process result var typedToken = ( OperatorParseResult )token; IParseResult operandRight = resultTokens.Pop(); IParseResult operandLeft = resultTokens.Pop(); if (operandLeft == null) { throw new InvalidTokenException(String.Format("Trying to perform {0} on invalid first operand", token.GetType())); } if (operandRight == null) { throw new InvalidTokenException(String.Format("Trying to perform {0} on invalid second operand", token.GetType())); } double leftResult = GetResult(operandLeft); double rightResult = GetResult(operandRight); double result = typedToken.Result.Eval(leftResult, rightResult); var expr = new ResultExpression { Expressions = Tuple.Create(operandLeft, operandRight), Operator = typedToken, Result = result }; resultTokens.Push(new ExpressionParseResult(expr)); return(null); }
Action IRunnerRepository.FindRunner(IParseResult inResult, ConsoleLogEventHandler inEvent) { Action<IParseResult, ConsoleLogEventHandler> act; if (mLookups.TryGetValue(inResult.GetType(), out act)) { return () => { act(inResult, inEvent); }; } throw new NotSupportedException(inResult.GetType().ToString()); }