public static Expression Var(IList <Expression> values, Stack <Expression> stack = null, JsonLogicOptions options = null) { if (values.Count < 1) { throw new JsonLogicException(); } var a = values[0]; if (a is ConstantExpression ce) { if (ce.Value is string str) { try { return(JsonLogic.GetProperty(str, stack, options)); } catch (JsonLogicException) { if (values.Count > 1) { return(values[1]); } throw; } } if (ce.Type.IsNumericType()) { var array = stack?.FirstOrDefault(e => e.Type.IsArray); if (array != default) { return(Expression.ArrayAccess(array, ce.EnsureIndexNumber())); } } } throw new JsonLogicException(); }
public override Delegate Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => JsonLogic.Parse <bool>(ref reader, typeof(T)).Compile();
public override void Write(Utf8JsonWriter writer, Delegate value, JsonSerializerOptions options) => JsonLogic.Assemble(writer, value, options);