Exemple #1
0
        public static LanguageExpression ParseExpression(string value)
        {
            if (ExpressionsEngine.IsLanguageExpression(value))
            {
                return(ExpressionsEngine.ParseLanguageExpression(value));
            }

            return(new JTokenExpression(value));
        }
        public static void VisitExpressions <TToken>(TToken input, Action <LanguageExpression> visitFunc)
            where TToken : JToken
        {
            var visitor = new LanguageExpressionVisitor
            {
                OnFunctionExpression = visitFunc,
                OnJTokenExpression   = visitFunc,
            };

            void VisitLanguageExpressions(string value)
            {
                if (ExpressionsEngine.IsLanguageExpression(value))
                {
                    var expression = ExpressionsEngine.ParseLanguageExpression(value);
                    expression.Accept(visitor);
                }
            }

            if (input is JValue jValue && jValue.ToObject <string>() is { } value)
            {
                VisitLanguageExpressions(value);
                return;
            }

            JsonUtility.WalkJsonRecursive(
                input,
                objectAction: @object =>
            {
                foreach (var property in @object.Properties())
                {
                    VisitLanguageExpressions(property.Name);
                }
            },
                tokenAction: token =>
            {
                if (token.Type == JTokenType.String && token.ToObject <string>() is { } value)
                {
                    VisitLanguageExpressions(value);
                }
            });