public object Apply(object rule, object data) { if (rule is null) { return(null); } if (rule is JsonArray jsonArray) { return(jsonArray.Select(r => Apply(r, data)).ToArray()); } if (rule is JsonObject jsonObject) { var p = jsonObject.First(); var opName = p.Key; var opArgs = p.Value as JsonArray ?? new JsonArray() { p.Value }; var op = operations.GetOperator(opName); return(op(this, opArgs, data)); } return(AdjustType(rule)); }
public object Apply(JToken rule, object data) { if (rule is null) { return(null); } if (rule is JValue) { return(AdjustType((rule as JValue).Value)); } if (rule is JArray) { return((rule as JArray).Select(r => Apply(r, data)).ToArray()); } var ruleObj = (JObject)rule; var p = ruleObj.Properties().First(); var opName = p.Name; var opArgs = (p.Value is JArray) ? (p.Value as JArray).ToArray() : new JToken[] { p.Value }; var op = operations.GetOperator(opName); return(op(this, opArgs, data)); }