private object[] GetParametersUsingCompiledDelgates(RpcJsonReader reader, ConverterInfo converter, JsonSerializer serializer) { if (reader.Read()) { if (reader.TokenType == JsonToken.StartArray) { reader.Read(); var deserializer = converter.ParameterArrayDeserializer ?? (converter.ParameterArrayDeserializer = _parameterArrayDeserializerBuilder.BuildDeserializer(converter.ExposedMethod)); return(deserializer(reader.Context, reader, serializer)); } if (reader.TokenType == JsonToken.StartObject) { reader.Read(); var deserializer = converter.NamedParamsDeserializer ?? (converter.NamedParamsDeserializer = _namedParameterDeserializerBuilder.BuildDeserializer(converter.ExposedMethod)); return(deserializer(reader.Context, reader, serializer)); } if (reader.TokenType == JsonToken.Null) { return(new object[0]); } } throw new Exception("Could not read parameters"); }
public static T GetInstance <T>(RpcJsonReader reader, JsonSerializer serializer) { var instance = serializer.Deserialize <T>(reader); reader.Read(); return(instance); }
private T GetInstanceWithDefault <T>(RpcJsonReader reader, JsonSerializer serializer, T defaultValue) { if (reader.TokenType == JsonToken.Null) { reader.Read(); return(defaultValue); } return(GetInstance <T>(reader, serializer)); }
public static int GetIntValueOrDefault(RpcJsonReader reader, int defaultValue) { if (reader.TokenType != JsonToken.Integer) { return(defaultValue); } var returnValue = (int)reader.Value; reader.Read(); return(returnValue); }
public static int GetIntValue(RpcJsonReader reader, int index) { if (reader.TokenType != JsonToken.Integer) { throw new Exception("Could not get int value for parameter index " + index); } var returnValue = Convert.ToInt32(reader.Value); reader.Read(); return(returnValue); }
public static string GetStringValue(RpcJsonReader reader, int index, string defaultValue, bool hasDefaultValue) { if (reader.TokenType != JsonToken.String) { if (hasDefaultValue) { return(defaultValue); } throw new Exception("Could not get string value for parameter index " + index); } var value = (string)reader.Value; reader.Read(); return(value); }
private object[] DeserializeParameters(HttpContext context, RpcJsonReader reader, JsonSerializer serializer, RpcParameterInfo[] parameters) { var returnParameters = new object[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; if (parameter.HasDefaultValue) { returnParameters[i] = parameter.DefaultValue; } else if (parameter.HttpContext) { returnParameters[i] = context; } else if (parameter.ServiceProvider) { returnParameters[i] = context.RequestServices; } else if (parameter.FromServices) { returnParameters[i] = context.RequestServices.GetService(parameter.ParameterType); } } while (reader.TokenType != JsonToken.EndObject) { if (reader.TokenType == JsonToken.PropertyName) { var propertyName = reader.Value as string; reader.Read(); var found = false; for (var i = 0; i < parameters.Length; i++) { if (string.Compare(propertyName, parameters[i].ParameterName, StringComparison.CurrentCultureIgnoreCase) == 0) { returnParameters[i] = serializer.Deserialize(reader, parameters[i].ParameterType); found = true; break; } } if (!found) { serializer.Deserialize(reader); } reader.Read(); } else { reader.Read(); } } return(returnParameters); }