Beispiel #1
0
        public override Ust VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            var token = node.Token;
            var span  = node.GetTextSpan();

            if (token.Value == null)
            {
                return(new NullLiteral(span));
            }

            var str = token.Value as string;

            if (str != null)
            {
                return(new StringLiteral(str, span));
            }

            if (token.Value is char)
            {
                return(new StringLiteral(token.ValueText, span));
            }

            var typeName = token.Value.GetType().Name;

            switch (typeName)
            {
            case "Boolean":
                return(new BooleanLiteral((bool)token.Value, node.GetTextSpan()));

            case "Int32":
            case "UInt32":
            case "Int16":
            case "UInt16":
            case "Byte":
            case "SByte":
            case "Int64":
                return(new IntLiteral(System.Convert.ToInt64(token.Value), node.GetTextSpan()));

            case "UInt64":
                return(new IntLiteral((long)System.Convert.ToUInt64(token.Value), node.GetTextSpan()));

            case "Double":
            case "Single":
            case "Decimal":
                return(new FloatLiteral(System.Convert.ToDouble(token.Value), node.GetTextSpan()));

            default:
                throw new NotImplementedException();
            }
        }