示例#1
0
        private Boolean TryConvertToLiteralToken(
            TemplateContext context,
            EvaluationResult result,
            out LiteralToken literal)
        {
            if (result.Raw is LiteralToken literal2)
            {
                context.Memory.AddBytes(literal2);
                literal = literal2;
                return(true);
            }

            switch (result.Kind)
            {
            case ValueKind.Null:
                literal = new NullToken(FileId, Line, Column);
                break;

            case ValueKind.Boolean:
                literal = new BooleanToken(FileId, Line, Column, (Boolean)result.Value);
                break;

            case ValueKind.Number:
                literal = new NumberToken(FileId, Line, Column, (Double)result.Value);
                break;

            case ValueKind.String:
                literal = new StringToken(FileId, Line, Column, (String)result.Value);
                break;

            default:
                literal = null;
                return(false);
            }

            context.Memory.AddBytes(literal);
            return(true);
        }
示例#2
0
 internal static void AssertUnexpectedValue(
     this LiteralToken literal,
     string objectDescription)
 {
     throw new ArgumentException($"Error while reading '{objectDescription}'. Unexpected value '{literal.ToString()}'");
 }