protected override string FormatLiteral(Decimal value, CultureInfo cultureInfo = null)
 {
     return(ObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.None, cultureInfo));
 }
 protected override string FormatLiteral(bool value)
 {
     return(ObjectDisplay.FormatLiteral(value));
 }
 protected override string FormatLiteral(ulong value, CultureInfo cultureInfo = null)
 {
     return(ObjectDisplay.FormatLiteral(value, ObjectFormatterHelpers.GetObjectDisplayOptions(false, false, false), cultureInfo));
 }
        public static string FormatLiteral(string value, ObjectDisplayOptions options)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            StringBuilder builder = new StringBuilder();
            bool          flag1   = options.IncludesOption(ObjectDisplayOptions.UseQuotes);
            bool          flag2   = options.IncludesOption(ObjectDisplayOptions.EscapeNonPrintableCharacters);
            bool          flag3   = flag1 && !flag2 && ObjectDisplay.ContainsNewLine(value);

            if (flag1)
            {
                if (flag3)
                {
                    builder.Append('@');
                }
                builder.Append('"');
            }
            for (int index = 0; index < value.Length; ++index)
            {
                char ch = value[index];
                if (flag2 && CharUnicodeInfo.GetUnicodeCategory(ch) == UnicodeCategory.Surrogate)
                {
                    UnicodeCategory unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(value, index);
                    if (unicodeCategory == UnicodeCategory.Surrogate)
                    {
                        builder.Append("\\u" + ((int)ch).ToString("x4"));
                    }
                    else if (ObjectDisplay.NeedsEscaping(unicodeCategory))
                    {
                        int utf32 = char.ConvertToUtf32(value, index);
                        builder.Append("\\U" + utf32.ToString("x8"));
                        ++index;
                    }
                    else
                    {
                        builder.Append(ch);
                        builder.Append(value[++index]);
                    }
                }
                else
                {
                    string replaceWith;
                    if (flag2 && ObjectDisplay.TryReplaceChar(ch, out replaceWith))
                    {
                        builder.Append(replaceWith);
                    }
                    else if (flag1 && ch == '"')
                    {
                        if (flag3)
                        {
                            builder.Append('"');
                            builder.Append('"');
                        }
                        else
                        {
                            builder.Append('\\');
                            builder.Append('"');
                        }
                    }
                    else
                    {
                        builder.Append(ch);
                    }
                }
            }
            if (flag1)
            {
                builder.Append('"');
            }
            return(builder.ToString());
        }