16 using Newtonsoft.Json;
17 using Newtonsoft.Json.Linq;
19 using System.Reflection;
32 public override void WriteJson(JsonWriter writer,
object value, JsonSerializer serializer)
34 JObject jo =
new JObject();
35 Type type = value.GetType();
37 foreach (PropertyInfo prop
in type.GetProperties())
41 var attribute = prop.GetCustomAttribute<JsonPropertyAttribute>();
42 object propVal = prop.GetValue(value,
null);
45 jo.Add(attribute.PropertyName ?? prop.Name, JToken.FromObject(propVal, serializer));
59 JsonSerializer serializer
62 JObject token = JObject.Load(reader);
63 var parameterName = (token.GetValue(
"name", StringComparison.OrdinalIgnoreCase) ?? token.GetValue(
"key", StringComparison.OrdinalIgnoreCase))?.Value<string>();
64 if (
string.IsNullOrEmpty(parameterName))
73 if (token.TryGetValue(
"min", StringComparison.OrdinalIgnoreCase, out minToken) &&
74 token.TryGetValue(
"max", StringComparison.OrdinalIgnoreCase, out maxToken))
76 var stepToken = token.GetValue(
"step", StringComparison.OrdinalIgnoreCase)?.Value<decimal>();
77 var minStepToken = token.GetValue(
"minStep", StringComparison.OrdinalIgnoreCase)?.Value<decimal>() ?? token.GetValue(
"min-step", StringComparison.OrdinalIgnoreCase)?.Value<decimal>();
78 if (stepToken.HasValue)
80 if (minStepToken.HasValue)
83 minToken.Value<decimal>(),
84 maxToken.Value<decimal>(),
91 minToken.Value<decimal>(),
92 maxToken.Value<decimal>(),
99 minToken.Value<decimal>(),
100 maxToken.Value<decimal>());
103 else if(token.TryGetValue(
"value", StringComparison.OrdinalIgnoreCase, out value))
108 if (optimizationParameter ==
null)
113 return optimizationParameter;