StringBuilder.Debug.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Diagnostics;
  5. namespace System.Text
  6. {
  7. public sealed partial class StringBuilder
  8. {
  9. private void ShowChunks(int maxChunksToShow = 10)
  10. {
  11. int count = 0;
  12. StringBuilder head = this;
  13. StringBuilder? current = this;
  14. while (current != null)
  15. {
  16. if (count < maxChunksToShow)
  17. {
  18. count++;
  19. }
  20. else
  21. {
  22. Debug.Assert(head.m_ChunkPrevious != null);
  23. head = head.m_ChunkPrevious;
  24. }
  25. current = current.m_ChunkPrevious;
  26. }
  27. current = head;
  28. string[] chunks = new string[count];
  29. for (int i = count; i > 0; i--)
  30. {
  31. chunks[i - 1] = new string(current.m_ChunkChars).Replace('\0', '.');
  32. Debug.Assert(current.m_ChunkPrevious != null);
  33. current = current.m_ChunkPrevious;
  34. }
  35. Debug.WriteLine('|' + string.Join('|', chunks) + '|');
  36. }
  37. }
  38. }