コード例 #1
0
        /// <summary>
        /// If a value is pure Expression.
        /// </summary>
        /// <param name="context">Key value structure value context.</param>
        /// <param name="expression">String expression.</param>
        /// <returns>Is pure expression or not.</returns>
        public static bool IsPureExpression(this LGTemplateParser.KeyValueStructureValueContext context, out string expression)
        {
            expression = context.GetText();

            var hasExpression = false;

            foreach (ITerminalNode node in context.children)
            {
                switch (node.Symbol.Type)
                {
                case LGTemplateParser.ESCAPE_CHARACTER_IN_STRUCTURE_BODY:
                    return(false);

                case LGTemplateParser.EXPRESSION_IN_STRUCTURE_BODY:
                    if (hasExpression)
                    {
                        return(false);
                    }

                    hasExpression = true;
                    expression    = node.GetText();
                    break;

                default:
                    if (!string.IsNullOrWhiteSpace(node.GetText()))
                    {
                        return(false);
                    }

                    break;
                }
            }

            return(hasExpression);
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: vman/botbuilder-dotnet
        /// <summary>
        /// If a value is pure Expression.
        /// </summary>
        /// <param name="context">Key value structure value context.</param>
        /// <returns>Is pure expression or not.</returns>
        public static bool IsPureExpression(this LGTemplateParser.KeyValueStructureValueContext context)
        {
            if (context.expressionInStructure() == null ||
                context.expressionInStructure().Length != 1)
            {
                return(false);
            }

            return(context.expressionInStructure(0).GetText().Trim() == context.GetText().Trim());
        }