FakeDriver.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. //
  2. // FakeDriver.cs: A fake ConsoleDriver for unit tests.
  3. //
  4. using System;
  5. using System.Buffers;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Threading;
  11. using System.Text;
  12. // Alias Console to MockConsole so we don't accidentally use Console
  13. using Console = Terminal.Gui.FakeConsole;
  14. using Unix.Terminal;
  15. using static Terminal.Gui.WindowsConsole;
  16. using System.Drawing;
  17. namespace Terminal.Gui;
  18. /// <summary>
  19. /// Implements a mock ConsoleDriver for unit testing
  20. /// </summary>
  21. public class FakeDriver : ConsoleDriver {
  22. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  23. public class Behaviors {
  24. public bool UseFakeClipboard { get; internal set; }
  25. public bool FakeClipboardAlwaysThrowsNotSupportedException { get; internal set; }
  26. public bool FakeClipboardIsSupportedAlwaysFalse { get; internal set; }
  27. public Behaviors (bool useFakeClipboard = false, bool fakeClipboardAlwaysThrowsNotSupportedException = false, bool fakeClipboardIsSupportedAlwaysTrue = false)
  28. {
  29. UseFakeClipboard = useFakeClipboard;
  30. FakeClipboardAlwaysThrowsNotSupportedException = fakeClipboardAlwaysThrowsNotSupportedException;
  31. FakeClipboardIsSupportedAlwaysFalse = fakeClipboardIsSupportedAlwaysTrue;
  32. // double check usage is correct
  33. Debug.Assert (useFakeClipboard == false && fakeClipboardAlwaysThrowsNotSupportedException == false);
  34. Debug.Assert (useFakeClipboard == false && fakeClipboardIsSupportedAlwaysTrue == false);
  35. }
  36. }
  37. public static FakeDriver.Behaviors FakeBehaviors = new Behaviors ();
  38. public override bool SupportsTrueColor => false;
  39. public FakeDriver ()
  40. {
  41. if (FakeBehaviors.UseFakeClipboard) {
  42. Clipboard = new FakeClipboard (FakeBehaviors.FakeClipboardAlwaysThrowsNotSupportedException, FakeBehaviors.FakeClipboardIsSupportedAlwaysFalse);
  43. } else {
  44. if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
  45. Clipboard = new WindowsClipboard ();
  46. } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
  47. Clipboard = new MacOSXClipboard ();
  48. } else {
  49. if (CursesDriver.Is_WSL_Platform ()) {
  50. Clipboard = new WSLClipboard ();
  51. } else {
  52. Clipboard = new CursesClipboard ();
  53. }
  54. }
  55. }
  56. }
  57. public override void End ()
  58. {
  59. FakeConsole.ResetColor ();
  60. FakeConsole.Clear ();
  61. }
  62. public override void Init (Action terminalResized)
  63. {
  64. FakeConsole.MockKeyPresses.Clear ();
  65. TerminalResized = terminalResized;
  66. Cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
  67. Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
  68. FakeConsole.Clear ();
  69. ResizeScreen ();
  70. // Call InitializeColorSchemes before UpdateOffScreen as it references Colors
  71. CurrentAttribute = MakeColor (Color.White, Color.Black);
  72. InitializeColorSchemes ();
  73. ClearContents ();
  74. }
  75. public override void UpdateScreen ()
  76. {
  77. var savedRow = FakeConsole.CursorTop;
  78. var savedCol = FakeConsole.CursorLeft;
  79. var savedCursorVisible = FakeConsole.CursorVisible;
  80. var top = 0;
  81. var left = 0;
  82. var rows = Rows;
  83. var cols = Cols;
  84. System.Text.StringBuilder output = new System.Text.StringBuilder ();
  85. Attribute redrawAttr = new Attribute ();
  86. var lastCol = -1;
  87. for (var row = top; row < rows; row++) {
  88. if (!_dirtyLines [row]) {
  89. continue;
  90. }
  91. FakeConsole.CursorTop = row;
  92. FakeConsole.CursorLeft = 0;
  93. _dirtyLines [row] = false;
  94. output.Clear ();
  95. for (var col = left; col < cols; col++) {
  96. lastCol = -1;
  97. var outputWidth = 0;
  98. for (; col < cols; col++) {
  99. if (!Contents [row, col].IsDirty) {
  100. if (output.Length > 0) {
  101. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  102. } else if (lastCol == -1) {
  103. lastCol = col;
  104. }
  105. if (lastCol + 1 < cols)
  106. lastCol++;
  107. continue;
  108. }
  109. if (lastCol == -1) {
  110. lastCol = col;
  111. }
  112. Attribute attr = Contents [row, col].Attribute.Value;
  113. // Performance: Only send the escape sequence if the attribute has changed.
  114. if (attr != redrawAttr) {
  115. redrawAttr = attr;
  116. FakeConsole.ForegroundColor = (ConsoleColor)attr.Foreground;
  117. FakeConsole.BackgroundColor = (ConsoleColor)attr.Background;
  118. }
  119. outputWidth++;
  120. var rune = (Rune)Contents [row, col].Runes [0];
  121. output.Append (rune.ToString ());
  122. if (rune.IsSurrogatePair () && rune.GetColumns () < 2) {
  123. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  124. FakeConsole.CursorLeft--;
  125. }
  126. Contents [row, col].IsDirty = false;
  127. }
  128. }
  129. if (output.Length > 0) {
  130. FakeConsole.CursorTop = row;
  131. FakeConsole.CursorLeft = lastCol;
  132. foreach (var c in output.ToString ()) {
  133. FakeConsole.Write (c);
  134. }
  135. }
  136. }
  137. FakeConsole.CursorTop = 0;
  138. FakeConsole.CursorLeft = 0;
  139. //SetCursorVisibility (savedVisibitity);
  140. void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
  141. {
  142. FakeConsole.CursorTop = row;
  143. FakeConsole.CursorLeft = lastCol;
  144. foreach (var c in output.ToString ()) {
  145. FakeConsole.Write (c);
  146. }
  147. output.Clear ();
  148. lastCol += outputWidth;
  149. outputWidth = 0;
  150. }
  151. FakeConsole.CursorTop = savedRow;
  152. FakeConsole.CursorLeft = savedCol;
  153. FakeConsole.CursorVisible = savedCursorVisible;
  154. }
  155. public override void Refresh ()
  156. {
  157. UpdateScreen ();
  158. UpdateCursor ();
  159. }
  160. #region Color Handling
  161. // Cache the list of ConsoleColor values.
  162. private static readonly HashSet<int> ConsoleColorValues = new HashSet<int> (
  163. Enum.GetValues (typeof (ConsoleColor)).OfType<ConsoleColor> ().Select (c => (int)c)
  164. );
  165. void SetColor (int color)
  166. {
  167. if (ConsoleColorValues.Contains (color & 0xffff)) {
  168. FakeConsole.BackgroundColor = (ConsoleColor)(color & 0xffff);
  169. }
  170. if (ConsoleColorValues.Contains ((color >> 16) & 0xffff)) {
  171. FakeConsole.ForegroundColor = (ConsoleColor)((color >> 16) & 0xffff);
  172. }
  173. }
  174. /// <remarks>
  175. /// In the FakeDriver, colors are encoded as an int; same as NetDriver
  176. /// Extracts the foreground and background colors from the encoded value.
  177. /// Assumes a 4-bit encoded value for both foreground and background colors.
  178. /// </remarks>
  179. internal override void GetColors (int value, out Color foreground, out Color background)
  180. {
  181. // Assume a 4-bit encoded value for both foreground and background colors.
  182. foreground = (Color)((value >> 16) & 0xF);
  183. background = (Color)(value & 0xF);
  184. }
  185. /// <remarks>
  186. /// In the FakeDriver, colors are encoded as an int; same as NetDriver
  187. /// However, the foreground color is stored in the most significant 16 bits,
  188. /// and the background color is stored in the least significant 16 bits.
  189. /// </remarks>
  190. public override Attribute MakeColor (Color foreground, Color background)
  191. {
  192. // Encode the colors into the int value.
  193. return new Attribute (
  194. value: ((((int)foreground) & 0xffff) << 16) | (((int)background) & 0xffff),
  195. foreground: foreground,
  196. background: background
  197. );
  198. }
  199. #endregion
  200. public ConsoleKeyInfo FromVKPacketToKConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo)
  201. {
  202. if (consoleKeyInfo.Key != ConsoleKey.Packet) {
  203. return consoleKeyInfo;
  204. }
  205. var mod = consoleKeyInfo.Modifiers;
  206. var shift = (mod & ConsoleModifiers.Shift) != 0;
  207. var alt = (mod & ConsoleModifiers.Alt) != 0;
  208. var control = (mod & ConsoleModifiers.Control) != 0;
  209. var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (consoleKeyInfo.KeyChar, consoleKeyInfo.Modifiers, out uint virtualKey, out _);
  210. return new ConsoleKeyInfo ((char)keyChar, (ConsoleKey)virtualKey, shift, alt, control);
  211. }
  212. Key MapKey (ConsoleKeyInfo keyInfo)
  213. {
  214. switch (keyInfo.Key) {
  215. case ConsoleKey.Escape:
  216. return MapKeyModifiers (keyInfo, Key.Esc);
  217. case ConsoleKey.Tab:
  218. return keyInfo.Modifiers == ConsoleModifiers.Shift ? Key.BackTab : Key.Tab;
  219. case ConsoleKey.Clear:
  220. return MapKeyModifiers (keyInfo, Key.Clear);
  221. case ConsoleKey.Home:
  222. return MapKeyModifiers (keyInfo, Key.Home);
  223. case ConsoleKey.End:
  224. return MapKeyModifiers (keyInfo, Key.End);
  225. case ConsoleKey.LeftArrow:
  226. return MapKeyModifiers (keyInfo, Key.CursorLeft);
  227. case ConsoleKey.RightArrow:
  228. return MapKeyModifiers (keyInfo, Key.CursorRight);
  229. case ConsoleKey.UpArrow:
  230. return MapKeyModifiers (keyInfo, Key.CursorUp);
  231. case ConsoleKey.DownArrow:
  232. return MapKeyModifiers (keyInfo, Key.CursorDown);
  233. case ConsoleKey.PageUp:
  234. return MapKeyModifiers (keyInfo, Key.PageUp);
  235. case ConsoleKey.PageDown:
  236. return MapKeyModifiers (keyInfo, Key.PageDown);
  237. case ConsoleKey.Enter:
  238. return MapKeyModifiers (keyInfo, Key.Enter);
  239. case ConsoleKey.Spacebar:
  240. return MapKeyModifiers (keyInfo, keyInfo.KeyChar == 0 ? Key.Space : (Key)keyInfo.KeyChar);
  241. case ConsoleKey.Backspace:
  242. return MapKeyModifiers (keyInfo, Key.Backspace);
  243. case ConsoleKey.Delete:
  244. return MapKeyModifiers (keyInfo, Key.DeleteChar);
  245. case ConsoleKey.Insert:
  246. return MapKeyModifiers (keyInfo, Key.InsertChar);
  247. case ConsoleKey.PrintScreen:
  248. return MapKeyModifiers (keyInfo, Key.PrintScreen);
  249. case ConsoleKey.Oem1:
  250. case ConsoleKey.Oem2:
  251. case ConsoleKey.Oem3:
  252. case ConsoleKey.Oem4:
  253. case ConsoleKey.Oem5:
  254. case ConsoleKey.Oem6:
  255. case ConsoleKey.Oem7:
  256. case ConsoleKey.Oem8:
  257. case ConsoleKey.Oem102:
  258. case ConsoleKey.OemPeriod:
  259. case ConsoleKey.OemComma:
  260. case ConsoleKey.OemPlus:
  261. case ConsoleKey.OemMinus:
  262. if (keyInfo.KeyChar == 0) {
  263. return Key.Unknown;
  264. }
  265. return (Key)((uint)keyInfo.KeyChar);
  266. }
  267. var key = keyInfo.Key;
  268. if (key >= ConsoleKey.A && key <= ConsoleKey.Z) {
  269. var delta = key - ConsoleKey.A;
  270. if (keyInfo.Modifiers == ConsoleModifiers.Control) {
  271. return (Key)(((uint)Key.CtrlMask) | ((uint)Key.A + delta));
  272. }
  273. if (keyInfo.Modifiers == ConsoleModifiers.Alt) {
  274. return (Key)(((uint)Key.AltMask) | ((uint)Key.A + delta));
  275. }
  276. if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
  277. return MapKeyModifiers (keyInfo, (Key)((uint)Key.A + delta));
  278. }
  279. if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  280. if (keyInfo.KeyChar == 0) {
  281. return (Key)(((uint)Key.AltMask | (uint)Key.CtrlMask) | ((uint)Key.A + delta));
  282. } else {
  283. return (Key)((uint)keyInfo.KeyChar);
  284. }
  285. }
  286. return (Key)((uint)keyInfo.KeyChar);
  287. }
  288. if (key >= ConsoleKey.D0 && key <= ConsoleKey.D9) {
  289. var delta = key - ConsoleKey.D0;
  290. if (keyInfo.Modifiers == ConsoleModifiers.Alt) {
  291. return (Key)(((uint)Key.AltMask) | ((uint)Key.D0 + delta));
  292. }
  293. if (keyInfo.Modifiers == ConsoleModifiers.Control) {
  294. return (Key)(((uint)Key.CtrlMask) | ((uint)Key.D0 + delta));
  295. }
  296. if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
  297. return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
  298. }
  299. if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  300. if (keyInfo.KeyChar == 0 || keyInfo.KeyChar == 30) {
  301. return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
  302. }
  303. }
  304. return (Key)((uint)keyInfo.KeyChar);
  305. }
  306. if (key >= ConsoleKey.F1 && key <= ConsoleKey.F12) {
  307. var delta = key - ConsoleKey.F1;
  308. if ((keyInfo.Modifiers & (ConsoleModifiers.Shift | ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  309. return MapKeyModifiers (keyInfo, (Key)((uint)Key.F1 + delta));
  310. }
  311. return (Key)((uint)Key.F1 + delta);
  312. }
  313. if (keyInfo.KeyChar != 0) {
  314. return MapKeyModifiers (keyInfo, (Key)((uint)keyInfo.KeyChar));
  315. }
  316. return (Key)(0xffffffff);
  317. }
  318. KeyModifiers keyModifiers;
  319. private Key MapKeyModifiers (ConsoleKeyInfo keyInfo, Key key)
  320. {
  321. Key keyMod = new Key ();
  322. if ((keyInfo.Modifiers & ConsoleModifiers.Shift) != 0) {
  323. keyMod = Key.ShiftMask;
  324. }
  325. if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) {
  326. keyMod |= Key.CtrlMask;
  327. }
  328. if ((keyInfo.Modifiers & ConsoleModifiers.Alt) != 0) {
  329. keyMod |= Key.AltMask;
  330. }
  331. return keyMod != Key.Null ? keyMod | key : key;
  332. }
  333. Action<KeyEvent> _keyDownHandler;
  334. Action<KeyEvent> _keyHandler;
  335. Action<KeyEvent> _keyUpHandler;
  336. private CursorVisibility _savedCursorVisibility;
  337. public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
  338. {
  339. _keyDownHandler = keyDownHandler;
  340. _keyHandler = keyHandler;
  341. _keyUpHandler = keyUpHandler;
  342. // Note: Net doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
  343. (mainLoop.MainLoopDriver as FakeMainLoop).KeyPressed += (consoleKey) => ProcessInput (consoleKey);
  344. }
  345. void ProcessInput (ConsoleKeyInfo consoleKey)
  346. {
  347. if (consoleKey.Key == ConsoleKey.Packet) {
  348. consoleKey = FromVKPacketToKConsoleKeyInfo (consoleKey);
  349. }
  350. keyModifiers = new KeyModifiers ();
  351. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Shift)) {
  352. keyModifiers.Shift = true;
  353. }
  354. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Alt)) {
  355. keyModifiers.Alt = true;
  356. }
  357. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Control)) {
  358. keyModifiers.Ctrl = true;
  359. }
  360. var map = MapKey (consoleKey);
  361. if (map == (Key)0xffffffff) {
  362. if ((consoleKey.Modifiers & (ConsoleModifiers.Shift | ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  363. _keyDownHandler (new KeyEvent (map, keyModifiers));
  364. _keyUpHandler (new KeyEvent (map, keyModifiers));
  365. }
  366. return;
  367. }
  368. _keyDownHandler (new KeyEvent (map, keyModifiers));
  369. _keyHandler (new KeyEvent (map, keyModifiers));
  370. _keyUpHandler (new KeyEvent (map, keyModifiers));
  371. }
  372. /// <inheritdoc/>
  373. public override bool GetCursorVisibility (out CursorVisibility visibility)
  374. {
  375. visibility = FakeConsole.CursorVisible
  376. ? CursorVisibility.Default
  377. : CursorVisibility.Invisible;
  378. return FakeConsole.CursorVisible;
  379. }
  380. /// <inheritdoc/>
  381. public override bool SetCursorVisibility (CursorVisibility visibility)
  382. {
  383. _savedCursorVisibility = visibility;
  384. return FakeConsole.CursorVisible = visibility == CursorVisibility.Default;
  385. }
  386. /// <inheritdoc/>
  387. public override bool EnsureCursorVisibility ()
  388. {
  389. if (!(Col >= 0 && Row >= 0 && Col < Cols && Row < Rows)) {
  390. GetCursorVisibility (out CursorVisibility cursorVisibility);
  391. _savedCursorVisibility = cursorVisibility;
  392. SetCursorVisibility (CursorVisibility.Invisible);
  393. return false;
  394. }
  395. SetCursorVisibility (_savedCursorVisibility);
  396. return FakeConsole.CursorVisible;
  397. }
  398. public override void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
  399. {
  400. ProcessInput (new ConsoleKeyInfo (keyChar, key, shift, alt, control));
  401. }
  402. public void SetBufferSize (int width, int height)
  403. {
  404. FakeConsole.SetBufferSize (width, height);
  405. Cols = width;
  406. Rows = height;
  407. SetWindowSize (width, height);
  408. ProcessResize ();
  409. }
  410. public void SetWindowSize (int width, int height)
  411. {
  412. FakeConsole.SetWindowSize (width, height);
  413. if (width != Cols || height != Rows) {
  414. SetBufferSize (width, height);
  415. Cols = width;
  416. Rows = height;
  417. }
  418. ProcessResize ();
  419. }
  420. public void SetWindowPosition (int left, int top)
  421. {
  422. if (Left > 0 || Top > 0) {
  423. Left = 0;
  424. Top = 0;
  425. }
  426. FakeConsole.SetWindowPosition (Left, Top);
  427. }
  428. void ProcessResize ()
  429. {
  430. ResizeScreen ();
  431. ClearContents ();
  432. TerminalResized?.Invoke ();
  433. }
  434. public virtual void ResizeScreen ()
  435. {
  436. if (FakeConsole.WindowHeight > 0) {
  437. // Can raise an exception while is still resizing.
  438. try {
  439. FakeConsole.CursorTop = 0;
  440. FakeConsole.CursorLeft = 0;
  441. FakeConsole.WindowTop = 0;
  442. FakeConsole.WindowLeft = 0;
  443. } catch (System.IO.IOException) {
  444. return;
  445. } catch (ArgumentOutOfRangeException) {
  446. return;
  447. }
  448. }
  449. Clip = new Rect (0, 0, Cols, Rows);
  450. }
  451. public override void UpdateCursor ()
  452. {
  453. if (!EnsureCursorVisibility ()) {
  454. return;
  455. }
  456. // Prevents the exception of size changing during resizing.
  457. try {
  458. // BUGBUG: Why is this using BufferWidth/Height and now Cols/Rows?
  459. if (Col >= 0 && Col < FakeConsole.BufferWidth && Row >= 0 && Row < FakeConsole.BufferHeight) {
  460. FakeConsole.SetCursorPosition (Col, Row);
  461. }
  462. } catch (System.IO.IOException) {
  463. } catch (ArgumentOutOfRangeException) {
  464. }
  465. }
  466. #region Not Implemented
  467. public override void Suspend ()
  468. {
  469. throw new NotImplementedException ();
  470. }
  471. #endregion
  472. public class FakeClipboard : ClipboardBase {
  473. public Exception FakeException = null;
  474. string _contents = string.Empty;
  475. bool _isSupportedAlwaysFalse = false;
  476. public override bool IsSupported => !_isSupportedAlwaysFalse;
  477. public FakeClipboard (bool fakeClipboardThrowsNotSupportedException = false, bool isSupportedAlwaysFalse = false)
  478. {
  479. _isSupportedAlwaysFalse = isSupportedAlwaysFalse;
  480. if (fakeClipboardThrowsNotSupportedException) {
  481. FakeException = new NotSupportedException ("Fake clipboard exception");
  482. }
  483. }
  484. protected override string GetClipboardDataImpl ()
  485. {
  486. if (FakeException != null) {
  487. throw FakeException;
  488. }
  489. return _contents;
  490. }
  491. protected override void SetClipboardDataImpl (string text)
  492. {
  493. if (text == null) {
  494. throw new ArgumentNullException (nameof (text));
  495. }
  496. if (FakeException != null) {
  497. throw FakeException;
  498. }
  499. _contents = text;
  500. }
  501. }
  502. #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
  503. }