DisplayName
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
namespace NUnit.Framework.Internal
{
    [System.Runtime.CompilerServices.NullableContext(1)]
    [System.Runtime.CompilerServices.Nullable(0)]
    internal static class DisplayName
    {
        private const string THREE_DOTS = "...";
        public static string GetValueString([System.Runtime.CompilerServices.Nullable(2)] object arg, int stringMax)
        {
            string text = (arg == null) ? "null" : Convert.ToString(arg, CultureInfo.InvariantCulture);
            Array array = arg as Array;
            if (array != null && array.Rank == 1) {
                if (array.Length == 0)
                    text = "[]";
                else {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append('[');
                    int num = Math.Min(array.Length, 5);
                    for (int i = 0; i < num; i++) {
                        if (i > 0)
                            stringBuilder.Append(", ");
                        object value = array.GetValue(i);
                        Array array2 = value as Array;
                        if (array2 != null && array2.Rank == 1) {
                            stringBuilder.Append(array2.GetType().GetElementType().Name);
                            stringBuilder.Append("[]");
                        } else {
                            string valueString = GetValueString(value, stringMax);
                            stringBuilder.Append(valueString);
                        }
                    }
                    if (array.Length > 5)
                        stringBuilder.Append(", ...");
                    stringBuilder.Append(']');
                    text = stringBuilder.ToString();
                }
            } else if (arg is double) {
                double num2 = (double)arg;
                if (double.IsNaN(num2))
                    text = "double.NaN";
                else if (double.IsPositiveInfinity(num2)) {
                    text = "double.PositiveInfinity";
                } else if (double.IsNegativeInfinity(num2)) {
                    text = "double.NegativeInfinity";
                } else if (num2 == 1.7976931348623157E+308) {
                    text = "double.MaxValue";
                } else if (num2 == -1.7976931348623157E+308) {
                    text = "double.MinValue";
                } else {
                    if (text.IndexOf('.') == -1)
                        text += ".0";
                    text += "d";
                }
            } else if (arg is float) {
                float num3 = (float)arg;
                if (float.IsNaN(num3))
                    text = "float.NaN";
                else if (float.IsPositiveInfinity(num3)) {
                    text = "float.PositiveInfinity";
                } else if (float.IsNegativeInfinity(num3)) {
                    text = "float.NegativeInfinity";
                } else if (num3 == 3.4028235E+38) {
                    text = "float.MaxValue";
                } else if (num3 == -3.4028235E+38) {
                    text = "float.MinValue";
                } else {
                    if (text.IndexOf('.') == -1)
                        text += ".0";
                    text += "f";
                }
            } else if (arg is decimal) {
                decimal d = (decimal)arg;
                text = ((d == decimal.MinValue) ? "decimal.MinValue" : ((!(d == decimal.MaxValue)) ? (text + "m") : "decimal.MaxValue"));
            } else if (arg is long) {
                long num4 = (long)arg;
                text = (num4.Equals(-9223372036854775808) ? "long.MinValue" : ((!num4.Equals(9223372036854775807)) ? (text + "L") : "long.MaxValue"));
            } else if (arg is ulong) {
                switch ((ulong)arg) {
                case 0:
                    text = "ulong.MinValue";
                    break;
                case ulong.MaxValue:
                    text = "ulong.MaxValue";
                    break;
                default:
                    text += "UL";
                    break;
                }
            } else {
                string text2 = arg as string;
                if (text2 != null) {
                    bool flag = stringMax > 0 && text2.Length > stringMax;
                    int num5 = flag ? (stringMax - "...".Length) : 0;
                    if (!flag && !MayNeedEscape(text2))
                        text = "\"" + text2 + "\"";
                    else {
                        StringBuilder stringBuilder2 = new StringBuilder();
                        stringBuilder2.Append('"');
                        string text3 = text2;
                        foreach (char c in text3) {
                            stringBuilder2.Append(EscapeCharInString(c));
                            if (flag && stringBuilder2.Length > num5) {
                                stringBuilder2.Append("...");
                                break;
                            }
                        }
                        stringBuilder2.Append('"');
                        text = stringBuilder2.ToString();
                    }
                } else if (arg is char) {
                    char c2 = (char)arg;
                    text = "'" + EscapeSingleChar(c2) + "'";
                } else if (arg is int) {
                    int num6 = (int)arg;
                    if (num6.Equals(2147483647))
                        text = "int.MaxValue";
                    else if (num6.Equals(-2147483648)) {
                        text = "int.MinValue";
                    }
                } else if (arg is uint) {
                    uint num7 = (uint)arg;
                    if (num7.Equals(uint.MaxValue))
                        text = "uint.MaxValue";
                    else if (num7.Equals(0)) {
                        text = "uint.MinValue";
                    }
                } else if (arg is short) {
                    short num8 = (short)arg;
                    if (num8.Equals(short.MaxValue))
                        text = "short.MaxValue";
                    else if (num8.Equals(short.MinValue)) {
                        text = "short.MinValue";
                    }
                } else if (arg is ushort) {
                    ushort num9 = (ushort)arg;
                    if (num9.Equals(ushort.MaxValue))
                        text = "ushort.MaxValue";
                    else if (num9.Equals(0)) {
                        text = "ushort.MinValue";
                    }
                } else if (arg is byte) {
                    byte b = (byte)arg;
                    if (b.Equals(byte.MaxValue))
                        text = "byte.MaxValue";
                    else if (b.Equals(0)) {
                        text = "byte.MinValue";
                    }
                } else if (arg is sbyte) {
                    sbyte b2 = (sbyte)arg;
                    if (b2.Equals(sbyte.MaxValue))
                        text = "sbyte.MaxValue";
                    else if (b2.Equals(sbyte.MinValue)) {
                        text = "sbyte.MinValue";
                    }
                } else {
                    Exception ex = arg as Exception;
                    if (ex != null)
                        text = FormatException(ex);
                }
            }
            return text;
        }
        private static string FormatException(Exception ex)
        {
            StringBuilder stringBuilder = new StringBuilder();
            for (Exception ex2 = ex; ex2 != null; ex2 = ex2.InnerException) {
                stringBuilder.Append(ex2.GetType().Name);
                stringBuilder.Append(": ");
                stringBuilder.Append(ex2.Message);
                if (ex2.InnerException != null)
                    stringBuilder.Append(", ");
            }
            return stringBuilder.ToString();
        }
        private static bool MayNeedEscape(string s)
        {
            foreach (char c in s) {
                if (MayNeedEscape(c))
                    return true;
            }
            return false;
        }
        private static bool MayNeedEscape(char c)
        {
            if (!char.IsLetterOrDigit(c) && c != '.' && c != '/' && c != '-')
                return c != '_';
            return false;
        }
        private static string EscapeSingleChar(char c)
        {
            if (c == '\'')
                return "\\'";
            return EscapeControlChar(c);
        }
        private static string EscapeCharInString(char c)
        {
            if (c == '"')
                return "\\\"";
            return EscapeControlChar(c);
        }
        private static string EscapeControlChar(char c)
        {
            switch (c) {
            case '\\':
                return "\\\\";
            case ' ':
                return "\\0";
            case '':
                return "\\a";
            case '\b':
                return "\\b";
            case '':
                return "\\f";
            case '\n':
                return "\\n";
            case '\r':
                return "\\r";
            case '\t':
                return "\\t";
            case '':
                return "\\v";
            case '
':
            case '
':
            case '
':
                return $"""{(int)c:""}";
            default:
                return c.ToString();
            }
        }
    }
}