Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        /// <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
                       ));
        }
Ejemplo n.º 3
0
 ImmutableArray <SymbolDisplayPart> ISymbol.ToDisplayParts(SymbolDisplayFormat format)
 {
     return(SymbolDisplay.ToDisplayParts(this, format));
 }
Ejemplo n.º 4
0
 string ISymbol.ToDisplayString(SymbolDisplayFormat format)
 {
     return(SymbolDisplay.ToDisplayString(this, format));
 }
Ejemplo n.º 5
0
 public ImmutableArray <SymbolDisplayPart> ToDisplayParts(SymbolDisplayFormat format = null)
 {
     return(SymbolDisplay.ToDisplayParts(this, format));
 }
Ejemplo n.º 6
0
 public string ToDisplayString(SymbolDisplayFormat format = null)
 {
     return(SymbolDisplay.ToDisplayString(this, format));
 }