Ejemplo n.º 1
0
        static DisplayPart[] CreateDisplayParts(string debuggerDisplayString)
        {
            var list = ListCache <DisplayPart> .AllocList();

            var sb  = ObjectCache.AllocStringBuilder();
            int pos = 0;

            for (;;)
            {
                sb.Clear();
                var text = ReadText(debuggerDisplayString, ref pos, sb);
                if (text.Length != 0)
                {
                    list.Add(DisplayPart.CreateText(text));
                }

                sb.Clear();
                var evalInfo = ReadEvalText(debuggerDisplayString, ref pos, sb);
                if (evalInfo.expression.Length != 0)
                {
                    list.Add(DisplayPart.CreateEvaluate(evalInfo.expression, evalInfo.formatSpecifiers));
                }

                if (pos >= debuggerDisplayString.Length)
                {
                    break;
                }
            }

            ObjectCache.Free(ref sb);
            return(ListCache <DisplayPart> .FreeAndToArray(ref list));
        }
Ejemplo n.º 2
0
        public static (string expression, string[] formatSpecifiers) GetFormatSpecifiers(StringBuilder sb)
        {
            int pos = sb.Length - 1;

            if (pos < 0)
            {
                return(string.Empty, Array.Empty <string>());
            }
            int lastComma = sb.Length;
            var list      = ListCache <string> .AllocList();

            for (;;)
            {
                var commaPos = ReverseIndexOf(sb, ',', pos);
                if (commaPos < 0)
                {
                    break;
                }
                var fs = sb.ToString(commaPos + 1, lastComma - (commaPos + 1)).Trim();
                if (!IsFormatSpecifier(fs))
                {
                    break;
                }
                list.Add(fs);
                lastComma = commaPos;
                pos       = commaPos - 1;
            }
            var expression = sb.ToString(0, lastComma);

            list.Reverse();
            var formatSpecifiers = ListCache <string> .FreeAndToArray(ref list);

            return(expression, formatSpecifiers);
        }