Exemplo 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));
        }
        static DisplayPart[] CreateDisplayParts(string?debuggerDisplayString)
        {
            if (debuggerDisplayString is null)
            {
                return(Array.Empty <DisplayPart>());
            }
            if (debuggerDisplayString.Length == 0)
            {
                return new[] { DisplayPart.CreateText(string.Empty) }
            }
            ;

            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 expression = ReadEvalText(debuggerDisplayString, ref pos, sb);
                if (expression.Length != 0)
                {
                    list.Add(DisplayPart.CreateEvaluate(expression));
                }

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

            ObjectCache.Free(ref sb);
            return(ListCache <DisplayPart> .FreeAndToArray(ref list));
        }