PowerArgs.TableExpressionProvider.CreateExpression C# (CSharp) Method

CreateExpression() public method

Creates a table expression from the given document info.
public CreateExpression ( PowerArgs.DocumentExpressionContext context ) : IDocumentExpression
context PowerArgs.DocumentExpressionContext The context that contains information about the document being rendered
return IDocumentExpression
        public IDocumentExpression CreateExpression(DocumentExpressionContext context)
        {
            if (context.Body.Count > 0)
            {
                throw new DocumentRenderException("table tags can't have a body", context.ReplacementKeyToken);
            }

            TokenReader<DocumentToken> reader = new TokenReader<DocumentToken>(context.Parameters);

            DocumentToken variableExpressionToken;

            if (reader.TryAdvance(out variableExpressionToken, skipWhitespace: true) == false)
            {
                throw new DocumentRenderException("missing collection expression after table tag", context.ReplacementKeyToken);
            }

            List<DocumentToken> columns = new List<DocumentToken>();

            bool showDefaults = true;
            bool showPossibilities = true;

            while(reader.CanAdvance(skipWhitespace: true))
            {
                var nextToken = reader.Advance(skipWhitespace: true);

                if (nextToken.Value == "-HideDefaults")
                {
                    showDefaults = false;
                }
                else if(nextToken.Value == "-HideEnumValues")
                {
                    showPossibilities = false;
                }
                else
                {
                    columns.Add(nextToken);
                }
            }

            if (columns.Count == 0)
            {
                throw new DocumentRenderException("table elements need to have at least one column parameter", context.ReplacementKeyToken);
            }

            return new TableExpression(variableExpressionToken, columns, context) { ShowDefaultValuesForArguments = showDefaults, ShowPossibleValuesForArguments = showPossibilities };
        }
TableExpressionProvider