Beispiel #1
0
        protected override void AddLiteralValue(SpecialType type, object value)
        {
            Debug.Assert(value.GetType().GetTypeInfo().IsPrimitive || value is string || value is decimal);
            var valueString = SymbolDisplay.FormatPrimitive(value, quoteStrings: true, useHexadecimalNumbers: false);

            Debug.Assert(valueString != null);

            var kind = SymbolDisplayPartKind.NumericLiteral;

            switch (type)
            {
            case SpecialType.System_Boolean:
                kind = SymbolDisplayPartKind.Keyword;
                break;

            case SpecialType.System_String:
            case SpecialType.System_Char:
                kind = SymbolDisplayPartKind.StringLiteral;
                break;
            }

            this.builder.Add(CreatePart(kind, null, valueString));
        }
        /// <summary>
        /// Returns the System.String that represents the current TypedConstant.
        /// </summary>
        /// <returns>A System.String that represents the current TypedConstant.</returns>
        public static string ToCSharpString(this TypedConstant constant)
        {
            if (constant.IsNull)
            {
                return("null");
            }

            if (constant.Kind == TypedConstantKind.Array)
            {
                return("{"
                       + string.Join(", ", constant.Values.Select(v => v.ToCSharpString()))
                       + "}");
            }

            if (
                constant.Kind == TypedConstantKind.Type ||
                constant.TypeInternal !.SpecialType == SpecialType.System_Object
                )
            {
                Debug.Assert(constant.Value is object);
                return("typeof(" + constant.Value.ToString() + ")");
            }

            if (constant.Kind == TypedConstantKind.Enum)
            {
                // TODO (tomat): replace with SymbolDisplay
                return(DisplayEnumConstant(constant));
            }

            Debug.Assert(constant.ValueInternal is object);
            return(SymbolDisplay.FormatPrimitive(
                       constant.ValueInternal,
                       quoteStrings: true,
                       useHexadecimalNumbers: false
                       ));
        }
Beispiel #3
0
 ImmutableArray <SymbolDisplayPart> ISymbol.ToDisplayParts(SymbolDisplayFormat format)
 {
     return(SymbolDisplay.ToDisplayParts(this, format));
 }
Beispiel #4
0
 string ISymbol.ToDisplayString(SymbolDisplayFormat format)
 {
     return(SymbolDisplay.ToDisplayString(this, format));
 }
Beispiel #5
0
 public ImmutableArray <SymbolDisplayPart> ToDisplayParts(SymbolDisplayFormat format = null)
 {
     return(SymbolDisplay.ToDisplayParts(this, format));
 }
Beispiel #6
0
 public string ToDisplayString(SymbolDisplayFormat format = null)
 {
     return(SymbolDisplay.ToDisplayString(this, format));
 }