Browse Source

Fixes #3242 - Replaces simple null checks (#3248)

* Replace all 342 `== null` with `is null`

* Replace 354 `!= null` with `is { }`

* Wrap these in conditionals since they break tests against Release configuration

The members they depend on do not exist in Release configuration

* Split these up and dispose properly

This test needs to be revisited for several reasons at some point.

* Fix release configuration tests

* Declare interface these already support

* Annotate constructor properly and use throw helper

* Move class to its own file

* Rename these files so they nest in the solution explorer

* Make this a record type and remove now-redundant/illegal members

* Reference passing to avoid some struct copies

* Simplify this

* Carry reference passing through as appropriate

* Turn this into a record struct

* Remove unused internal constructor and its test

It was only used by that test.

* Simplify this constructor

* This should be a property

* Simplify constructor

* Simplify GetHashCode

* Mark this ignored just in case

* Missed a couple of opportunities for reference passing

* record struct already does this by value

* Remove unused class

* Simplify the type initializer and Reset method

* Implement INotifyCollectionChanged and IDictionary by delegating to ColorSchemes

* Fix for reflection-based configuration

* Make CI  build happy by disambiguiating this attribute
dodexahedron 1 year ago
parent
commit
34bef2c839
94 changed files with 1023 additions and 969 deletions
  1. 43 43
      Terminal.Gui/Application.cs
  2. 2 2
      Terminal.Gui/Clipboard/Clipboard.cs
  3. 2 2
      Terminal.Gui/Clipboard/ClipboardBase.cs
  4. 2 2
      Terminal.Gui/Configuration/AttributeJsonConverter.cs
  5. 1 1
      Terminal.Gui/Configuration/ColorJsonConverter.cs
  6. 1 1
      Terminal.Gui/Configuration/ColorSchemeJsonConverter.cs
  7. 6 6
      Terminal.Gui/Configuration/ConfigProperty.cs
  8. 8 8
      Terminal.Gui/Configuration/ConfigurationManager.cs
  9. 1 1
      Terminal.Gui/Configuration/KeyCodeJsonConverter.cs
  10. 1 1
      Terminal.Gui/Configuration/Scope.cs
  11. 5 5
      Terminal.Gui/Configuration/ScopeJsonConverter.cs
  12. 2 2
      Terminal.Gui/Configuration/SettingsScope.cs
  13. 1 1
      Terminal.Gui/Configuration/ThemeManager.cs
  14. 2 2
      Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
  15. 12 12
      Terminal.Gui/ConsoleDrivers/ConsoleKeyMapping.cs
  16. 2 2
      Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
  17. 2 2
      Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
  18. 7 7
      Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqReq.cs
  19. 9 9
      Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs
  20. 3 3
      Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
  21. 5 5
      Terminal.Gui/ConsoleDrivers/NetDriver.cs
  22. 14 14
      Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
  23. 17 56
      Terminal.Gui/Drawing/Attribute.cs
  24. 0 0
      Terminal.Gui/Drawing/Color.ColorExtensions.cs
  25. 0 0
      Terminal.Gui/Drawing/Color.ColorName.cs
  26. 0 0
      Terminal.Gui/Drawing/Color.ColorParseException.cs
  27. 176 0
      Terminal.Gui/Drawing/ColorScheme.Colors.cs
  28. 8 128
      Terminal.Gui/Drawing/ColorScheme.cs
  29. 5 5
      Terminal.Gui/Drawing/LineCanvas.cs
  30. 2 2
      Terminal.Gui/Drawing/Thickness.cs
  31. 1 1
      Terminal.Gui/FileServices/DefaultFileOperations.cs
  32. 4 4
      Terminal.Gui/FileServices/FileDialogHistory.cs
  33. 2 2
      Terminal.Gui/FileServices/FileDialogState.cs
  34. 1 1
      Terminal.Gui/Input/KeyBinding.cs
  35. 1 1
      Terminal.Gui/Input/Responder.cs
  36. 1 1
      Terminal.Gui/MainLoop.cs
  37. 1 1
      Terminal.Gui/RunState.cs
  38. 3 0
      Terminal.Gui/Terminal.Gui.csproj
  39. 8 8
      Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs
  40. 1 1
      Terminal.Gui/Text/StringExtensions.cs
  41. 8 8
      Terminal.Gui/Text/TextFormatter.cs
  42. 1 1
      Terminal.Gui/View/Adornment/Adornment.cs
  43. 3 3
      Terminal.Gui/View/Adornment/Border.cs
  44. 1 1
      Terminal.Gui/View/Adornment/Margin.cs
  45. 1 1
      Terminal.Gui/View/Adornment/Padding.cs
  46. 3 3
      Terminal.Gui/View/Layout/PosDim.cs
  47. 19 19
      Terminal.Gui/View/Layout/ViewLayout.cs
  48. 5 5
      Terminal.Gui/View/View.cs
  49. 14 14
      Terminal.Gui/View/ViewDrawing.cs
  50. 7 7
      Terminal.Gui/View/ViewKeyboard.cs
  51. 1 1
      Terminal.Gui/View/ViewMouse.cs
  52. 31 31
      Terminal.Gui/View/ViewSubViews.cs
  53. 4 4
      Terminal.Gui/View/ViewText.cs
  54. 1 1
      Terminal.Gui/Views/AutocompleteFilepathContext.cs
  55. 1 1
      Terminal.Gui/Views/CheckBox.cs
  56. 9 9
      Terminal.Gui/Views/ComboBox.cs
  57. 2 2
      Terminal.Gui/Views/Dialog.cs
  58. 21 21
      Terminal.Gui/Views/FileDialog.cs
  59. 1 1
      Terminal.Gui/Views/FileDialogTableSource.cs
  60. 2 2
      Terminal.Gui/Views/GraphView/Series.cs
  61. 2 2
      Terminal.Gui/Views/HexView.cs
  62. 1 1
      Terminal.Gui/Views/Label.cs
  63. 15 15
      Terminal.Gui/Views/ListView.cs
  64. 5 5
      Terminal.Gui/Views/Menu/ContextMenu.cs
  65. 37 37
      Terminal.Gui/Views/Menu/Menu.cs
  66. 56 56
      Terminal.Gui/Views/Menu/MenuBar.cs
  67. 1 1
      Terminal.Gui/Views/MessageBox.cs
  68. 1 1
      Terminal.Gui/Views/ProgressBar.cs
  69. 1 1
      Terminal.Gui/Views/RadioGroup.cs
  70. 30 30
      Terminal.Gui/Views/ScrollBarView.cs
  71. 3 3
      Terminal.Gui/Views/ScrollView.cs
  72. 4 4
      Terminal.Gui/Views/Slider.cs
  73. 2 2
      Terminal.Gui/Views/SpinnerView/SpinnerView.cs
  74. 3 3
      Terminal.Gui/Views/StatusBar.cs
  75. 17 17
      Terminal.Gui/Views/TabView.cs
  76. 2 2
      Terminal.Gui/Views/TableView/ColumnStyle.cs
  77. 1 1
      Terminal.Gui/Views/TableView/ListTableSource.cs
  78. 12 12
      Terminal.Gui/Views/TableView/TableView.cs
  79. 2 2
      Terminal.Gui/Views/TableView/TreeTableSource.cs
  80. 15 15
      Terminal.Gui/Views/TextField.cs
  81. 6 6
      Terminal.Gui/Views/TextValidateField.cs
  82. 47 47
      Terminal.Gui/Views/TextView.cs
  83. 3 3
      Terminal.Gui/Views/TileView.cs
  84. 32 32
      Terminal.Gui/Views/Toplevel.cs
  85. 12 12
      Terminal.Gui/Views/ToplevelOverlapped.cs
  86. 12 12
      Terminal.Gui/Views/TreeView/Branch.cs
  87. 23 23
      Terminal.Gui/Views/TreeView/TreeView.cs
  88. 12 12
      Terminal.Gui/Views/Wizard/Wizard.cs
  89. 2 2
      Terminal.Gui/Views/Wizard/WizardStep.cs
  90. 0 13
      UnitTests/Drawing/AttributeTests.cs
  91. 14 1
      UnitTests/Input/ResponderTests.cs
  92. 60 49
      UnitTests/View/Layout/DimTests.cs
  93. 8 0
      UnitTests/View/ViewTests.cs
  94. 85 70
      UnitTests/Views/WindowTests.cs

+ 43 - 43
Terminal.Gui/Application.cs

@@ -103,7 +103,7 @@ public static partial class Application
         EndAfterFirstIteration = false;
 
         // Driver stuff
-        if (Driver != null)
+        if (Driver is { })
         {
             Driver.SizeChanged -= Driver_SizeChanged;
             Driver.KeyDown -= Driver_KeyDown;
@@ -199,7 +199,7 @@ public static partial class Application
         bool calledViaRunT = false
     )
     {
-        if (_initialized && driver == null)
+        if (_initialized && driver is null)
         {
             return;
         }
@@ -216,7 +216,7 @@ public static partial class Application
         }
 
         // For UnitTests
-        if (driver != null)
+        if (driver is { })
         {
             Driver = driver;
         }
@@ -235,7 +235,7 @@ public static partial class Application
             ForceDriver = driverName;
         }
 
-        if (Driver == null)
+        if (Driver is null)
         {
             PlatformID p = Environment.OSVersion.Platform;
 
@@ -255,7 +255,7 @@ public static partial class Application
                 List<Type> drivers = GetDriverTypes ();
                 Type driverType = drivers.FirstOrDefault (t => t.Name.ToLower () == ForceDriver.ToLower ());
 
-                if (driverType != null)
+                if (driverType is { })
                 {
                     Driver = (ConsoleDriver)Activator.CreateInstance (driverType);
                 }
@@ -377,12 +377,12 @@ public static partial class Application
     /// </remarks>
     public static RunState Begin (Toplevel Toplevel)
     {
-        if (Toplevel == null)
+        if (Toplevel is null)
         {
             throw new ArgumentNullException (nameof (Toplevel));
         }
 
-        if (Toplevel.IsOverlappedContainer && OverlappedTop != Toplevel && OverlappedTop != null)
+        if (Toplevel.IsOverlappedContainer && OverlappedTop != Toplevel && OverlappedTop is { })
         {
             throw new InvalidOperationException ("Only one Overlapped Container is allowed.");
         }
@@ -404,12 +404,12 @@ public static partial class Application
             // If Top was already initialized with Init, and Begin has never been called
             // Top was not added to the Toplevels Stack. It will thus never get disposed.
             // Clean it up here:
-            if (Top != null && Toplevel != Top && !_topLevels.Contains (Top))
+            if (Top is { } && Toplevel != Top && !_topLevels.Contains (Top))
             {
                 Top.Dispose ();
                 Top = null;
             }
-            else if (Top != null && Toplevel != Top && _topLevels.Contains (Top))
+            else if (Top is { } && Toplevel != Top && _topLevels.Contains (Top))
             {
                 Top.OnLeave (Toplevel);
             }
@@ -421,7 +421,7 @@ public static partial class Application
                 var count = 1;
                 var id = (_topLevels.Count + count).ToString ();
 
-                while (_topLevels.Count > 0 && _topLevels.FirstOrDefault (x => x.Id == id) != null)
+                while (_topLevels.Count > 0 && _topLevels.FirstOrDefault (x => x.Id == id) is { })
                 {
                     count++;
                     id = (_topLevels.Count + count).ToString ();
@@ -435,7 +435,7 @@ public static partial class Application
             {
                 Toplevel dup = _topLevels.FirstOrDefault (x => x.Id == Toplevel.Id);
 
-                if (dup == null)
+                if (dup is null)
                 {
                     _topLevels.Push (Toplevel);
                 }
@@ -447,7 +447,7 @@ public static partial class Application
             }
         }
 
-        if (Top == null || Toplevel.IsOverlappedContainer)
+        if (Top is null || Toplevel.IsOverlappedContainer)
         {
             Top = Toplevel;
         }
@@ -474,7 +474,7 @@ public static partial class Application
                   && Toplevel != OverlappedTop
                   && Current?.Modal == true
                   && !_topLevels.Peek ().Modal)
-                 || (OverlappedTop != null && Toplevel != OverlappedTop && Current?.Running == false))
+                 || (OverlappedTop is { } && Toplevel != OverlappedTop && Current?.Running == false))
         {
             refreshDriver = false;
             MoveCurrent (Toplevel);
@@ -536,7 +536,7 @@ public static partial class Application
     {
         if (_initialized)
         {
-            if (Driver != null)
+            if (Driver is { })
             {
                 // Init() has been called and we have a driver, so just run the app.
                 var top = new T ();
@@ -629,7 +629,7 @@ public static partial class Application
             }
             catch (Exception error)
             {
-                if (errorHandler == null)
+                if (errorHandler is null)
                 {
                     throw;
                 }
@@ -767,12 +767,12 @@ public static partial class Application
     /// <param name="state">The state returned by the <see cref="Begin(Toplevel)"/> method.</param>
     public static void RunLoop (RunState state)
     {
-        if (state == null)
+        if (state is null)
         {
             throw new ArgumentNullException (nameof (state));
         }
 
-        if (state.Toplevel == null)
+        if (state.Toplevel is null)
         {
             throw new ObjectDisposedException ("state");
         }
@@ -885,7 +885,7 @@ public static partial class Application
     /// </remarks>
     public static void RequestStop (Toplevel top = null)
     {
-        if (OverlappedTop == null || top == null || (OverlappedTop == null && top != null))
+        if (OverlappedTop is null || top is null || (OverlappedTop is null && top is { }))
         {
             top = Current;
         }
@@ -1011,12 +1011,12 @@ public static partial class Application
     /// <param name="runState">The <see cref="RunState"/> returned by the <see cref="Begin(Toplevel)"/> method.</param>
     public static void End (RunState runState)
     {
-        if (runState == null)
+        if (runState is null)
         {
             throw new ArgumentNullException (nameof (runState));
         }
 
-        if (OverlappedTop != null)
+        if (OverlappedTop is { })
         {
             OverlappedTop.OnChildUnloaded (runState.Toplevel);
         }
@@ -1044,7 +1044,7 @@ public static partial class Application
 
         // If there is a OverlappedTop that is not the RunState.Toplevel then runstate.TopLevel 
         // is a child of MidTop and we should notify the OverlappedTop that it is closing
-        if (OverlappedTop != null && !runState.Toplevel.Modal && runState.Toplevel != OverlappedTop)
+        if (OverlappedTop is { } && !runState.Toplevel.Modal && runState.Toplevel != OverlappedTop)
         {
             OverlappedTop.OnChildClosed (runState.Toplevel);
         }
@@ -1137,7 +1137,7 @@ public static partial class Application
             return null;
         }
 
-        if (_topLevels != null)
+        if (_topLevels is { })
         {
             int count = _topLevels.Count;
 
@@ -1169,11 +1169,11 @@ public static partial class Application
 
     private static View FindTopFromView (View view)
     {
-        View top = view?.SuperView != null && view?.SuperView != Top
+        View top = view?.SuperView is { } && view?.SuperView != Top
                        ? view.SuperView
                        : view;
 
-        while (top?.SuperView != null && top?.SuperView != Top)
+        while (top?.SuperView is { } && top?.SuperView != Top)
         {
             top = top.SuperView;
         }
@@ -1247,10 +1247,10 @@ public static partial class Application
             return false;
         }
 
-        if ((OverlappedTop != null && top?.Modal == true && _topLevels.Peek () != top)
-            || (OverlappedTop != null && Current != OverlappedTop && Current?.Modal == false && top == OverlappedTop)
-            || (OverlappedTop != null && Current?.Modal == false && top != Current)
-            || (OverlappedTop != null && Current?.Modal == true && top == OverlappedTop))
+        if ((OverlappedTop is { } && top?.Modal == true && _topLevels.Peek () != top)
+            || (OverlappedTop is { } && Current != OverlappedTop && Current?.Modal == false && top == OverlappedTop)
+            || (OverlappedTop is { } && Current?.Modal == false && top != Current)
+            || (OverlappedTop is { } && Current?.Modal == true && top == OverlappedTop))
         {
             lock (_topLevels)
             {
@@ -1333,7 +1333,7 @@ public static partial class Application
     /// <param name="view">View that will receive all mouse events until <see cref="UngrabMouse"/> is invoked.</param>
     public static void GrabMouse (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return;
         }
@@ -1348,7 +1348,7 @@ public static partial class Application
     /// <summary>Releases the mouse grab, so mouse events will be routed to the view on which the mouse is.</summary>
     public static void UngrabMouse ()
     {
-        if (MouseGrabView == null)
+        if (MouseGrabView is null)
         {
             return;
         }
@@ -1362,7 +1362,7 @@ public static partial class Application
 
     private static bool OnGrabbingMouse (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return false;
         }
@@ -1375,7 +1375,7 @@ public static partial class Application
 
     private static bool OnUnGrabbingMouse (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return false;
         }
@@ -1388,7 +1388,7 @@ public static partial class Application
 
     private static void OnGrabbedMouse (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return;
         }
@@ -1398,7 +1398,7 @@ public static partial class Application
 
     private static void OnUnGrabbedMouse (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return;
         }
@@ -1433,7 +1433,7 @@ public static partial class Application
 
         var view = View.FindDeepestView (Current, a.MouseEvent.X, a.MouseEvent.Y, out int screenX, out int screenY);
 
-        if (view != null && view.WantContinuousButtonPressed)
+        if (view is { } && view.WantContinuousButtonPressed)
         {
             WantContinuousButtonPressedView = view;
         }
@@ -1442,7 +1442,7 @@ public static partial class Application
             WantContinuousButtonPressedView = null;
         }
 
-        if (view != null)
+        if (view is { })
         {
             a.MouseEvent.View = view;
         }
@@ -1454,7 +1454,7 @@ public static partial class Application
             return;
         }
 
-        if (MouseGrabView != null)
+        if (MouseGrabView is { })
         {
             // If the mouse is grabbed, send the event to the view that grabbed it.
             // The coordinates are relative to the Bounds of the view that grabbed the mouse.
@@ -1487,7 +1487,7 @@ public static partial class Application
             }
         }
 
-        if ((view == null || view == OverlappedTop)
+        if ((view is null || view == OverlappedTop)
             && Current is { Modal: false }
             && OverlappedTop != null
             && a.MouseEvent.Flags != MouseFlags.ReportMousePosition
@@ -1496,7 +1496,7 @@ public static partial class Application
             View top = FindDeepestTop (Top, a.MouseEvent.X, a.MouseEvent.Y, out _, out _);
             view = View.FindDeepestView (top, a.MouseEvent.X, a.MouseEvent.Y, out screenX, out screenY);
 
-            if (view != null && view != OverlappedTop && top != Current)
+            if (view is { } && view != OverlappedTop && top != Current)
             {
                 MoveCurrent ((Toplevel)top);
             }
@@ -1525,7 +1525,7 @@ public static partial class Application
             return false;
         }
 
-        if (view != null)
+        if (view is { })
         {
             // Work inside-out (Padding, Border, Margin)
             // TODO: Debate whether inside-out or outside-in is the right strategy
@@ -1551,7 +1551,7 @@ public static partial class Application
                         View = view
                     };
 
-                    if (_mouseEnteredView == null)
+                    if (_mouseEnteredView is null)
                     {
                         _mouseEnteredView = view;
                         view.OnMouseEnter (me);
@@ -1603,7 +1603,7 @@ public static partial class Application
                     View = view
                 };
 
-                if (_mouseEnteredView == null)
+                if (_mouseEnteredView is null)
                 {
                     _mouseEnteredView = view;
                     view.OnMouseEnter (me);
@@ -1784,7 +1784,7 @@ public static partial class Application
                     keyEvent.Scope = KeyBindingScope.Application;
                     bool? handled = view.OnInvokingKeyBindings (keyEvent);
 
-                    if (handled != null && (bool)handled)
+                    if (handled is { } && (bool)handled)
                     {
                         return true;
                     }

+ 2 - 2
Terminal.Gui/Clipboard/Clipboard.cs

@@ -33,7 +33,7 @@ public static class Clipboard
                 {
                     string clipData = Application.Driver.Clipboard.GetClipboardData ();
 
-                    if (clipData == null)
+                    if (clipData is null)
                     {
                         // throw new InvalidOperationException ($"{Application.Driver.GetType ().Name}.GetClipboardData returned null instead of string.Empty");
                         clipData = string.Empty;
@@ -55,7 +55,7 @@ public static class Clipboard
             {
                 if (IsSupported)
                 {
-                    if (value == null)
+                    if (value is null)
                     {
                         value = string.Empty;
                     }

+ 2 - 2
Terminal.Gui/Clipboard/ClipboardBase.cs

@@ -17,7 +17,7 @@ public abstract class ClipboardBase : IClipboard
         {
             string result = GetClipboardDataImpl ();
 
-            if (result == null)
+            if (result is null)
             {
                 return string.Empty;
             }
@@ -35,7 +35,7 @@ public abstract class ClipboardBase : IClipboard
     /// <exception cref="NotSupportedException">Thrown if it was not possible to paste to the OS clipboard.</exception>
     public void SetClipboardData (string text)
     {
-        if (text == null)
+        if (text is null)
         {
             throw new ArgumentNullException (nameof (text));
         }

+ 2 - 2
Terminal.Gui/Configuration/AttributeJsonConverter.cs

@@ -13,7 +13,7 @@ internal class AttributeJsonConverter : JsonConverter<Attribute>
     {
         get
         {
-            if (_instance == null)
+            if (_instance is null)
             {
                 _instance = new AttributeJsonConverter ();
             }
@@ -37,7 +37,7 @@ internal class AttributeJsonConverter : JsonConverter<Attribute>
         {
             if (reader.TokenType == JsonTokenType.EndObject)
             {
-                if (foreground == null || background == null)
+                if (foreground is null || background is null)
                 {
                     throw new JsonException ("Both Foreground and Background colors must be provided.");
                 }

+ 1 - 1
Terminal.Gui/Configuration/ColorJsonConverter.cs

@@ -13,7 +13,7 @@ internal class ColorJsonConverter : JsonConverter<Color>
     {
         get
         {
-            if (_instance == null)
+            if (_instance is null)
             {
                 _instance = new ColorJsonConverter ();
             }

+ 1 - 1
Terminal.Gui/Configuration/ColorSchemeJsonConverter.cs

@@ -13,7 +13,7 @@ internal class ColorSchemeJsonConverter : JsonConverter<ColorScheme>
     {
         get
         {
-            if (instance == null)
+            if (instance is null)
             {
                 instance = new ColorSchemeJsonConverter ();
             }

+ 6 - 6
Terminal.Gui/Configuration/ConfigProperty.cs

@@ -35,11 +35,11 @@ public class ConfigProperty
     /// <returns></returns>
     public bool Apply ()
     {
-        if (PropertyValue != null)
+        if (PropertyValue is { })
         {
             try
             {
-                if (PropertyInfo?.GetValue (null) != null)
+                if (PropertyInfo?.GetValue (null) is { })
                 {
                     PropertyInfo?.SetValue (null, DeepMemberwiseCopy (PropertyValue, PropertyInfo?.GetValue (null)));
                 }
@@ -47,7 +47,7 @@ public class ConfigProperty
             catch (TargetInvocationException tie)
             {
                 // Check if there is an inner exception
-                if (tie.InnerException != null)
+                if (tie.InnerException is { })
                 {
                     // Handle the inner exception separately without catching the outer exception
                     Exception? innerException = tie.InnerException;
@@ -96,14 +96,14 @@ public class ConfigProperty
 
     internal object? UpdateValueFrom (object source)
     {
-        if (source == null)
+        if (source is null)
         {
             return PropertyValue;
         }
 
         Type? ut = Nullable.GetUnderlyingType (PropertyInfo!.PropertyType);
 
-        if (source.GetType () != PropertyInfo!.PropertyType && ut != null && source.GetType () != ut)
+        if (source.GetType () != PropertyInfo!.PropertyType && ut is { } && source.GetType () != ut)
         {
             throw new ArgumentException (
                                          $"The source object ({
@@ -116,7 +116,7 @@ public class ConfigProperty
                                         );
         }
 
-        if (PropertyValue != null)
+        if (PropertyValue is { })
         {
             PropertyValue = DeepMemberwiseCopy (source, PropertyValue);
         }

+ 8 - 8
Terminal.Gui/Configuration/ConfigurationManager.cs

@@ -145,7 +145,7 @@ public static class ConfigurationManager
     {
         get
         {
-            if (_settings == null)
+            if (_settings is null)
             {
                 throw new InvalidOperationException (
                                                      "ConfigurationManager has not been initialized. Call ConfigurationManager.Reset() before accessing the Settings property."
@@ -320,7 +320,7 @@ public static class ConfigurationManager
     {
         Debug.WriteLine (@"ConfigurationManager.Reset()");
 
-        if (_allConfigProperties == null)
+        if (_allConfigProperties is null)
         {
             Initialize ();
         }
@@ -364,12 +364,12 @@ public static class ConfigurationManager
     /// <returns><paramref name="destination"/> updated from <paramref name="source"/></returns>
     internal static object? DeepMemberwiseCopy (object? source, object? destination)
     {
-        if (destination == null)
+        if (destination is null)
         {
             throw new ArgumentNullException (nameof (destination));
         }
 
-        if (source == null)
+        if (source is null)
         {
             return null!;
         }
@@ -432,11 +432,11 @@ public static class ConfigurationManager
             object? sourceVal = sourceProp.GetValue (source);
             object? destVal = destProp.GetValue (destination);
 
-            if (sourceVal != null)
+            if (sourceVal is { })
             {
                 try
                 {
-                    if (destVal != null)
+                    if (destVal is { })
                     {
                         // Recurse
                         destProp.SetValue (destination, DeepMemberwiseCopy (sourceVal, destVal));
@@ -474,7 +474,7 @@ public static class ConfigurationManager
     /// </remarks>
     internal static void GetHardCodedDefaults ()
     {
-        if (_allConfigProperties == null)
+        if (_allConfigProperties is null)
         {
             throw new InvalidOperationException ("Initialize must be called first.");
         }
@@ -483,7 +483,7 @@ public static class ConfigurationManager
         ThemeManager.GetHardCodedDefaults ();
         AppSettings?.RetrieveValues ();
 
-        foreach (KeyValuePair<string, ConfigProperty> p in Settings!.Where (cp => cp.Value.PropertyInfo != null))
+        foreach (KeyValuePair<string, ConfigProperty> p in Settings!.Where (cp => cp.Value.PropertyInfo is { }))
         {
             Settings! [p.Key].PropertyValue = p.Value.PropertyInfo?.GetValue (null);
         }

+ 1 - 1
Terminal.Gui/Configuration/KeyCodeJsonConverter.cs

@@ -126,7 +126,7 @@ internal class KeyCodeJsonConverter : JsonConverter<KeyCode>
 
         var keyName = (value & ~KeyCode.CtrlMask & ~KeyCode.ShiftMask & ~KeyCode.AltMask).ToString ();
 
-        if (keyName != null)
+        if (keyName is { })
         {
             writer.WriteString ("Key", keyName);
         }

+ 1 - 1
Terminal.Gui/Configuration/Scope.cs

@@ -21,7 +21,7 @@ public class Scope<T> : Dictionary<string, ConfigProperty>
     /// <summary>Retrieves the values of the properties of this scope from their corresponding static properties.</summary>
     public void RetrieveValues ()
     {
-        foreach (KeyValuePair<string, ConfigProperty> p in this.Where (cp => cp.Value.PropertyInfo != null))
+        foreach (KeyValuePair<string, ConfigProperty> p in this.Where (cp => cp.Value.PropertyInfo is { }))
         {
             p.Value.RetrieveValue ();
         }

+ 5 - 5
Terminal.Gui/Configuration/ScopeJsonConverter.cs

@@ -39,7 +39,7 @@ internal class ScopeJsonConverter<scopeT> : JsonConverter<scopeT> where scopeT :
             string? propertyName = reader.GetString ();
             reader.Read ();
 
-            if (propertyName != null && scope!.TryGetValue (propertyName, out ConfigProperty? configProp))
+            if (propertyName is { } && scope!.TryGetValue (propertyName, out ConfigProperty? configProp))
             {
                 // This property name was found in the Scope's ScopeProperties dictionary
                 // Figure out if it needs a JsonConverter and if so, create one
@@ -54,7 +54,7 @@ internal class ScopeJsonConverter<scopeT> : JsonConverter<scopeT> where scopeT :
                     {
                         var factory = (JsonConverterFactory)converter;
 
-                        if (propertyType != null && factory.CanConvert (propertyType))
+                        if (propertyType is { } && factory.CanConvert (propertyType))
                         {
                             converter = factory.CreateConverter (propertyType, options);
                         }
@@ -106,7 +106,7 @@ internal class ScopeJsonConverter<scopeT> : JsonConverter<scopeT> where scopeT :
                                                                p.GetCustomAttribute (typeof (JsonIncludeAttribute)) as
                                                                    JsonIncludeAttribute;
 
-                                                           if (jia != null)
+                                                           if (jia is { })
                                                            {
                                                                var jpna =
                                                                    p.GetCustomAttribute (
@@ -130,7 +130,7 @@ internal class ScopeJsonConverter<scopeT> : JsonConverter<scopeT> where scopeT :
                                                       )
                                                .FirstOrDefault ();
 
-                if (property != null)
+                if (property is { })
                 {
                     PropertyInfo prop = scope.GetType ().GetProperty (propertyName!)!;
                     prop.SetValue (scope, JsonSerializer.Deserialize (ref reader, prop.PropertyType, options));
@@ -196,7 +196,7 @@ internal class ScopeJsonConverter<scopeT> : JsonConverter<scopeT> where scopeT :
                     }
                 }
 
-                if (p.Value.PropertyValue != null)
+                if (p.Value.PropertyValue is { })
                 {
                     converter.GetType ()
                              .GetMethod ("Write")

+ 2 - 2
Terminal.Gui/Configuration/SettingsScope.cs

@@ -102,7 +102,7 @@ public class SettingsScope : Scope<SettingsScope>
     /// <param name="resourceName"></param>
     public SettingsScope? UpdateFromResource (Assembly assembly, string resourceName)
     {
-        if (resourceName == null || string.IsNullOrEmpty (resourceName))
+        if (resourceName is null || string.IsNullOrEmpty (resourceName))
         {
             Debug.WriteLine (
                              $"ConfigurationManager: Resource \"{resourceName}\" does not exist in \"{assembly.GetName ().Name}\"."
@@ -113,7 +113,7 @@ public class SettingsScope : Scope<SettingsScope>
 
         using Stream? stream = assembly.GetManifestResourceStream (resourceName)!;
 
-        if (stream == null)
+        if (stream is null)
         {
             Debug.WriteLine (
                              $"ConfigurationManager: Failed to read resource \"{resourceName}\" from \"{assembly.GetName ().Name}\"."

+ 1 - 1
Terminal.Gui/Configuration/ThemeManager.cs

@@ -78,7 +78,7 @@ public class ThemeManager : IDictionary<string, ThemeScope>
                    Dictionary<string, ThemeScope>; // themes ?? new Dictionary<string, ThemeScope> ();
         set =>
 
-            //if (themes == null || value == null) {
+            //if (themes is null || value is null) {
             //	themes = value;
             //} else {
             //	themes = (Dictionary<string, ThemeScope>)DeepMemberwiseCopy (value!, themes!)!;

+ 2 - 2
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -488,7 +488,7 @@ public abstract class ConsoleDriver
         get => _currentAttribute;
         set
         {
-            if (Application.Driver != null)
+            if (Application.Driver is { })
             {
                 _currentAttribute = new Attribute (value.Foreground, value.Background);
 
@@ -520,7 +520,7 @@ public abstract class ConsoleDriver
     /// <param name="foreground">The foreground color.</param>
     /// <param name="background">The background color.</param>
     /// <returns>The attribute for the foreground and background colors.</returns>
-    public virtual Attribute MakeColor (Color foreground, Color background)
+    public virtual Attribute MakeColor (in Color foreground, in Color background)
     {
         // Encode the colors into the int value.
         return new Attribute (

+ 12 - 12
Terminal.Gui/ConsoleDrivers/ConsoleKeyMapping.cs

@@ -155,7 +155,7 @@ public static class ConsoleKeyMapping
                 ScanCodeMapping sCode =
                     _scanCodes.FirstOrDefault (e => e.UnicodeChar == keyValue && e.Modifiers == modifiers);
 
-                if (sCode == null && modifiers == (ConsoleModifiers.Alt | ConsoleModifiers.Control))
+                if (sCode is null && modifiers == (ConsoleModifiers.Alt | ConsoleModifiers.Control))
                 {
                     return _scanCodes.FirstOrDefault (e => e.UnicodeChar == keyValue && e.Modifiers == 0);
                 }
@@ -164,7 +164,7 @@ public static class ConsoleKeyMapping
             case "VirtualKey":
                 sCode = _scanCodes.FirstOrDefault (e => e.VirtualKey == (VK)keyValue && e.Modifiers == modifiers);
 
-                if (sCode == null && modifiers == (ConsoleModifiers.Alt | ConsoleModifiers.Control))
+                if (sCode is null && modifiers == (ConsoleModifiers.Alt | ConsoleModifiers.Control))
                 {
                     return _scanCodes.FirstOrDefault (e => e.VirtualKey == (VK)keyValue && e.Modifiers == 0);
                 }
@@ -184,7 +184,7 @@ public static class ConsoleKeyMapping
         ConsoleModifiers mod = GetModifiers (consoleKeyInfo.Modifiers);
         ScanCodeMapping scode = GetScanCode ("VirtualKey", (uint)consoleKeyInfo.Key, mod);
 
-        if (scode != null)
+        if (scode is { })
         {
             return scode.ScanCode;
         }
@@ -206,7 +206,7 @@ public static class ConsoleKeyMapping
             ConsoleModifiers mod = GetModifiers (modifiers);
             ScanCodeMapping scode = GetScanCode ("VirtualKey", keyValue, mod);
 
-            if (scode != null)
+            if (scode is { })
             {
                 return new ConsoleKeyInfo (
                                            (char)scode.UnicodeChar,
@@ -328,12 +328,12 @@ public static class ConsoleKeyMapping
         {
             ScanCodeMapping sCode = _scanCodes.FirstOrDefault (e => e.UnicodeChar == keyValue);
 
-            if (sCode == null)
+            if (sCode is null)
             {
                 consoleKey = (byte)(keyValue & byte.MaxValue);
                 sCode = _scanCodes.FirstOrDefault (e => e.VirtualKey == (VK)consoleKey);
 
-                if (sCode == null)
+                if (sCode is null)
                 {
                     consoleKey = 0;
                     outputChar = keyValue;
@@ -561,18 +561,18 @@ public static class ConsoleKeyMapping
             scode = GetScanCode ("VirtualKey", decodedChar, mod);
         }
 
-        if (isConsoleKey && scode != null)
+        if (isConsoleKey && scode is { })
         {
             consoleKey = (uint)scode.VirtualKey;
             keyChar = scode.UnicodeChar;
             scanCode = scode.ScanCode;
         }
 
-        if (scode == null)
+        if (scode is null)
         {
             scode = unicodeChar != 0 ? GetScanCode ("UnicodeChar", decodedChar, mod) : null;
 
-            if (scode != null)
+            if (scode is { })
             {
                 consoleKey = (uint)scode.VirtualKey;
                 keyChar = scode.UnicodeChar;
@@ -593,7 +593,7 @@ public static class ConsoleKeyMapping
                     consoleKey = char.ToUpper (stFormD [i]);
                     scode = GetScanCode ("VirtualKey", char.ToUpper (stFormD [i]), 0);
 
-                    if (scode != null)
+                    if (scode is { })
                     {
                         scanCode = scode.ScanCode;
                     }
@@ -605,7 +605,7 @@ public static class ConsoleKeyMapping
         {
             scode = GetScanCode ("VirtualKey", keyChar, mod);
 
-            if (scode != null)
+            if (scode is { })
             {
                 consoleKey = (uint)scode.VirtualKey;
                 keyChar = scode.UnicodeChar;
@@ -2520,7 +2520,7 @@ public static class ConsoleKeyMapping
             // try to get the ConsoleKey
             ScanCodeMapping scode = _scanCodes.FirstOrDefault (e => e.UnicodeChar == keyChar);
 
-            if (scode != null)
+            if (scode is { })
             {
                 consoleKey = (ConsoleKey)scode.VirtualKey;
             }

+ 2 - 2
Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

@@ -282,7 +282,7 @@ internal class CursesDriver : ConsoleDriver
         StopReportingMouseMoves ();
         SetCursorVisibility (CursorVisibility.Default);
 
-        if (_mainLoopDriver != null)
+        if (_mainLoopDriver is { })
         {
             _mainLoopDriver.RemoveWatch (_processInputToken);
         }
@@ -835,7 +835,7 @@ internal class CursesDriver : ConsoleDriver
     ///     bits, and the background color is stored in the least significant 4 bits. The Terminal.GUi Color values are
     ///     converted to curses color encoding before being encoded.
     /// </remarks>
-    public override Attribute MakeColor (Color foreground, Color background)
+    public override Attribute MakeColor (in Color foreground, in Color background)
     {
         if (!RunningUnitTests)
         {

+ 2 - 2
Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs

@@ -118,7 +118,7 @@ internal class UnixMainLoop : IMainLoopDriver
             _cursesDriver.ProcessWinChange ();
         }
 
-        if (_pollMap == null)
+        if (_pollMap is null)
         {
             return;
         }
@@ -159,7 +159,7 @@ internal class UnixMainLoop : IMainLoopDriver
     /// </remarks>
     internal object AddWatch (int fileDescriptor, Condition condition, Func<MainLoop, bool> callback)
     {
-        if (callback == null)
+        if (callback is null)
         {
             throw new ArgumentNullException (nameof (callback));
         }

+ 7 - 7
Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqReq.cs

@@ -48,11 +48,11 @@ public class EscSeqRequests
         {
             EscSeqReqStatus found = Statuses.Find (x => x.Terminator == terminator);
 
-            if (found == null)
+            if (found is null)
             {
                 Statuses.Add (new EscSeqReqStatus (terminator, numReq));
             }
-            else if (found != null && found.NumOutstanding < found.NumRequests)
+            else if (found is { } && found.NumOutstanding < found.NumRequests)
             {
                 found.NumOutstanding = Math.Min (found.NumOutstanding + numReq, found.NumRequests);
             }
@@ -71,12 +71,12 @@ public class EscSeqRequests
         {
             EscSeqReqStatus found = Statuses.Find (x => x.Terminator == terminator);
 
-            if (found == null)
+            if (found is null)
             {
                 return false;
             }
 
-            if (found != null && found.NumOutstanding > 0)
+            if (found is { } && found.NumOutstanding > 0)
             {
                 return true;
             }
@@ -102,16 +102,16 @@ public class EscSeqRequests
         {
             EscSeqReqStatus found = Statuses.Find (x => x.Terminator == terminator);
 
-            if (found == null)
+            if (found is null)
             {
                 return;
             }
 
-            if (found != null && found.NumOutstanding == 0)
+            if (found is { } && found.NumOutstanding == 0)
             {
                 Statuses.Remove (found);
             }
-            else if (found != null && found.NumOutstanding > 0)
+            else if (found is { } && found.NumOutstanding > 0)
             {
                 found.NumOutstanding--;
 

+ 9 - 9
Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs

@@ -200,7 +200,7 @@ public static class EscSeqUtils
         switch (c1Control)
         {
             case "ESC":
-                if (values == null && string.IsNullOrEmpty (terminator))
+                if (values is null && string.IsNullOrEmpty (terminator))
                 {
                     key = ConsoleKey.Escape;
 
@@ -262,7 +262,7 @@ public static class EscSeqUtils
                     return;
                 }
 
-                if (escSeqRequests != null && escSeqRequests.HasResponse (terminator))
+                if (escSeqRequests is { } && escSeqRequests.HasResponse (terminator))
                 {
                     isResponse = true;
                     escSeqRequests.Remove (terminator);
@@ -515,7 +515,7 @@ public static class EscSeqUtils
     /// </returns>
     public static (string c1Control, string code, string [] values, string terminating) GetEscapeResult (char [] kChar)
     {
-        if (kChar == null || kChar.Length == 0)
+        if (kChar is null || kChar.Length == 0)
         {
             return (null, null, null, null);
         }
@@ -866,8 +866,8 @@ public static class EscSeqUtils
                  || buttonState == MouseFlags.Button2Pressed
                  || buttonState == MouseFlags.Button3Pressed
                  || buttonState == MouseFlags.Button4Pressed)
-             && lastMouseButtonPressed == null)
-            || (isButtonPressed && lastMouseButtonPressed != null && buttonState.HasFlag (MouseFlags.ReportMousePosition)))
+             && lastMouseButtonPressed is null)
+            || (isButtonPressed && lastMouseButtonPressed is { } && buttonState.HasFlag (MouseFlags.ReportMousePosition)))
         {
             mouseFlags [0] = buttonState;
             lastMouseButtonPressed = buttonState;
@@ -1038,7 +1038,7 @@ public static class EscSeqUtils
         {
             foreach (ManagementObject mo in mos.Get ())
             {
-                if (mo ["ParentProcessId"] != null)
+                if (mo ["ParentProcessId"] is { })
                 {
                     try
                     {
@@ -1131,7 +1131,7 @@ public static class EscSeqUtils
     /// <returns>The <see cref="ConsoleKeyInfo"/> resized.</returns>
     public static ConsoleKeyInfo [] ResizeArray (ConsoleKeyInfo consoleKeyInfo, ConsoleKeyInfo [] cki)
     {
-        Array.Resize (ref cki, cki == null ? 1 : cki.Length + 1);
+        Array.Resize (ref cki, cki is null ? 1 : cki.Length + 1);
         cki [cki.Length - 1] = consoleKeyInfo;
 
         return cki;
@@ -1232,12 +1232,12 @@ public static class EscSeqUtils
 
             View view = Application.WantContinuousButtonPressedView;
 
-            if (view == null)
+            if (view is null)
             {
                 break;
             }
 
-            if (isButtonPressed && lastMouseButtonPressed != null && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
+            if (isButtonPressed && lastMouseButtonPressed is { } && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
             {
                 Application.Invoke (() => continuousButtonPressedHandler (mouseFlag, point ?? Point.Empty));
             }

+ 3 - 3
Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs

@@ -513,7 +513,7 @@ public class FakeDriver : ConsoleDriver
 
         protected override string GetClipboardDataImpl ()
         {
-            if (FakeException != null)
+            if (FakeException is { })
             {
                 throw FakeException;
             }
@@ -523,12 +523,12 @@ public class FakeDriver : ConsoleDriver
 
         protected override void SetClipboardDataImpl (string text)
         {
-            if (text == null)
+            if (text is null)
             {
                 throw new ArgumentNullException (nameof (text));
             }
 
-            if (FakeException != null)
+            if (FakeException is { })
             {
                 throw FakeException;
             }

+ 5 - 5
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -262,7 +262,7 @@ internal class NetEvents : IDisposable
                     if ((consoleKeyInfo.KeyChar == (char)KeyCode.Esc && !_isEscSeq)
                         || (consoleKeyInfo.KeyChar != (char)KeyCode.Esc && _isEscSeq))
                     {
-                        if (_cki == null && consoleKeyInfo.KeyChar != (char)KeyCode.Esc && _isEscSeq)
+                        if (_cki is null && consoleKeyInfo.KeyChar != (char)KeyCode.Esc && _isEscSeq)
                         {
                             _cki = EscSeqUtils.ResizeArray (
                                                             new ConsoleKeyInfo (
@@ -292,7 +292,7 @@ internal class NetEvents : IDisposable
                         break;
                     }
 
-                    if (consoleKeyInfo.KeyChar == (char)KeyCode.Esc && _isEscSeq && _cki != null)
+                    if (consoleKeyInfo.KeyChar == (char)KeyCode.Esc && _isEscSeq && _cki is { })
                     {
                         ProcessRequestResponse (ref newConsoleKeyInfo, ref key, _cki, ref mod);
                         _cki = null;
@@ -1646,7 +1646,7 @@ internal class NetMainLoop : IMainLoopDriver
     /// <exception cref="ArgumentNullException"></exception>
     public NetMainLoop (ConsoleDriver consoleDriver = null)
     {
-        if (consoleDriver == null)
+        if (consoleDriver is null)
         {
             throw new ArgumentNullException (nameof (consoleDriver));
         }
@@ -1727,7 +1727,7 @@ internal class NetMainLoop : IMainLoopDriver
 
     private void NetInputHandler ()
     {
-        while (_mainLoop != null)
+        while (_mainLoop is { })
         {
             try
             {
@@ -1760,7 +1760,7 @@ internal class NetMainLoop : IMainLoopDriver
 
             try
             {
-                while (_resultQueue.Peek () == null)
+                while (_resultQueue.Peek () is null)
                 {
                     _resultQueue.Dequeue ();
                 }

+ 14 - 14
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -985,7 +985,7 @@ internal class WindowsDriver : ConsoleDriver
         // TODO: if some other Windows-based terminal supports true color, update this logic to not
         // force 16color mode (.e.g ConEmu which really doesn't work well at all).
         _isWindowsTerminal = _isWindowsTerminal =
-                                 Environment.GetEnvironmentVariable ("WT_SESSION") != null || Environment.GetEnvironmentVariable ("VSAPPIDNAME") != null;
+                                 Environment.GetEnvironmentVariable ("WT_SESSION") is { } || Environment.GetEnvironmentVariable ("VSAPPIDNAME") != null;
 
         if (!_isWindowsTerminal)
         {
@@ -998,7 +998,7 @@ internal class WindowsDriver : ConsoleDriver
     public WindowsConsole WinConsole { get; private set; }
 
     /// <inheritdoc/>
-    public override bool EnsureCursorVisibility () { return WinConsole == null || WinConsole.EnsureCursorVisibility (); }
+    public override bool EnsureCursorVisibility () { return WinConsole is null || WinConsole.EnsureCursorVisibility (); }
 
     public WindowsConsole.KeyEventRecord FromVKPacketToKeyEventRecord (WindowsConsole.KeyEventRecord keyEvent)
     {
@@ -1049,7 +1049,7 @@ internal class WindowsDriver : ConsoleDriver
     /// <inheritdoc/>
     public override bool GetCursorVisibility (out CursorVisibility visibility)
     {
-        if (WinConsole != null)
+        if (WinConsole is { })
         {
             return WinConsole.GetCursorVisibility (out visibility);
         }
@@ -1143,7 +1143,7 @@ internal class WindowsDriver : ConsoleDriver
     {
         _cachedCursorVisibility = visibility;
 
-        return WinConsole == null || WinConsole.SetCursorVisibility (visibility);
+        return WinConsole is null || WinConsole.SetCursorVisibility (visibility);
     }
 
     #region Not Implemented
@@ -1274,7 +1274,7 @@ internal class WindowsDriver : ConsoleDriver
 
     internal override void End ()
     {
-        if (_mainLoopDriver != null)
+        if (_mainLoopDriver is { })
         {
 #if HACK_CHECK_WINCHANGED
 
@@ -1302,7 +1302,7 @@ internal class WindowsDriver : ConsoleDriver
         {
             try
             {
-                if (WinConsole != null)
+                if (WinConsole is { })
                 {
                     // BUGBUG: The results from GetConsoleOutputWindow are incorrect when called from Init. 
                     // Our thread in WindowsMainLoop.CheckWin will get the correct results. See #if HACK_CHECK_WINCHANGED
@@ -1709,7 +1709,7 @@ internal class WindowsDriver : ConsoleDriver
 
             View view = Application.WantContinuousButtonPressedView;
 
-            if (view == null)
+            if (view is null)
             {
                 break;
             }
@@ -1783,7 +1783,7 @@ internal class WindowsDriver : ConsoleDriver
         // be fired with it's bit set to 0. So when the button is up ButtonState will be 0.
         // To map to the correct driver events we save the last pressed mouse button so we can
         // map to the correct clicked event.
-        if ((_lastMouseButtonPressed != null || _isButtonReleased) && mouseEvent.ButtonState != 0)
+        if ((_lastMouseButtonPressed is { } || _isButtonReleased) && mouseEvent.ButtonState != 0)
         {
             _lastMouseButtonPressed = null;
 
@@ -1797,7 +1797,7 @@ internal class WindowsDriver : ConsoleDriver
             Y = mouseEvent.MousePosition.Y
         };
 
-        if ((mouseEvent.ButtonState != 0 && mouseEvent.EventFlags == 0 && _lastMouseButtonPressed == null && !_isButtonDoubleClicked)
+        if ((mouseEvent.ButtonState != 0 && mouseEvent.EventFlags == 0 && _lastMouseButtonPressed is null && !_isButtonDoubleClicked)
             || (_lastMouseButtonPressed == null
                 && mouseEvent.EventFlags.HasFlag (WindowsConsole.EventFlags.MouseMoved)
                 && mouseEvent.ButtonState != 0
@@ -1876,7 +1876,7 @@ internal class WindowsDriver : ConsoleDriver
             _isButtonPressed = false;
             _isButtonReleased = true;
 
-            if (_point != null && ((Point)_point).X == mouseEvent.MousePosition.X && ((Point)_point).Y == mouseEvent.MousePosition.Y)
+            if (_point is { } && ((Point)_point).X == mouseEvent.MousePosition.X && ((Point)_point).Y == mouseEvent.MousePosition.Y)
             {
                 _processButtonClick = true;
             }
@@ -1998,7 +1998,7 @@ internal class WindowsDriver : ConsoleDriver
         mouseFlag = SetControlKeyStates (mouseEvent, mouseFlag);
 
         //System.Diagnostics.Debug.WriteLine (
-        //	$"point.X:{(point != null ? ((Point)point).X : -1)};point.Y:{(point != null ? ((Point)point).Y : -1)}");
+        //	$"point.X:{(point is { } ? ((Point)point).X : -1)};point.Y:{(point is { } ? ((Point)point).Y : -1)}");
 
         return new MouseEvent
         {
@@ -2137,7 +2137,7 @@ internal class WindowsMainLoop : IMainLoopDriver
 
     private void WindowsInputHandler ()
     {
-        while (_mainLoop != null)
+        while (_mainLoop is { })
         {
             try
             {
@@ -2170,14 +2170,14 @@ internal class WindowsMainLoop : IMainLoopDriver
     private Size _windowSize;
     private void CheckWinChange ()
     {
-        while (_mainLoop != null)
+        while (_mainLoop is { })
         {
             _winChange.Wait ();
             _winChange.Reset ();
 
             // Check if the window size changed every half second. 
             // We do this to minimize the weird tearing seen on Windows when resizing the console
-            while (_mainLoop != null)
+            while (_mainLoop is { })
             {
                 Task.Delay (500).Wait ();
                 _windowSize = _winConsole.GetConsoleBufferWindow (out _);

+ 17 - 56
Terminal.Gui/Drawing/Attribute.cs

@@ -1,4 +1,5 @@
 #nullable enable
+using System.Numerics;
 using System.Text.Json.Serialization;
 
 namespace Terminal.Gui;
@@ -10,14 +11,15 @@ namespace Terminal.Gui;
 ///     <see cref="ColorScheme"/> class to define color schemes that can be used in an application.
 /// </remarks>
 [JsonConverter (typeof (AttributeJsonConverter))]
-public readonly struct Attribute : IEquatable<Attribute>
+public readonly record struct Attribute : IEqualityOperators<Attribute, Attribute, bool>
 {
     /// <summary>Default empty attribute.</summary>
-    public static readonly Attribute Default = new (Color.White, ColorName.Black);
+    [JsonIgnore]
+    public static Attribute Default => new (Color.White, ColorName.Black);
 
     /// <summary>The <see cref="ConsoleDriver"/>-specific color value.</summary>
     [JsonIgnore (Condition = JsonIgnoreCondition.Always)]
-    internal int PlatformColor { get; }
+    internal int PlatformColor { get; init; }
 
     /// <summary>The foreground color.</summary>
     [JsonConverter (typeof (ColorJsonConverter))]
@@ -30,33 +32,20 @@ public readonly struct Attribute : IEquatable<Attribute>
     /// <summary>Initializes a new instance with default values.</summary>
     public Attribute ()
     {
-        PlatformColor = -1;
-        Foreground = Default.Foreground;
-        Background = Default.Background;
+        this = Default with { PlatformColor = -1 };
     }
 
     /// <summary>Initializes a new instance from an existing instance.</summary>
     public Attribute (in Attribute attr)
     {
-        PlatformColor = -1;
-        Foreground = attr.Foreground;
-        Background = attr.Background;
-    }
-
-    /// <summary>Initializes a new instance with platform specific color value.</summary>
-    /// <param name="platformColor">Value.</param>
-    internal Attribute (int platformColor)
-    {
-        PlatformColor = platformColor;
-        Foreground = Default.Foreground;
-        Background = Default.Background;
+        this = attr with { PlatformColor = -1 };
     }
 
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>
     /// <param name="platformColor">platform-dependent color value.</param>
     /// <param name="foreground">Foreground</param>
     /// <param name="background">Background</param>
-    internal Attribute (int platformColor, in Color foreground, in Color background)
+    internal Attribute (int platformColor, Color foreground, Color background)
     {
         Foreground = foreground;
         Background = background;
@@ -66,21 +55,13 @@ public readonly struct Attribute : IEquatable<Attribute>
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>
     /// <param name="foreground">Foreground</param>
     /// <param name="background">Background</param>
-    public Attribute (Color foreground, Color background)
+    public Attribute (in Color foreground, in Color background)
     {
         Foreground = foreground;
         Background = background;
 
-        // TODO: Once CursesDriver supports truecolor all the PlatformColor stuff goes away
-        if (Application.Driver == null)
-        {
-            PlatformColor = -1;
-
-            return;
-        }
-
-        Attribute make = Application.Driver.MakeColor (foreground, background);
-        PlatformColor = make.PlatformColor;
+        // TODO: Once CursesDriver supports true color all the PlatformColor stuff goes away
+        PlatformColor = Application.Driver?.MakeColor(in foreground, in background).PlatformColor ?? -1;
     }
 
     /// <summary>
@@ -88,51 +69,31 @@ public readonly struct Attribute : IEquatable<Attribute>
     ///     <see cref="Background"/> will be set to the specified color.
     /// </summary>
     /// <param name="colorName">Value.</param>
-    internal Attribute (ColorName colorName) : this (colorName, colorName) { }
+    internal Attribute (in ColorName colorName) : this (in colorName, in colorName) { }
 
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>
     /// <param name="foregroundName">Foreground</param>
     /// <param name="backgroundName">Background</param>
-    public Attribute (in ColorName foregroundName, in ColorName backgroundName) : this (
-                                                                                        new Color (foregroundName),
-                                                                                        new Color (backgroundName)
-                                                                                       )
+    public Attribute (in ColorName foregroundName, in ColorName backgroundName)
+        : this (new Color (in foregroundName), new Color (in backgroundName))
     { }
 
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>
     /// <param name="foregroundName">Foreground</param>
     /// <param name="background">Background</param>
-    public Attribute (ColorName foregroundName, Color background) : this (new Color (foregroundName), background) { }
+    public Attribute (in ColorName foregroundName, in Color background) : this (new Color (in foregroundName), in background) { }
 
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>
     /// <param name="foreground">Foreground</param>
     /// <param name="backgroundName">Background</param>
-    public Attribute (Color foreground, ColorName backgroundName) : this (foreground, new Color (backgroundName)) { }
+    public Attribute (in Color foreground, in ColorName backgroundName) : this (in foreground, new Color (in backgroundName)) { }
 
     /// <summary>
     ///     Initializes a new instance of the <see cref="Attribute"/> struct with the same colors for the foreground and
     ///     background.
     /// </summary>
     /// <param name="color">The color.</param>
-    public Attribute (Color color) : this (color, color) { }
-
-    /// <summary>Compares two attributes for equality.</summary>
-    /// <param name="left"></param>
-    /// <param name="right"></param>
-    /// <returns></returns>
-    public static bool operator == (Attribute left, Attribute right) { return left.Equals (right); }
-
-    /// <summary>Compares two attributes for inequality.</summary>
-    /// <param name="left"></param>
-    /// <param name="right"></param>
-    /// <returns></returns>
-    public static bool operator != (Attribute left, Attribute right) { return !(left == right); }
-
-    /// <inheritdoc/>
-    public override bool Equals (object? obj) { return obj is Attribute other && Equals (other); }
-
-    /// <inheritdoc/>
-    public bool Equals (Attribute other) { return PlatformColor == other.PlatformColor && Foreground == other.Foreground && Background == other.Background; }
+    public Attribute (in Color color) : this (color, color) { }
 
     /// <inheritdoc/>
     public override int GetHashCode () { return HashCode.Combine (PlatformColor, Foreground, Background); }

+ 0 - 0
Terminal.Gui/Drawing/ColorExtensions.cs → Terminal.Gui/Drawing/Color.ColorExtensions.cs


+ 0 - 0
Terminal.Gui/Drawing/ColorName.cs → Terminal.Gui/Drawing/Color.ColorName.cs


+ 0 - 0
Terminal.Gui/Drawing/ColorParseException.cs → Terminal.Gui/Drawing/Color.ColorParseException.cs


+ 176 - 0
Terminal.Gui/Drawing/ColorScheme.Colors.cs

@@ -0,0 +1,176 @@
+#nullable enable
+using System.Collections;
+using System.Collections.Specialized;
+using System.Text.Json.Serialization;
+
+namespace Terminal.Gui;
+
+/// <summary>
+///     Holds the <see cref="ColorScheme"/>s that define the <see cref="Attribute"/>s that are used by views to render
+///     themselves.
+/// </summary>
+public sealed class Colors : INotifyCollectionChanged, IDictionary<string, ColorScheme?>
+{
+    static Colors ()
+    {
+        ColorSchemes = new (5, StringComparer.InvariantCultureIgnoreCase);
+        Reset ();
+    }
+
+    /// <summary>Gets a dictionary of defined <see cref="ColorScheme"/> objects.</summary>
+    /// <remarks>
+    ///     <para>
+    ///         The <see cref="ColorSchemes"/> dictionary includes the following keys, by default:
+    ///         <list type="table">
+    ///             <listheader>
+    ///                 <term>Built-in Color Scheme</term> <description>Description</description>
+    ///             </listheader>
+    ///             <item>
+    ///                 <term>Base</term> <description>The base color scheme used for most Views.</description>
+    ///             </item>
+    ///             <item>
+    ///                 <term>TopLevel</term>
+    ///                 <description>The application Toplevel color scheme; used for the <see cref="Toplevel"/> View.</description>
+    ///             </item>
+    ///             <item>
+    ///                 <term>Dialog</term>
+    ///                 <description>
+    ///                     The dialog color scheme; used for <see cref="Dialog"/>, <see cref="MessageBox"/>, and
+    ///                     other views dialog-like views.
+    ///                 </description>
+    ///             </item>
+    ///             <item>
+    ///                 <term>Menu</term>
+    ///                 <description>
+    ///                     The menu color scheme; used for <see cref="MenuBar"/>, <see cref="ContextMenu"/>, and
+    ///                     <see cref="StatusBar"/>.
+    ///                 </description>
+    ///             </item>
+    ///             <item>
+    ///                 <term>Error</term>
+    ///                 <description>
+    ///                     The color scheme for showing errors, such as in
+    ///                     <see cref="MessageBox.ErrorQuery(string, string, string[])"/>.
+    ///                 </description>
+    ///             </item>
+    ///         </list>
+    ///     </para>
+    ///     <para>Changing the values of an entry in this dictionary will affect all views that use the scheme.</para>
+    ///     <para>
+    ///         <see cref="ConfigurationManager"/> can be used to override the default values for these schemes and add
+    ///         additional schemes. See <see cref="ConfigurationManager.Themes"/>.
+    ///     </para>
+    /// </remarks>
+    [SerializableConfigurationProperty (Scope = typeof (ThemeScope), OmitClassName = true)]
+    [JsonConverter (typeof (DictionaryJsonConverter<ColorScheme?>))]
+    [UsedImplicitly]
+    public static Dictionary<string, ColorScheme?> ColorSchemes { get; private set; }
+
+    /// <inheritdoc/>
+    public IEnumerator<KeyValuePair<string, ColorScheme?>> GetEnumerator () { return ColorSchemes.GetEnumerator (); }
+
+    /// <inheritdoc/>
+    IEnumerator IEnumerable.GetEnumerator () { return GetEnumerator (); }
+
+    /// <inheritdoc/>
+    public void Add (KeyValuePair<string, ColorScheme?> item)
+    {
+        ColorSchemes.Add (item.Key, item.Value);
+        CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Add, item));
+    }
+
+    /// <inheritdoc/>
+    public void Clear ()
+    {
+        ColorSchemes.Clear ();
+        CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Reset));
+    }
+
+    /// <inheritdoc/>
+    public bool Contains (KeyValuePair<string, ColorScheme?> item) { return ColorSchemes.Contains (item); }
+
+    /// <inheritdoc/>
+    public void CopyTo (KeyValuePair<string, ColorScheme?> [] array, int arrayIndex) { ((ICollection)ColorSchemes).CopyTo (array, arrayIndex); }
+
+    /// <inheritdoc/>
+    public bool Remove (KeyValuePair<string, ColorScheme?> item)
+    {
+        if (ColorSchemes.Remove (item.Key))
+        {
+            CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Remove, item));
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /// <inheritdoc/>
+    public int Count => ColorSchemes.Count;
+
+    /// <inheritdoc/>
+    public bool IsReadOnly => false;
+
+    /// <inheritdoc/>
+    public void Add (string key, ColorScheme? value) { Add (new (key, value)); }
+
+    /// <inheritdoc/>
+    public bool ContainsKey (string key) { return ColorSchemes.ContainsKey (key); }
+
+    /// <inheritdoc/>
+    public bool Remove (string key)
+    {
+        if (ColorSchemes.Remove (key))
+        {
+            CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Remove, key));
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /// <inheritdoc/>
+    public bool TryGetValue (string key, out ColorScheme? value) { return ColorSchemes.TryGetValue (key, out value); }
+
+    /// <inheritdoc/>
+    public ColorScheme? this [string key]
+    {
+        get => ColorSchemes [key];
+        set
+        {
+            if (ColorSchemes.TryAdd (key, value))
+            {
+                CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Add, new KeyValuePair<string, ColorScheme?> (key, value)));
+            }
+            else
+            {
+                ColorScheme? oldValue = ColorSchemes [key];
+                ColorSchemes [key] = value;
+                CollectionChanged?.Invoke (this, new (NotifyCollectionChangedAction.Replace, value, oldValue));
+            }
+        }
+    }
+
+    /// <inheritdoc/>
+    public ICollection<string> Keys => ColorSchemes.Keys;
+
+    /// <inheritdoc/>
+    public ICollection<ColorScheme?> Values => ColorSchemes.Values;
+
+    /// <inheritdoc/>
+    public event NotifyCollectionChangedEventHandler? CollectionChanged;
+
+    /// <summary>Resets the <see cref="ColorSchemes"/> dictionary to the default values.</summary>
+    public static Dictionary<string, ColorScheme?> Reset ()
+    {
+        ColorSchemes.Clear ();
+        ColorSchemes.Add ("TopLevel", new ());
+        ColorSchemes.Add ("Base", new ());
+        ColorSchemes.Add ("Dialog", new ());
+        ColorSchemes.Add ("Menu", new ());
+        ColorSchemes.Add ("Error", new ());
+
+        return ColorSchemes;
+    }
+}

+ 8 - 128
Terminal.Gui/Drawing/ColorScheme.cs

@@ -1,5 +1,5 @@
-#nullable enable
-using System.Globalization;
+#nullable enable
+using System.Numerics;
 using System.Text.Json.Serialization;
 
 namespace Terminal.Gui;
@@ -13,7 +13,7 @@ namespace Terminal.Gui;
 ///     </para>
 /// </remarks>
 [JsonConverter (typeof (ColorSchemeJsonConverter))]
-public class ColorScheme : IEquatable<ColorScheme>
+public record ColorScheme : IEqualityOperators<ColorScheme, ColorScheme, bool>
 {
     private readonly Attribute _disabled;
     private readonly Attribute _focus;
@@ -26,12 +26,9 @@ public class ColorScheme : IEquatable<ColorScheme>
 
     /// <summary>Creates a new instance, initialized with the values from <paramref name="scheme"/>.</summary>
     /// <param name="scheme">The scheme to initialize the new instance with.</param>
-    public ColorScheme (ColorScheme scheme)
+    public ColorScheme (ColorScheme? scheme)
     {
-        if (scheme is null)
-        {
-            throw new ArgumentNullException (nameof (scheme));
-        }
+        ArgumentNullException.ThrowIfNull (scheme);
 
         _normal = scheme.Normal;
         _focus = scheme.Focus;
@@ -89,7 +86,7 @@ public class ColorScheme : IEquatable<ColorScheme>
     /// <summary>Compares two <see cref="ColorScheme"/> objects for equality.</summary>
     /// <param name="other"></param>
     /// <returns>true if the two objects are equal</returns>
-    public bool Equals (ColorScheme? other)
+    public virtual bool Equals (ColorScheme? other)
     {
         return other is { }
                && EqualityComparer<Attribute>.Default.Equals (_normal, other._normal)
@@ -99,130 +96,13 @@ public class ColorScheme : IEquatable<ColorScheme>
                && EqualityComparer<Attribute>.Default.Equals (_disabled, other._disabled);
     }
 
-    /// <summary>Compares two <see cref="ColorScheme"/> objects for equality.</summary>
-    /// <param name="obj"></param>
-    /// <returns>true if the two objects are equal</returns>
-    public override bool Equals (object? obj) { return Equals (obj as ColorScheme); }
-
     /// <summary>Returns a hashcode for this instance.</summary>
     /// <returns>hashcode for this instance</returns>
     public override int GetHashCode ()
     {
-        int hashCode = -1242460230;
-        hashCode = hashCode * -1521134295 + _normal.GetHashCode ();
-        hashCode = hashCode * -1521134295 + _focus.GetHashCode ();
-        hashCode = hashCode * -1521134295 + _hotNormal.GetHashCode ();
-        hashCode = hashCode * -1521134295 + _hotFocus.GetHashCode ();
-        hashCode = hashCode * -1521134295 + _disabled.GetHashCode ();
-
-        return hashCode;
+        return HashCode.Combine (_normal, _focus, _hotNormal, _hotFocus, _disabled);
     }
 
-    /// <summary>Compares two <see cref="ColorScheme"/> objects for equality.</summary>
-    /// <param name="left"></param>
-    /// <param name="right"></param>
-    /// <returns><c>true</c> if the two objects are equivalent</returns>
-    public static bool operator == (ColorScheme left, ColorScheme right) { return EqualityComparer<ColorScheme>.Default.Equals (left, right); }
-
-    /// <summary>Compares two <see cref="ColorScheme"/> objects for inequality.</summary>
-    /// <param name="left"></param>
-    /// <param name="right"></param>
-    /// <returns><c>true</c> if the two objects are not equivalent</returns>
-    public static bool operator != (ColorScheme left, ColorScheme right) { return !(left == right); }
-
     /// <inheritdoc/>
     public override string ToString () { return $"Normal: {Normal}; Focus: {Focus}; HotNormal: {HotNormal}; HotFocus: {HotFocus}; Disabled: {Disabled}"; }
-}
-
-/// <summary>
-///     Holds the <see cref="ColorScheme"/>s that define the <see cref="Attribute"/>s that are used by views to render
-///     themselves.
-/// </summary>
-public static class Colors
-{
-    static Colors () { Reset (); }
-
-    /// <summary>Gets a dictionary of defined <see cref="ColorScheme"/> objects.</summary>
-    /// <remarks>
-    ///     <para>
-    ///         The <see cref="ColorSchemes"/> dictionary includes the following keys, by default:
-    ///         <list type="table">
-    ///             <listheader>
-    ///                 <term>Built-in Color Scheme</term> <description>Description</description>
-    ///             </listheader>
-    ///             <item>
-    ///                 <term>Base</term> <description>The base color scheme used for most Views.</description>
-    ///             </item>
-    ///             <item>
-    ///                 <term>TopLevel</term>
-    ///                 <description>The application Toplevel color scheme; used for the <see cref="Toplevel"/> View.</description>
-    ///             </item>
-    ///             <item>
-    ///                 <term>Dialog</term>
-    ///                 <description>
-    ///                     The dialog color scheme; used for <see cref="Dialog"/>, <see cref="MessageBox"/>, and
-    ///                     other views dialog-like views.
-    ///                 </description>
-    ///             </item>
-    ///             <item>
-    ///                 <term>Menu</term>
-    ///                 <description>
-    ///                     The menu color scheme; used for <see cref="MenuBar"/>, <see cref="ContextMenu"/>, and
-    ///                     <see cref="StatusBar"/>.
-    ///                 </description>
-    ///             </item>
-    ///             <item>
-    ///                 <term>Error</term>
-    ///                 <description>
-    ///                     The color scheme for showing errors, such as in
-    ///                     <see cref="MessageBox.ErrorQuery(string, string, string[])"/>.
-    ///                 </description>
-    ///             </item>
-    ///         </list>
-    ///     </para>
-    ///     <para>Changing the values of an entry in this dictionary will affect all views that use the scheme.</para>
-    ///     <para>
-    ///         <see cref="ConfigurationManager"/> can be used to override the default values for these schemes and add
-    ///         additional schemes. See <see cref="ConfigurationManager.Themes"/>.
-    ///     </para>
-    /// </remarks>
-    [SerializableConfigurationProperty (Scope = typeof (ThemeScope), OmitClassName = true)]
-    [JsonConverter (typeof (DictionaryJsonConverter<ColorScheme>))]
-    public static Dictionary<string, ColorScheme>
-        ColorSchemes { get; private set; } // Serialization requires this to have a setter (private set;)
-
-    /// <summary>Resets the <see cref="ColorSchemes"/> dictionary to the default values.</summary>
-    public static Dictionary<string, ColorScheme> Reset ()
-    {
-        ColorSchemes ??= new Dictionary<string, ColorScheme> (
-                                                              5,
-                                                              CultureInfo.InvariantCulture.CompareInfo
-                                                                         .GetStringComparer (
-                                                                                             CompareOptions.IgnoreCase
-                                                                                            )
-                                                             );
-        ColorSchemes.Clear ();
-        ColorSchemes.Add ("TopLevel", new ColorScheme ());
-        ColorSchemes.Add ("Base", new ColorScheme ());
-        ColorSchemes.Add ("Dialog", new ColorScheme ());
-        ColorSchemes.Add ("Menu", new ColorScheme ());
-        ColorSchemes.Add ("Error", new ColorScheme ());
-
-        return ColorSchemes;
-    }
-
-    private class SchemeNameComparerIgnoreCase : IEqualityComparer<string>
-    {
-        public bool Equals (string x, string y)
-        {
-            if (x != null && y != null)
-            {
-                return string.Equals (x, y, StringComparison.InvariantCultureIgnoreCase);
-            }
-
-            return false;
-        }
-
-        public int GetHashCode (string obj) { return obj.ToLowerInvariant ().GetHashCode (); }
-    }
-}
+}

+ 5 - 5
Terminal.Gui/Drawing/LineCanvas.cs

@@ -225,12 +225,12 @@ public class LineCanvas : IDisposable
             {
                 IntersectionDefinition? [] intersects = _lines
                                                         .Select (l => l.Intersects (x, y))
-                                                        .Where (i => i != null)
+                                                        .Where (i => i is { })
                                                         .ToArray ();
 
                 Cell? cell = GetCellForIntersects (Application.Driver, intersects);
 
-                if (cell != null)
+                if (cell is { })
                 {
                     map.Add (new Point (x, y), cell);
                 }
@@ -260,12 +260,12 @@ public class LineCanvas : IDisposable
             {
                 IntersectionDefinition? [] intersects = _lines
                                                         .Select (l => l.Intersects (x, y))
-                                                        .Where (i => i != null)
+                                                        .Where (i => i is { })
                                                         .ToArray ();
 
                 Rune? rune = GetRuneForIntersects (Application.Driver, intersects);
 
-                if (rune != null)
+                if (rune is { })
                 {
                     map.Add (new Point (x, y), rune.Value);
                 }
@@ -299,7 +299,7 @@ public class LineCanvas : IDisposable
     {
         StraightLine? l = _lines.LastOrDefault ();
 
-        if (l != null)
+        if (l is { })
         {
             _lines.Remove (l);
         }

+ 2 - 2
Terminal.Gui/Drawing/Thickness.cs

@@ -217,7 +217,7 @@ public class Thickness : IEquatable<Thickness>
             // Draw the diagnostics label on the bottom
             var tf = new TextFormatter
             {
-                Text = label == null ? string.Empty : $"{label} {this}",
+                Text = label is null ? string.Empty : $"{label} {this}",
                 Alignment = TextAlignment.Centered,
                 VerticalAlignment = VerticalTextAlignment.Bottom
             };
@@ -233,7 +233,7 @@ public class Thickness : IEquatable<Thickness>
     public override bool Equals (object obj)
     {
         //Check for null and compare run-time types.
-        if (obj == null || !GetType ().Equals (obj.GetType ()))
+        if (obj is null || !GetType ().Equals (obj.GetType ()))
         {
             return false;
         }

+ 1 - 1
Terminal.Gui/FileServices/DefaultFileOperations.cs

@@ -53,7 +53,7 @@ public class DefaultFileOperations : IFileOperations
     public IFileSystemInfo Rename (IFileSystem fileSystem, IFileSystemInfo toRename)
     {
         // Don't allow renaming C: or D: or / (on linux) etc
-        if (toRename is IDirectoryInfo dir && dir.Parent == null)
+        if (toRename is IDirectoryInfo dir && dir.Parent is null)
         {
             return null;
         }

+ 4 - 4
Terminal.Gui/FileServices/FileDialogHistory.cs

@@ -28,7 +28,7 @@ internal class FileDialogHistory
         }
 
         // nowhere to go
-        if (goTo == null)
+        if (goTo is null)
         {
             return false;
         }
@@ -36,7 +36,7 @@ internal class FileDialogHistory
         forward.Push (dlg.State);
         dlg.PushState (goTo, false, true, false, restorePath);
 
-        if (restoreSelection != null)
+        if (restoreSelection is { })
         {
             dlg.RestoreSelection (restoreSelection.FileSystemInfo);
         }
@@ -63,7 +63,7 @@ internal class FileDialogHistory
 
     internal void Push (FileDialogState state, bool clearForward)
     {
-        if (state == null)
+        if (state is null)
         {
             return;
         }
@@ -84,7 +84,7 @@ internal class FileDialogHistory
     {
         IDirectoryInfo parent = dlg.State?.Directory.Parent;
 
-        if (parent != null)
+        if (parent is { })
         {
             back.Push (new FileDialogState (parent, dlg));
             dlg.PushState (parent, false);

+ 2 - 2
Terminal.Gui/FileServices/FileDialogState.cs

@@ -55,13 +55,13 @@ internal class FileDialogState
             }
 
             // if theres a UI filter in place too
-            if (Parent.CurrentFilter != null)
+            if (Parent.CurrentFilter is { })
             {
                 children = children.Where (MatchesApiFilter).ToList ();
             }
 
             // allow navigating up as '..'
-            if (dir.Parent != null)
+            if (dir.Parent is { })
             {
                 children.Add (new FileSystemInfoStats (dir.Parent, Parent.Style.Culture) { IsParent = true });
             }

+ 1 - 1
Terminal.Gui/Input/KeyBinding.cs

@@ -97,7 +97,7 @@ public class KeyBindings
             throw new ArgumentException (@"At least one command must be specified", nameof (commands));
         }
 
-        if (key == null || !key.IsValid)
+        if (key is null || !key.IsValid)
         {
             //throw new ArgumentException ("Invalid Key", nameof (commands));
             return;

+ 1 - 1
Terminal.Gui/Input/Responder.cs

@@ -132,7 +132,7 @@ public class Responder : IDisposable
                                            | BindingFlags.DeclaredOnly
                                           );
 
-        if (m == null)
+        if (m is null)
         {
             return false;
         }

+ 1 - 1
Terminal.Gui/MainLoop.cs

@@ -125,7 +125,7 @@ internal class MainLoop : IDisposable
     /// </remarks>
     internal object AddTimeout (TimeSpan time, Func<bool> callback)
     {
-        if (callback == null)
+        if (callback is null)
         {
             throw new ArgumentNullException (nameof (callback));
         }

+ 1 - 1
Terminal.Gui/RunState.cs

@@ -30,7 +30,7 @@ public class RunState : IDisposable
     /// <param name="disposing">If set to <see langword="true"/> we are disposing and should dispose held objects.</param>
     protected virtual void Dispose (bool disposing)
     {
-        if (Toplevel != null && disposing)
+        if (Toplevel is { } && disposing)
         {
             throw new InvalidOperationException (
                                                  "You must clean up (Dispose) the Toplevel before calling Application.RunState.Dispose"

+ 3 - 0
Terminal.Gui/Terminal.Gui.csproj

@@ -38,6 +38,7 @@
   <!-- Dependencies -->
   <!-- =================================================================== -->
   <ItemGroup>
+    <PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
     <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
     <PackageReference Include="System.IO.Abstractions" Version="20.0.4" />
     <PackageReference Include="System.Text.Json" Version="8.0.1" />
@@ -83,6 +84,8 @@
   </ItemGroup>
   <ItemGroup>
     <Using Include="System.Text" />
+    <Using Include="JetBrains.Annotations" />
+    <Using Include="System.Diagnostics.Contracts.PureAttribute" Alias="PureAttribute" />
   </ItemGroup>
   <!-- =================================================================== -->
   <!-- Nuget  -->

+ 8 - 8
Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs

@@ -23,7 +23,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
     {
         get
         {
-            if (colorScheme == null)
+            if (colorScheme is null)
             {
                 colorScheme = Colors.ColorSchemes ["Menu"];
             }
@@ -42,7 +42,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
             hostControl = value;
             top = hostControl.SuperView;
 
-            if (top != null)
+            if (top is { })
             {
                 top.DrawContent += Top_DrawContent;
                 top.DrawContentComplete += Top_DrawContentComplete;
@@ -114,7 +114,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
             }
 
             // not in the popup
-            if (Visible && HostControl != null)
+            if (Visible && HostControl is { })
             {
                 Visible = false;
                 closed = false;
@@ -125,7 +125,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
             return false;
         }
 
-        if (popup == null || Suggestions.Count == 0)
+        if (popup is null || Suggestions.Count == 0)
         {
             ManipulatePopup ();
 
@@ -467,7 +467,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
         {
             SelectedIdx = me.Y - ScrollOffset;
 
-            if (LastPopupPos != null)
+            if (LastPopupPos is { })
             {
                 RenderOverlay ((Point)LastPopupPos);
             }
@@ -516,13 +516,13 @@ public abstract class PopupAutocomplete : AutocompleteBase
 
     private void ManipulatePopup ()
     {
-        if (Visible && popup == null)
+        if (Visible && popup is null)
         {
             popup = new Popup (this) { Frame = Rect.Empty };
             top?.Add (popup);
         }
 
-        if (!Visible && popup != null)
+        if (!Visible && popup is { })
         {
             top?.Remove (popup);
             popup.Dispose ();
@@ -568,7 +568,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
 
         public override void OnDrawContent (Rect contentArea)
         {
-            if (autocomplete.LastPopupPos == null)
+            if (autocomplete.LastPopupPos is null)
             {
                 return;
             }

+ 1 - 1
Terminal.Gui/Text/StringExtensions.cs

@@ -55,7 +55,7 @@ public static class StringExtensions
     /// <remarks>This is a Terminal.Gui extension method to <see cref="string"/> to support TUI text manipulation.</remarks>
     /// <param name="str">The string to measure.</param>
     /// <returns></returns>
-    public static int GetColumns (this string str) { return str == null ? 0 : str.EnumerateRunes ().Sum (r => Math.Max (r.GetColumns (), 0)); }
+    public static int GetColumns (this string str) { return str is null ? 0 : str.EnumerateRunes ().Sum (r => Math.Max (r.GetColumns (), 0)); }
 
     /// <summary>Gets the number of runes in the string.</summary>
     /// <remarks>This is a Terminal.Gui extension method to <see cref="string"/> to support TUI text manipulation.</remarks>

+ 8 - 8
Terminal.Gui/Text/TextFormatter.cs

@@ -270,7 +270,7 @@ public class TextFormatter
         get => _text;
         set
         {
-            bool textWasNull = _text == null && value != null;
+            bool textWasNull = _text is null && value != null;
             _text = EnableNeedsFormat (value);
 
             if ((AutoSize && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) || (textWasNull && Size.IsEmpty))
@@ -340,7 +340,7 @@ public class TextFormatter
         bool isVertical = IsVerticalDirection (Direction);
         Rect maxBounds = bounds;
 
-        if (driver != null)
+        if (driver is { })
         {
             maxBounds = containerBounds == default (Rect)
                             ? bounds
@@ -505,7 +505,7 @@ public class TextFormatter
             {
                 Rune lastRuneUsed = rune;
 
-                if (lastZeroWidthPos == null)
+                if (lastZeroWidthPos is null)
                 {
                     if (idx < 0 || x + current + colOffset < 0)
                     {
@@ -540,7 +540,7 @@ public class TextFormatter
                         rune = runes [idx];
                     }
 
-                    if (lastZeroWidthPos == null)
+                    if (lastZeroWidthPos is null)
                     {
                         driver?.Move (x, current);
                     }
@@ -548,7 +548,7 @@ public class TextFormatter
                     {
                         int foundIdx = lastZeroWidthPos.IndexOf (
                                                                  p =>
-                                                                     p != null && p.Value.Y == current
+                                                                     p is { } && p.Value.Y == current
                                                                 );
 
                         if (foundIdx > -1)
@@ -611,14 +611,14 @@ public class TextFormatter
                     {
                         if (runeWidth == 0)
                         {
-                            if (lastZeroWidthPos == null)
+                            if (lastZeroWidthPos is null)
                             {
                                 lastZeroWidthPos = new List<Point?> ();
                             }
 
                             int foundIdx = lastZeroWidthPos.IndexOf (
                                                                      p =>
-                                                                         p != null && p.Value.Y == current
+                                                                         p is { } && p.Value.Y == current
                                                                     );
 
                             if (foundIdx == -1)
@@ -1764,7 +1764,7 @@ public class TextFormatter
     /// <returns>The index of the last Rune in <paramref name="runes"/> that fit in <paramref name="columns"/>.</returns>
     public static int GetLengthThatFits (List<Rune> runes, int columns, int tabWidth = 0)
     {
-        if (runes == null || runes.Count == 0)
+        if (runes is null || runes.Count == 0)
         {
             return 0;
         }

+ 1 - 1
Terminal.Gui/View/Adornment/Adornment.cs

@@ -134,7 +134,7 @@ public class Adornment : View
 
         if (!string.IsNullOrEmpty (TextFormatter.Text))
         {
-            if (TextFormatter != null)
+            if (TextFormatter is { })
             {
                 TextFormatter.Size = Frame.Size;
                 TextFormatter.NeedsFormat = true;

+ 3 - 3
Terminal.Gui/View/Adornment/Border.cs

@@ -63,7 +63,7 @@ public class Border : Adornment
     {
         get
         {
-            if (base.ColorScheme != null)
+            if (base.ColorScheme is { })
             {
                 return base.ColorScheme;
             }
@@ -317,7 +317,7 @@ public class Border : Adornment
 
             Attribute prevAttr = Driver.GetAttribute ();
 
-            if (ColorScheme != null)
+            if (ColorScheme is { })
             {
                 Driver.SetAttribute (GetNormalColor ());
             }
@@ -482,7 +482,7 @@ public class Border : Adornment
                 {
                     prevAttr = Driver.GetAttribute ();
 
-                    if (ColorScheme != null)
+                    if (ColorScheme is { })
                     {
                         Driver.SetAttribute (HasFocus ? GetHotNormalColor () : GetNormalColor ());
                     }

+ 1 - 1
Terminal.Gui/View/Adornment/Margin.cs

@@ -25,7 +25,7 @@ public class Margin : Adornment
     {
         get
         {
-            if (base.ColorScheme != null)
+            if (base.ColorScheme is { })
             {
                 return base.ColorScheme;
             }

+ 1 - 1
Terminal.Gui/View/Adornment/Padding.cs

@@ -25,7 +25,7 @@ public class Padding : Adornment
     {
         get
         {
-            if (base.ColorScheme != null)
+            if (base.ColorScheme is { })
             {
                 return base.ColorScheme;
             }

+ 3 - 3
Terminal.Gui/View/Layout/PosDim.cs

@@ -298,7 +298,7 @@ public class Pos
     {
         var view = left as PosView;
 
-        if (view != null)
+        if (view is { })
         {
             view.Target.SetNeedsLayout ();
         }
@@ -422,7 +422,7 @@ public class Pos
                     break;
             }
 
-            if (Target == null)
+            if (Target is null)
             {
                 throw new NullReferenceException (nameof (Target));
             }
@@ -726,7 +726,7 @@ public class Dim
 
         public override string ToString ()
         {
-            if (Target == null)
+            if (Target is null)
             {
                 throw new NullReferenceException ();
             }

+ 19 - 19
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -177,7 +177,7 @@ public partial class View
 #endif // DEBUG
 
             // BUGBUG: I think there's a bug here. This should be && not ||
-            if (Margin == null || Border == null || Padding == null)
+            if (Margin is null || Border is null || Padding is null)
             {
                 return new Rect (default (Point), Frame.Size);
             }
@@ -526,7 +526,7 @@ public partial class View
 
         View super = SuperView;
 
-        while (super != null)
+        while (super is { })
         {
             boundsOffset = super.GetBoundsOffset ();
             rx += super.Frame.X + boundsOffset.X;
@@ -556,14 +556,14 @@ public partial class View
     {
         resy = resx = 0;
 
-        if (start == null || !start.Frame.Contains (x, y))
+        if (start is null || !start.Frame.Contains (x, y))
         {
             return null;
         }
 
         Rect startFrame = start.Frame;
 
-        if (start.InternalSubviews != null)
+        if (start.InternalSubviews is { })
         {
             int count = start.InternalSubviews.Count;
 
@@ -581,7 +581,7 @@ public partial class View
                     {
                         View deep = FindDeepestView (v, rx, ry, out resx, out resy);
 
-                        if (deep == null)
+                        if (deep is null)
                         {
                             return v;
                         }
@@ -605,7 +605,7 @@ public partial class View
         Rect ret = Frame;
         View super = SuperView;
 
-        while (super != null)
+        while (super is { })
         {
             Point boundsOffset = super.GetBoundsOffset ();
             ret.X += super.Frame.X + boundsOffset.X;
@@ -701,7 +701,7 @@ public partial class View
 
         // If the 'to' is rooted to 'from' and the layoutstyle is Computed it's a special-case.
         // Use LayoutSubview with the Frame of the 'from' 
-        if (SuperView != null && GetTopSuperView () != null && LayoutNeeded && edges.Count > 0)
+        if (SuperView is { } && GetTopSuperView () is { } && LayoutNeeded && edges.Count > 0)
         {
             foreach ((View from, View to) in edges)
             {
@@ -738,7 +738,7 @@ public partial class View
         Point superViewBoundsOffset = SuperView?.GetBoundsOffset () ?? Point.Empty;
         var ret = new Point (x - Frame.X - superViewBoundsOffset.X, y - Frame.Y - superViewBoundsOffset.Y);
 
-        if (SuperView != null)
+        if (SuperView is { })
         {
             Point superFrame = SuperView.ScreenToFrame (x - superViewBoundsOffset.X, y - superViewBoundsOffset.Y);
             ret = new Point (superFrame.X - Frame.X, superFrame.Y - Frame.Y);
@@ -846,7 +846,7 @@ public partial class View
     /// <summary>Overriden by <see cref="Adornment"/> to do nothing, as the <see cref="Adornment"/> does not have adornments.</summary>
     internal virtual void LayoutAdornments ()
     {
-        if (Margin == null)
+        if (Margin is null)
         {
             return; // CreateAdornments () has not been called yet
         }
@@ -918,7 +918,7 @@ public partial class View
         // First try SuperView.Bounds, then Application.Top, then Driver.Bounds.
         // Finally, if none of those are valid, use int.MaxValue (for Unit tests).
         Rect relativeBounds = SuperView is { IsInitialized: true } ? SuperView.Bounds :
-                              Application.Top != null && Application.Top.IsInitialized ? Application.Top.Bounds :
+                              Application.Top is { } && Application.Top.IsInitialized ? Application.Top.Bounds :
                               Application.Driver?.Bounds ?? new Rect (0, 0, int.MaxValue, int.MaxValue);
         SetRelativeLayout (relativeBounds);
 
@@ -970,10 +970,10 @@ public partial class View
     /// </param>
     internal void SetRelativeLayout (Rect superviewBounds)
     {
-        Debug.Assert (_x != null);
-        Debug.Assert (_y != null);
-        Debug.Assert (_width != null);
-        Debug.Assert (_height != null);
+        Debug.Assert (_x is { });
+        Debug.Assert (_y is { });
+        Debug.Assert (_width is { });
+        Debug.Assert (_height is { });
 
         int newX, newW, newY, newH;
         var autosize = Size.Empty;
@@ -1248,7 +1248,7 @@ public partial class View
             if (from == to)
             {
                 // if not yet added to the result, add it and remove from edge
-                if (result.Find (v => v == from) == null)
+                if (result.Find (v => v == from) is null)
                 {
                     result.Add (from);
                 }
@@ -1258,13 +1258,13 @@ public partial class View
             else if (from.SuperView == to.SuperView)
             {
                 // if 'from' is not yet added to the result, add it
-                if (result.Find (v => v == from) == null)
+                if (result.Find (v => v == from) is null)
                 {
                     result.Add (from);
                 }
 
                 // if 'to' is not yet added to the result, add it
-                if (result.Find (v => v == to) == null)
+                if (result.Find (v => v == to) is null)
                 {
                     result.Add (to);
                 }
@@ -1319,7 +1319,7 @@ public partial class View
                 break;
             case Dim.DimFactor factor:
                 // Tries to get the SuperView height otherwise the view height.
-                int sh = SuperView != null ? SuperView.Frame.Height : h;
+                int sh = SuperView is { } ? SuperView.Frame.Height : h;
 
                 if (factor.IsFromRemaining ())
                 {
@@ -1369,7 +1369,7 @@ public partial class View
                 break;
             case Dim.DimFactor factor:
                 // Tries to get the SuperView Width otherwise the view Width.
-                int sw = SuperView != null ? SuperView.Frame.Width : w;
+                int sw = SuperView is { } ? SuperView.Frame.Width : w;
 
                 if (factor.IsFromRemaining ())
                 {

+ 5 - 5
Terminal.Gui/View/View.cs

@@ -139,7 +139,7 @@ public partial class View : Responder, ISupportInitializeNotification
             {
                 if (value)
                 {
-                    if (SuperView == null || SuperView?.Enabled == true)
+                    if (SuperView is null || SuperView?.Enabled == true)
                     {
                         base.Enabled = value;
                     }
@@ -157,7 +157,7 @@ public partial class View : Responder, ISupportInitializeNotification
                 OnEnabledChanged ();
                 SetNeedsDisplay ();
 
-                if (_subviews != null)
+                if (_subviews is { })
                 {
                     foreach (View view in _subviews)
                     {
@@ -198,11 +198,11 @@ public partial class View : Responder, ISupportInitializeNotification
                 _title = value;
                 SetNeedsDisplay ();
 #if DEBUG
-                if (_title != null && string.IsNullOrEmpty (Id))
+                if (_title is { } && string.IsNullOrEmpty (Id))
                 {
                     Id = _title;
                 }
-#endif // DEBUG
+#endif
                 OnTitleChanged (old, _title);
             }
         }
@@ -438,7 +438,7 @@ public partial class View : Responder, ISupportInitializeNotification
 
         OnResizeNeeded ();
 
-        if (_subviews != null)
+        if (_subviews is { })
         {
             foreach (View view in _subviews)
             {

+ 14 - 14
Terminal.Gui/View/ViewDrawing.cs

@@ -11,7 +11,7 @@ public partial class View
     {
         get
         {
-            if (_colorScheme == null)
+            if (_colorScheme is null)
             {
                 return SuperView?.ColorScheme;
             }
@@ -100,7 +100,7 @@ public partial class View
     /// <param name="regionScreen">The screen-relative rectangle to clear.</param>
     public void Clear (Rect regionScreen)
     {
-        if (Driver == null)
+        if (Driver is null)
         {
             return;
         }
@@ -123,7 +123,7 @@ public partial class View
     /// </remarks>
     public Rect ClipToBounds ()
     {
-        if (Driver == null)
+        if (Driver is null)
         {
             return Rect.Empty;
         }
@@ -163,7 +163,7 @@ public partial class View
 
         Rect prevClip = ClipToBounds ();
 
-        if (ColorScheme != null)
+        if (ColorScheme is { })
         {
             //Driver.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
             Driver?.SetAttribute (GetNormalColor ());
@@ -178,7 +178,7 @@ public partial class View
             OnDrawContent (Bounds);
         }
 
-        if (Driver != null)
+        if (Driver is { })
         {
             Driver.Clip = prevClip;
         }
@@ -279,7 +279,7 @@ public partial class View
     {
         ColorScheme cs = ColorScheme;
 
-        if (ColorScheme == null)
+        if (ColorScheme is null)
         {
             cs = new ColorScheme ();
         }
@@ -297,7 +297,7 @@ public partial class View
     {
         ColorScheme cs = ColorScheme;
 
-        if (ColorScheme == null)
+        if (ColorScheme is null)
         {
             cs = new ColorScheme ();
         }
@@ -315,7 +315,7 @@ public partial class View
     {
         ColorScheme cs = ColorScheme;
 
-        if (ColorScheme == null)
+        if (ColorScheme is null)
         {
             cs = new ColorScheme ();
         }
@@ -329,7 +329,7 @@ public partial class View
     /// <param name="row">the row to move to, in view-relative coordinates.</param>
     public void Move (int col, int row)
     {
-        if (Driver == null || Driver?.Rows == 0)
+        if (Driver is null || Driver?.Rows == 0)
         {
             return;
         }
@@ -371,14 +371,14 @@ public partial class View
     {
         if (NeedsDisplay)
         {
-            if (SuperView != null)
+            if (SuperView is { })
             {
                 Clear (BoundsToScreen (contentArea));
             }
 
             if (!string.IsNullOrEmpty (TextFormatter.Text))
             {
-                if (TextFormatter != null)
+                if (TextFormatter is { })
                 {
                     TextFormatter.NeedsFormat = true;
                 }
@@ -396,7 +396,7 @@ public partial class View
 
         // Draw subviews
         // TODO: Implement OnDrawSubviews (cancelable);
-        if (_subviews != null && SubViewNeedsDisplay)
+        if (_subviews is { } && SubViewNeedsDisplay)
         {
             IEnumerable<View> subviewsNeedingDraw = _subviews.Where (
                                                                      view => view.Visible
@@ -544,7 +544,7 @@ public partial class View
             Padding?.SetNeedsDisplay (Padding.Bounds);
         }
 
-        if (_subviews == null)
+        if (_subviews is null)
         {
             return;
         }
@@ -566,7 +566,7 @@ public partial class View
     {
         SubViewNeedsDisplay = true;
 
-        if (_superView != null && !_superView.SubViewNeedsDisplay)
+        if (_superView is { } && !_superView.SubViewNeedsDisplay)
         {
             _superView.SetSubViewNeedsDisplay ();
         }

+ 7 - 7
Terminal.Gui/View/ViewKeyboard.cs

@@ -199,7 +199,7 @@ public partial class View
     {
         get
         {
-            if (TextFormatter != null)
+            if (TextFormatter is { })
             {
                 return TextFormatter.HotKeySpecifier;
             }
@@ -215,7 +215,7 @@ public partial class View
 
     private void SetHotKey ()
     {
-        if (TextFormatter == null || HotKeySpecifier == new Rune ('\xFFFF'))
+        if (TextFormatter is null || HotKeySpecifier == new Rune ('\xFFFF'))
         {
             return; // throw new InvalidOperationException ("Can't set HotKey unless a TextFormatter has been created");
         }
@@ -263,7 +263,7 @@ public partial class View
                 return;
             }
 
-            if (SuperView?._tabIndexes == null || SuperView?._tabIndexes.Count == 1)
+            if (SuperView?._tabIndexes is null || SuperView?._tabIndexes.Count == 1)
             {
                 _tabIndex = 0;
 
@@ -401,7 +401,7 @@ public partial class View
 
         bool? handled = OnInvokingKeyBindings (keyEvent);
 
-        if (handled != null && (bool)handled)
+        if (handled is { } && (bool)handled)
         {
             return true;
         }
@@ -643,7 +643,7 @@ public partial class View
         //   `InvokeKeyBindings` returns `true`. Continue passing the event (return `false` from `OnInvokeKeyBindings`).
         bool? handled = InvokeKeyBindings (keyEvent);
 
-        if (handled != null && (bool)handled)
+        if (handled is { } && (bool)handled)
         {
             // Stop processing if any key binding handled the key.
             // DO NOT stop processing if there are no matching key bindings or none of the key bindings handled the key
@@ -665,7 +665,7 @@ public partial class View
                 keyEvent.Scope = KeyBindingScope.HotKey;
                 handled = view.OnInvokingKeyBindings (keyEvent);
 
-                if (handled != null && (bool)handled)
+                if (handled is { } && (bool)handled)
                 {
                     return true;
                 }
@@ -765,7 +765,7 @@ public partial class View
         // if there is already an implementation of this command
         // replace that implementation
         // else record how to perform the action (this should be the normal case)
-        if (CommandImplementations != null)
+        if (CommandImplementations is { })
         {
             CommandImplementations [command] = f;
         }

+ 1 - 1
Terminal.Gui/View/ViewMouse.cs

@@ -61,7 +61,7 @@ public partial class View
 
         if (mouseEvent.Flags == MouseFlags.Button1Clicked)
         {
-            if (CanFocus && !HasFocus && SuperView != null)
+            if (CanFocus && !HasFocus && SuperView is { })
             {
                 SuperView.SetFocus (this);
                 SetNeedsDisplay ();

+ 31 - 31
Terminal.Gui/View/ViewSubViews.cs

@@ -36,17 +36,17 @@ public partial class View
     /// </remarks>
     public virtual void Add (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return;
         }
 
-        if (_subviews == null)
+        if (_subviews is null)
         {
             _subviews = new List<View> ();
         }
 
-        if (_tabIndexes == null)
+        if (_tabIndexes is null)
         {
             _tabIndexes = new List<View> ();
         }
@@ -97,7 +97,7 @@ public partial class View
     /// </remarks>
     public void Add (params View [] views)
     {
-        if (views == null)
+        if (views is null)
         {
             return;
         }
@@ -188,7 +188,7 @@ public partial class View
     /// <remarks></remarks>
     public virtual void Remove (View view)
     {
-        if (view == null || _subviews == null)
+        if (view is null || _subviews is null)
         {
             return;
         }
@@ -220,7 +220,7 @@ public partial class View
     /// <summary>Removes all subviews (children) added via <see cref="Add(View)"/> or <see cref="Add(View[])"/> from this View.</summary>
     public virtual void RemoveAll ()
     {
-        if (_subviews == null)
+        if (_subviews is null)
         {
             return;
         }
@@ -305,7 +305,7 @@ public partial class View
         get => SuperView?.FocusDirection ?? _focusDirection;
         set
         {
-            if (SuperView != null)
+            if (SuperView is { })
             {
                 SuperView.FocusDirection = value;
             }
@@ -341,7 +341,7 @@ public partial class View
         }
 
         // Remove focus down the chain of subviews if focus is removed
-        if (!value && Focused != null)
+        if (!value && Focused is { })
         {
             View f = Focused;
             f.OnLeave (view);
@@ -387,7 +387,7 @@ public partial class View
 
                 if (value && _tabIndex == -1)
                 {
-                    TabIndex = SuperView != null ? SuperView._tabIndexes.IndexOf (this) : -1;
+                    TabIndex = SuperView is { } ? SuperView._tabIndexes.IndexOf (this) : -1;
                 }
 
                 TabStop = value;
@@ -402,11 +402,11 @@ public partial class View
                     SetHasFocus (false, this);
                     SuperView?.EnsureFocus ();
 
-                    if (SuperView != null && SuperView.Focused == null)
+                    if (SuperView is { } && SuperView.Focused is null)
                     {
                         SuperView.FocusNext ();
 
-                        if (SuperView.Focused == null && Application.Current != null)
+                        if (SuperView.Focused is null && Application.Current is { })
                         {
                             Application.Current.FocusNext ();
                         }
@@ -415,7 +415,7 @@ public partial class View
                     }
                 }
 
-                if (_subviews != null && IsInitialized)
+                if (_subviews is { } && IsInitialized)
                 {
                     foreach (View view in _subviews)
                     {
@@ -499,14 +499,14 @@ public partial class View
     {
         get
         {
-            if (Focused == null)
+            if (Focused is null)
             {
                 return null;
             }
 
             View most = Focused.MostFocused;
 
-            if (most != null)
+            if (most is { })
             {
                 return most;
             }
@@ -519,7 +519,7 @@ public partial class View
     /// <param name="view">View.</param>
     private void SetFocus (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return;
         }
@@ -556,12 +556,12 @@ public partial class View
             }
         }
 
-        if (c == null)
+        if (c is null)
         {
             throw new ArgumentException ("the specified view is not part of the hierarchy of this view");
         }
 
-        if (Focused != null)
+        if (Focused is { })
         {
             Focused.SetHasFocus (false, view);
         }
@@ -572,7 +572,7 @@ public partial class View
         Focused.EnsureFocus ();
 
         // Send focus upwards
-        if (SuperView != null)
+        if (SuperView is { })
         {
             SuperView.SetFocus (this);
         }
@@ -595,7 +595,7 @@ public partial class View
             return;
         }
 
-        if (SuperView != null)
+        if (SuperView is { })
         {
             SuperView.SetFocus (this);
         }
@@ -611,7 +611,7 @@ public partial class View
     /// </summary>
     public void EnsureFocus ()
     {
-        if (Focused == null && _subviews?.Count > 0)
+        if (Focused is null && _subviews?.Count > 0)
         {
             if (FocusDirection == NavigationDirection.Forward)
             {
@@ -632,7 +632,7 @@ public partial class View
             return;
         }
 
-        if (_tabIndexes == null)
+        if (_tabIndexes is null)
         {
             SuperView?.SetFocus (this);
 
@@ -658,7 +658,7 @@ public partial class View
             return;
         }
 
-        if (_tabIndexes == null)
+        if (_tabIndexes is null)
         {
             SuperView?.SetFocus (this);
 
@@ -691,12 +691,12 @@ public partial class View
 
         FocusDirection = NavigationDirection.Backward;
 
-        if (_tabIndexes == null || _tabIndexes.Count == 0)
+        if (_tabIndexes is null || _tabIndexes.Count == 0)
         {
             return false;
         }
 
-        if (Focused == null)
+        if (Focused is null)
         {
             FocusLast ();
 
@@ -737,7 +737,7 @@ public partial class View
             }
         }
 
-        if (Focused != null)
+        if (Focused is { })
         {
             Focused.SetHasFocus (false, this);
             Focused = null;
@@ -757,12 +757,12 @@ public partial class View
 
         FocusDirection = NavigationDirection.Forward;
 
-        if (_tabIndexes == null || _tabIndexes.Count == 0)
+        if (_tabIndexes is null || _tabIndexes.Count == 0)
         {
             return false;
         }
 
-        if (Focused == null)
+        if (Focused is null)
         {
             FocusFirst ();
 
@@ -802,7 +802,7 @@ public partial class View
             }
         }
 
-        if (Focused != null)
+        if (Focused is { })
         {
             Focused.SetHasFocus (false, this);
             Focused = null;
@@ -813,12 +813,12 @@ public partial class View
 
     private View GetMostFocused (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return null;
         }
 
-        return view.Focused != null ? GetMostFocused (view.Focused) : view;
+        return view.Focused is { } ? GetMostFocused (view.Focused) : view;
     }
 
     /// <summary>Positions the cursor in the right position based on the currently focused view in the chain.</summary>
@@ -838,7 +838,7 @@ public partial class View
 
         // BUGBUG: v2 - This needs to support children of Frames too
 
-        if (Focused == null && SuperView != null)
+        if (Focused is null && SuperView is { })
         {
             SuperView.EnsureFocus ();
         }

+ 4 - 4
Terminal.Gui/View/ViewText.cs

@@ -50,7 +50,7 @@ public partial class View
             OnResizeNeeded ();
 
 #if DEBUG
-            if (_text != null && string.IsNullOrEmpty (Id))
+            if (_text is { } && string.IsNullOrEmpty (Id))
             {
                 Id = _text;
             }
@@ -183,7 +183,7 @@ public partial class View
     /// <summary>Can be overridden if the <see cref="Terminal.Gui.TextFormatter.Text"/> has different format than the default.</summary>
     protected virtual void UpdateTextFormatterText ()
     {
-        if (TextFormatter != null)
+        if (TextFormatter is { })
         {
             TextFormatter.Text = _text;
         }
@@ -313,7 +313,7 @@ public partial class View
 
                     // TODO: v2 - This uses frame.Width; it should only use Bounds
                     if (_frame.Width < colWidth
-                        && (Width == null || (Bounds.Width >= 0 && Width is Dim.DimAbsolute && Width.Anchor (0) >= 0 && Width.Anchor (0) < colWidth)))
+                        && (Width is null || (Bounds.Width >= 0 && Width is Dim.DimAbsolute && Width.Anchor (0) >= 0 && Width.Anchor (0) < colWidth)))
                     {
                         sizeRequired = new Size (colWidth, Bounds.Height);
 
@@ -322,7 +322,7 @@ public partial class View
 
                     break;
                 default:
-                    if (_frame.Height < 1 && (Height == null || (Height is Dim.DimAbsolute && Height.Anchor (0) == 0)))
+                    if (_frame.Height < 1 && (Height is null || (Height is Dim.DimAbsolute && Height.Anchor (0) == 0)))
                     {
                         sizeRequired = new Size (Bounds.Width, 1);
 

+ 1 - 1
Terminal.Gui/Views/AutocompleteFilepathContext.cs

@@ -25,7 +25,7 @@ internal class FilepathSuggestionGenerator : ISuggestionGenerator
             state = fileState.State;
         }
 
-        if (state == null)
+        if (state is null)
         {
             return Enumerable.Empty<Suggestion> ();
         }

+ 1 - 1
Terminal.Gui/Views/CheckBox.cs

@@ -68,7 +68,7 @@ public class CheckBox : View
         get => _checked;
         set
         {
-            if (value == null && !AllowNullChecked)
+            if (value is null && !AllowNullChecked)
             {
                 return;
             }

+ 9 - 9
Terminal.Gui/Views/ComboBox.cs

@@ -56,7 +56,7 @@ public class ComboBox : View
                      // Determine if this view is hosted inside a dialog and is the only control
                      for (View view = SuperView; view != null; view = view.SuperView)
                      {
-                         if (view is Dialog && SuperView != null && SuperView.Subviews.Count == 1 && SuperView.Subviews [0] == this)
+                         if (view is Dialog && SuperView is { } && SuperView.Subviews.Count == 1 && SuperView.Subviews [0] == this)
                          {
                              _autoHide = false;
 
@@ -128,7 +128,7 @@ public class ComboBox : View
 
             if (_search.ReadOnly)
             {
-                if (_search.ColorScheme != null)
+                if (_search.ColorScheme is { })
                 {
                     _search.ColorScheme = new ColorScheme (_search.ColorScheme) { Normal = _search.ColorScheme.Focus };
                 }
@@ -152,7 +152,7 @@ public class ComboBox : View
         {
             if (_selectedItem != value
                 && (value == -1
-                    || (_source != null && value > -1 && value < _source.Count)))
+                    || (_source is { } && value > -1 && value < _source.Count)))
             {
                 _selectedItem = _lastSelectedItem = value;
 
@@ -181,7 +181,7 @@ public class ComboBox : View
             _source = value;
 
             // Only need to refresh list if its been added to a container view
-            if (SuperView != null && SuperView.Subviews.Contains (this))
+            if (SuperView is { } && SuperView.Subviews.Contains (this))
             {
                 SelectedItem = -1;
                 _search.Text = "";
@@ -372,7 +372,7 @@ public class ComboBox : View
     /// </remarks>
     public void SetSource (IList source)
     {
-        if (source == null)
+        if (source is null)
         {
             Source = null;
         }
@@ -605,7 +605,7 @@ public class ComboBox : View
 
     private void ProcessLayout ()
     {
-        if (Bounds.Height < _minimumHeight && (Height == null || Height is Dim.DimAbsolute))
+        if (Bounds.Height < _minimumHeight && (Height is null || Height is Dim.DimAbsolute))
         {
             Height = _minimumHeight;
         }
@@ -723,7 +723,7 @@ public class ComboBox : View
 
     private void SetSearchSet ()
     {
-        if (Source == null)
+        if (Source is null)
         {
             return;
         }
@@ -873,7 +873,7 @@ public class ComboBox : View
 
                 Move (0, row);
 
-                if (Source == null || item >= Source.Count)
+                if (Source is null || item >= Source.Count)
                 {
                     for (var c = 0; c < f.Width; c++)
                     {
@@ -885,7 +885,7 @@ public class ComboBox : View
                     var rowEventArgs = new ListViewRowEventArgs (item);
                     OnRowRender (rowEventArgs);
 
-                    if (rowEventArgs.RowAttribute != null && current != rowEventArgs.RowAttribute)
+                    if (rowEventArgs.RowAttribute is { } && current != rowEventArgs.RowAttribute)
                     {
                         current = (Attribute)rowEventArgs.RowAttribute;
                         Driver.SetAttribute (current);

+ 2 - 2
Terminal.Gui/Views/Dialog.cs

@@ -80,7 +80,7 @@ public class Dialog : Window
         get => _buttons.ToArray ();
         init
         {
-            if (value == null)
+            if (value is null)
             {
                 return;
             }
@@ -105,7 +105,7 @@ public class Dialog : Window
     /// <param name="button">Button to add.</param>
     public void AddButton (Button button)
     {
-        if (button == null)
+        if (button is null)
         {
             return;
         }

+ 21 - 21
Terminal.Gui/Views/FileDialog.cs

@@ -257,7 +257,7 @@ public class FileDialog : Dialog
                              {
                                  IFileSystemInfo selected = _treeView.SelectedObject;
 
-                                 if (selected != null)
+                                 if (selected is { })
                                  {
                                      if (!_treeView.CanExpand (selected) || _treeView.IsExpanded (selected))
                                      {
@@ -705,7 +705,7 @@ public class FileDialog : Dialog
 
         if (!IsCompatibleWithOpenMode (_tbPath.Text, out string reason))
         {
-            if (reason != null)
+            if (reason is { })
             {
                 _feedback = reason;
                 SetNeedsDisplay ();
@@ -746,7 +746,7 @@ public class FileDialog : Dialog
         _tbPath.ClearAllSelection ();
         _tbPath.Autocomplete.ClearSuggestions ();
 
-        if (State != null)
+        if (State is { })
         {
             State.RefreshChildren ();
             WriteStateToTableView ();
@@ -842,7 +842,7 @@ public class FileDialog : Dialog
     {
         IFileSystemInfo [] toDelete = GetFocusedFiles ();
 
-        if (toDelete != null && FileOperationsHandler.Delete (toDelete))
+        if (toDelete is { } && FileOperationsHandler.Delete (toDelete))
         {
             RefreshState ();
         }
@@ -876,7 +876,7 @@ public class FileDialog : Dialog
 
     private IFileSystemInfo [] GetFocusedFiles ()
     {
-        if (!_tableView.HasFocus || !_tableView.CanFocus || FileOperationsHandler == null)
+        if (!_tableView.HasFocus || !_tableView.CanFocus || FileOperationsHandler is null)
         {
             return null;
         }
@@ -1025,7 +1025,7 @@ public class FileDialog : Dialog
             {
                 FileSystemInfoStats add = State?.Children [p.Y];
 
-                if (add != null)
+                if (add is { })
                 {
                     toReturn.Add (add);
                 }
@@ -1054,11 +1054,11 @@ public class FileDialog : Dialog
 
     private void New ()
     {
-        if (State != null)
+        if (State is { })
         {
             IFileSystemInfo created = FileOperationsHandler.New (_fileSystem, State.Directory);
 
-            if (created != null)
+            if (created is { })
             {
                 RefreshState ();
                 RestoreSelection (created);
@@ -1070,7 +1070,7 @@ public class FileDialog : Dialog
     {
         Point? clickedCell = _tableView.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out int? clickedCol);
 
-        if (clickedCol != null)
+        if (clickedCol is { })
         {
             if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked))
             {
@@ -1085,7 +1085,7 @@ public class FileDialog : Dialog
         }
         else
         {
-            if (clickedCell != null && e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked))
+            if (clickedCell is { } && e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked))
             {
                 // right click in rest of table
                 ShowCellContextMenu (clickedCell, e);
@@ -1149,7 +1149,7 @@ public class FileDialog : Dialog
 
             _tbPath.Autocomplete.ClearSuggestions ();
 
-            if (pathText != null)
+            if (pathText is { })
             {
                 Path = pathText;
             }
@@ -1199,7 +1199,7 @@ public class FileDialog : Dialog
         {
             IFileSystemInfo newNamed = FileOperationsHandler.Rename (_fileSystem, toRename.Single ());
 
-            if (newNamed != null)
+            if (newNamed is { })
             {
                 RefreshState ();
                 RestoreSelection (newNamed);
@@ -1219,7 +1219,7 @@ public class FileDialog : Dialog
 
     //			ClearFeedback ();
 
-    //			if (allowedTypeMenuBar != null &&
+    //			if (allowedTypeMenuBar is { } &&
     //				keyEvent.ConsoleDriverKey == Key.Tab &&
     //				allowedTypeMenuBar.IsMenuOpen) {
     //				allowedTypeMenuBar.CloseMenu (false, false, false);
@@ -1229,7 +1229,7 @@ public class FileDialog : Dialog
     //		}
     private void RestartSearch ()
     {
-        if (_disposed || State?.Directory == null)
+        if (_disposed || State?.Directory is null)
         {
             return;
         }
@@ -1240,7 +1240,7 @@ public class FileDialog : Dialog
         }
 
         // user is clearing search terms
-        if (_tbFind.Text == null || _tbFind.Text.Length == 0)
+        if (_tbFind.Text is null || _tbFind.Text.Length == 0)
         {
             // Wait for search cancellation (if any) to finish
             // then push the current dir state
@@ -1259,7 +1259,7 @@ public class FileDialog : Dialog
 
     private void ShowCellContextMenu (Point? clickedCell, MouseEventEventArgs e)
     {
-        if (clickedCell == null)
+        if (clickedCell is null)
         {
             return;
         }
@@ -1394,7 +1394,7 @@ public class FileDialog : Dialog
 
         FileSystemInfoStats stats = RowToStats (obj.NewRow);
 
-        if (stats == null)
+        if (stats is null)
         {
             return;
         }
@@ -1439,7 +1439,7 @@ public class FileDialog : Dialog
 
     private void TreeView_SelectionChanged (object sender, SelectionChangedEventArgs<IFileSystemInfo> e)
     {
-        if (e.NewValue == null)
+        if (e.NewValue is null)
         {
             return;
         }
@@ -1469,7 +1469,7 @@ public class FileDialog : Dialog
             return true;
         }
 
-        if (reason != null)
+        if (reason is { })
         {
             _feedback = reason;
             SetNeedsDisplay ();
@@ -1487,7 +1487,7 @@ public class FileDialog : Dialog
 
     private void WriteStateToTableView ()
     {
-        if (State == null)
+        if (State is null)
         {
             return;
         }
@@ -1511,7 +1511,7 @@ public class FileDialog : Dialog
                                                                   _fileDialog.State?.Children [idx]
                                                                  );
 
-            if (val == null)
+            if (val is null)
             {
                 return string.Empty;
             }

+ 1 - 1
Terminal.Gui/Views/FileDialogTableSource.cs

@@ -65,7 +65,7 @@ internal class FileDialogTableSource : ITableSource
             case 1:
                 return stats?.HumanReadableLength ?? string.Empty;
             case 2:
-                if (stats == null || stats.IsParent || stats.LastWriteTime == null)
+                if (stats is null || stats.IsParent || stats.LastWriteTime is null)
                 {
                     return string.Empty;
                 }

+ 2 - 2
Terminal.Gui/Views/GraphView/Series.cs

@@ -64,7 +64,7 @@ public class MultiBarSeries : ISeries
     {
         subSeries = new BarSeries [numberOfBarsPerCategory];
 
-        if (colors != null && colors.Length != numberOfBarsPerCategory)
+        if (colors is { } && colors.Length != numberOfBarsPerCategory)
         {
             throw new ArgumentException (
                                          "Number of colors must match the number of bars",
@@ -81,7 +81,7 @@ public class MultiBarSeries : ISeries
             // Only draw labels for the first bar in each category
             subSeries [i].DrawLabels = i == 0;
 
-            if (colors != null)
+            if (colors is { })
             {
                 subSeries [i].OverrideBarColor = colors [i];
             }

+ 2 - 2
Terminal.Gui/Views/HexView.cs

@@ -173,7 +173,7 @@ public class HexView : View
         get => source;
         set
         {
-            if (value == null)
+            if (value is null)
             {
                 throw new ArgumentNullException ("source");
             }
@@ -233,7 +233,7 @@ public class HexView : View
             source.WriteByte (kv.Value);
             source.Flush ();
 
-            if (stream != null)
+            if (stream is { })
             {
                 stream.Position = kv.Key;
                 stream.WriteByte (kv.Value);

+ 1 - 1
Terminal.Gui/Views/Label.cs

@@ -77,7 +77,7 @@ public class Label : View
 
         if (mouseEvent.Flags == MouseFlags.Button1Clicked)
         {
-            if (!HasFocus && SuperView != null)
+            if (!HasFocus && SuperView is { })
             {
                 if (!SuperView.HasFocus)
                 {

+ 15 - 15
Terminal.Gui/Views/ListView.cs

@@ -172,7 +172,7 @@ public class ListView : View
         {
             _allowsMultipleSelection = value;
 
-            if (Source != null && !_allowsMultipleSelection)
+            if (Source is { } && !_allowsMultipleSelection)
             {
                 // Clear all selections except selected 
                 for (var i = 0; i < Source.Count; i++)
@@ -201,7 +201,7 @@ public class ListView : View
         get => _left;
         set
         {
-            if (_source == null)
+            if (_source is null)
             {
                 return;
             }
@@ -226,7 +226,7 @@ public class ListView : View
         get => _selected;
         set
         {
-            if (_source == null || _source.Count == 0)
+            if (_source is null || _source.Count == 0)
             {
                 return;
             }
@@ -265,7 +265,7 @@ public class ListView : View
         get => _top;
         set
         {
-            if (_source == null)
+            if (_source is null)
             {
                 return;
             }
@@ -363,7 +363,7 @@ public class ListView : View
             SetFocus ();
         }
 
-        if (_source == null)
+        if (_source is null)
         {
             return false;
         }
@@ -643,7 +643,7 @@ public class ListView : View
 
             Move (0, row);
 
-            if (_source == null || item >= _source.Count)
+            if (_source is null || item >= _source.Count)
             {
                 for (var c = 0; c < f.Width; c++)
                 {
@@ -655,7 +655,7 @@ public class ListView : View
                 var rowEventArgs = new ListViewRowEventArgs (item);
                 OnRowRender (rowEventArgs);
 
-                if (rowEventArgs.RowAttribute != null && current != rowEventArgs.RowAttribute)
+                if (rowEventArgs.RowAttribute is { } && current != rowEventArgs.RowAttribute)
                 {
                     current = (Attribute)rowEventArgs.RowAttribute;
                     Driver.SetAttribute (current);
@@ -695,7 +695,7 @@ public class ListView : View
     /// <returns></returns>
     public virtual bool OnOpenSelectedItem ()
     {
-        if (_source.Count <= _selected || _selected < 0 || OpenSelectedItem == null)
+        if (_source.Count <= _selected || _selected < 0 || OpenSelectedItem is null)
         {
             return false;
         }
@@ -819,7 +819,7 @@ public class ListView : View
     /// </remarks>
     public void SetSource (IList source)
     {
-        if (source == null && (Source == null || !(Source is ListWrapper)))
+        if (source is null && (Source is null || !(Source is ListWrapper)))
         {
             Source = null;
         }
@@ -840,7 +840,7 @@ public class ListView : View
         return Task.Factory.StartNew (
                                       () =>
                                       {
-                                          if (source == null && (Source == null || !(Source is ListWrapper)))
+                                          if (source is null && (Source is null || !(Source is ListWrapper)))
                                           {
                                               Source = null;
                                           }
@@ -873,7 +873,7 @@ public class ListWrapper : IListDataSource
     /// <inheritdoc/>
     public ListWrapper (IList source)
     {
-        if (source != null)
+        if (source is { })
         {
             _count = source.Count;
             _marks = new BitArray (_count);
@@ -883,7 +883,7 @@ public class ListWrapper : IListDataSource
     }
 
     /// <inheritdoc/>
-    public int Count => _source != null ? _source.Count : 0;
+    public int Count => _source is { } ? _source.Count : 0;
 
     /// <inheritdoc/>
     public int Length { get; }
@@ -903,7 +903,7 @@ public class ListWrapper : IListDataSource
         container.Move (col, line);
         object t = _source? [item];
 
-        if (t == null)
+        if (t is null)
         {
             RenderUstr (driver, "", col, line, width);
         }
@@ -950,7 +950,7 @@ public class ListWrapper : IListDataSource
     /// <inheritdoc/>
     public int StartsWith (string search)
     {
-        if (_source == null || _source?.Count == 0)
+        if (_source is null || _source?.Count == 0)
         {
             return -1;
         }
@@ -980,7 +980,7 @@ public class ListWrapper : IListDataSource
 
     private int GetMaxLengthItem ()
     {
-        if (_source == null || _source?.Count == 0)
+        if (_source is null || _source?.Count == 0)
         {
             return 0;
         }

+ 5 - 5
Terminal.Gui/Views/Menu/ContextMenu.cs

@@ -33,7 +33,7 @@ public sealed class ContextMenu : IDisposable
     {
         if (IsShow)
         {
-            if (_menuBar.SuperView != null)
+            if (_menuBar.SuperView is { })
             {
                 Hide ();
             }
@@ -113,7 +113,7 @@ public sealed class ContextMenu : IDisposable
             IsShow = false;
         }
 
-        if (_container != null)
+        if (_container is { })
         {
             _container.Closing -= Container_Closing;
         }
@@ -135,7 +135,7 @@ public sealed class ContextMenu : IDisposable
     /// <summary>Shows (opens) the ContextMenu, displaying the <see cref="MenuItem"/>s it contains.</summary>
     public void Show ()
     {
-        if (_menuBar != null)
+        if (_menuBar is { })
         {
             Hide ();
         }
@@ -145,7 +145,7 @@ public sealed class ContextMenu : IDisposable
         Rect frame = Application.Driver.Bounds;
         Point position = Position;
 
-        if (Host != null)
+        if (Host is { })
         {
             Host.BoundsToScreen (frame.X, frame.Y, out int x, out int y);
             var pos = new Point (x, y);
@@ -179,7 +179,7 @@ public sealed class ContextMenu : IDisposable
         {
             if (frame.Bottom - rect.Height - 1 >= 0 || !ForceMinimumPosToZero)
             {
-                if (Host == null)
+                if (Host is null)
                 {
                     position.Y = frame.Bottom - rect.Height - 1;
                 }

+ 37 - 37
Terminal.Gui/Views/Menu/Menu.cs

@@ -103,7 +103,7 @@ public class MenuItem
         {
             _checkType = value;
 
-            if (_checkType == MenuItemCheckStyle.Checked && !_allowNullChecked && Checked == null)
+            if (_checkType == MenuItemCheckStyle.Checked && !_allowNullChecked && Checked is null)
             {
                 Checked = false;
             }
@@ -300,7 +300,7 @@ internal sealed class Menu : View
 
     internal static Rect MakeFrame (int x, int y, MenuItem [] items, Menu parent = null)
     {
-        if (items == null || items.Length == 0)
+        if (items is null || items.Length == 0)
         {
             return new Rect ();
         }
@@ -311,7 +311,7 @@ internal sealed class Menu : View
         int maxW = (items.Max (z => z?.Width) ?? 0) + borderOffset;
         int maxH = items.Length + borderOffset;
 
-        if (parent != null && x + maxW > Driver.Cols)
+        if (parent is { } && x + maxW > Driver.Cols)
         {
             minX = Math.Max (parent.Frame.Right - parent.Frame.Width - maxW, 0);
         }
@@ -411,7 +411,7 @@ internal sealed class Menu : View
 #if SUPPORT_ALT_TO_ACTIVATE_MENU
         Initialized += (s, e) =>
                        {
-                           if (SuperView != null)
+                           if (SuperView is { })
                            {
                                SuperView.KeyUp += SuperView_KeyUp;
                            }
@@ -421,7 +421,7 @@ internal sealed class Menu : View
 
     public Menu ()
     {
-        if (Application.Current != null)
+        if (Application.Current is { })
         {
             Application.Current.DrawContentComplete += Current_DrawContentComplete;
             Application.Current.SizeChanging += Current_TerminalResized;
@@ -485,7 +485,7 @@ internal sealed class Menu : View
 #if SUPPORT_ALT_TO_ACTIVATE_MENU
     void SuperView_KeyUp (object sender, KeyEventArgs e)
     {
-        if (SuperView == null || SuperView.CanFocus == false || SuperView.Visible == false)
+        if (SuperView is null || SuperView.CanFocus == false || SuperView.Visible == false)
         {
             return;
         }
@@ -496,12 +496,12 @@ internal sealed class Menu : View
 
     private void AddKeyBindings (MenuBarItem menuBarItem)
     {
-        if (menuBarItem == null || menuBarItem.Children == null)
+        if (menuBarItem is null || menuBarItem.Children is null)
         {
             return;
         }
 
-        foreach (MenuItem menuItem in menuBarItem.Children.Where (m => m != null))
+        foreach (MenuItem menuItem in menuBarItem.Children.Where (m => m is { }))
         {
             KeyBindings.Add ((KeyCode)menuItem.HotKey.Value, Command.ToggleExpandCollapse);
 
@@ -536,7 +536,7 @@ internal sealed class Menu : View
         {
             _host.Activate (1, _menuBarItemToActivate);
         }
-        else if (_menuItemToSelect != null)
+        else if (_menuItemToSelect is { })
         {
             var m = _menuItemToSelect as MenuBarItem;
 
@@ -544,12 +544,12 @@ internal sealed class Menu : View
             {
                 MenuItem item = _barItems.Children [_currentChild];
 
-                if (item == null)
+                if (item is null)
                 {
                     return true;
                 }
 
-                bool disabled = item == null || !item.IsEnabled ();
+                bool disabled = item is null || !item.IsEnabled ();
 
                 if (!disabled && (_host.UseSubMenusSingleFrame || !CheckSubMenu ()))
                 {
@@ -598,7 +598,7 @@ internal sealed class Menu : View
 
             MenuItem [] children = _barItems.Children;
 
-            if (children == null)
+            if (children is null)
             {
                 return base.OnInvokingKeyBindings (keyEvent);
             }
@@ -656,7 +656,7 @@ internal sealed class Menu : View
 
         bool? handled = base.OnInvokingKeyBindings (keyEvent);
 
-        if (handled != null && (bool)handled)
+        if (handled is { } && (bool)handled)
         {
             return true;
         }
@@ -667,7 +667,7 @@ internal sealed class Menu : View
 
     private bool FindShortcutInChildMenu (KeyCode key, MenuBarItem menuBarItem)
     {
-        if (menuBarItem?.Children == null)
+        if (menuBarItem?.Children is null)
         {
             return false;
         }
@@ -721,7 +721,7 @@ internal sealed class Menu : View
 
         Point locationOffset = _host.GetScreenOffsetFromCurrent ();
 
-        if (SuperView != null && SuperView != Application.Current)
+        if (SuperView is { } && SuperView != Application.Current)
         {
             locationOffset.X += SuperView.Border.Thickness.Left;
             locationOffset.Y += SuperView.Border.Thickness.Top;
@@ -753,7 +753,7 @@ internal sealed class Menu : View
 
     internal Attribute DetermineColorSchemeFor (MenuItem item, int index)
     {
-        if (item == null)
+        if (item is null)
         {
             return GetNormalColor ();
         }
@@ -768,7 +768,7 @@ internal sealed class Menu : View
 
     public override void OnDrawContent (Rect contentArea)
     {
-        if (_barItems.Children == null)
+        if (_barItems.Children is null)
         {
             return;
         }
@@ -795,11 +795,11 @@ internal sealed class Menu : View
             MenuItem item = _barItems.Children [i];
 
             Driver.SetAttribute (
-                                 item == null ? GetNormalColor () :
+                                 item is null ? GetNormalColor () :
                                  i == _currentChild ? ColorScheme.Focus : GetNormalColor ()
                                 );
 
-            if (item == null && BorderStyle != LineStyle.None)
+            if (item is null && BorderStyle != LineStyle.None)
             {
                 Move (-1, i);
                 Driver.AddRune (Glyphs.LeftTee);
@@ -824,17 +824,17 @@ internal sealed class Menu : View
                     break;
                 }
 
-                if (item == null)
+                if (item is null)
                 {
                     Driver.AddRune (Glyphs.HLine);
                 }
-                else if (i == 0 && p == 0 && _host.UseSubMenusSingleFrame && item.Parent.Parent != null)
+                else if (i == 0 && p == 0 && _host.UseSubMenusSingleFrame && item.Parent.Parent is { })
                 {
                     Driver.AddRune (Glyphs.LeftArrow);
                 }
 
                 // This `- 3` is left border + right border + one row in from right
-                else if (p == Frame.Width - 3 && _barItems.SubMenu (_barItems.Children [i]) != null)
+                else if (p == Frame.Width - 3 && _barItems.SubMenu (_barItems.Children [i]) is { })
                 {
                     Driver.AddRune (Glyphs.RightArrow);
                 }
@@ -844,7 +844,7 @@ internal sealed class Menu : View
                 }
             }
 
-            if (item == null)
+            if (item is null)
             {
                 if (BorderStyle != LineStyle.None && SuperView?.Frame.Right - Frame.X > Frame.Width)
                 {
@@ -867,7 +867,7 @@ internal sealed class Menu : View
             }
 
             // Support Checked even though CheckType wasn't set
-            if (item.CheckType == MenuItemCheckStyle.Checked && item.Checked == null)
+            if (item.CheckType == MenuItemCheckStyle.Checked && item.Checked is null)
             {
                 textToDraw = $"{nullCheckedChar} {item.Title}";
             }
@@ -894,7 +894,7 @@ internal sealed class Menu : View
                 {
                     DrawHotString (textToDraw, ColorScheme.Disabled, ColorScheme.Disabled);
                 }
-                else if (i == 0 && _host.UseSubMenusSingleFrame && item.Parent.Parent != null)
+                else if (i == 0 && _host.UseSubMenusSingleFrame && item.Parent.Parent is { })
                 {
                     var tf = new TextFormatter
                     {
@@ -974,7 +974,7 @@ internal sealed class Menu : View
 
     public void Run (Action action)
     {
-        if (action == null || _host == null)
+        if (action is null || _host is null)
         {
             return;
         }
@@ -1075,7 +1075,7 @@ internal sealed class Menu : View
                 _host.OpenMenu (_host._selected);
             }
         }
-        while (_barItems.Children [_currentChild] == null || disabled);
+        while (_barItems.Children [_currentChild] is null || disabled);
 
         SetNeedsDisplay ();
         SetParentSetNeedsDisplay ();
@@ -1156,7 +1156,7 @@ internal sealed class Menu : View
 
             break;
         }
-        while (_barItems.Children [_currentChild] == null || disabled);
+        while (_barItems.Children [_currentChild] is null || disabled);
 
         SetNeedsDisplay ();
         SetParentSetNeedsDisplay ();
@@ -1171,7 +1171,7 @@ internal sealed class Menu : View
 
     private void SetParentSetNeedsDisplay ()
     {
-        if (_host._openSubMenu != null)
+        if (_host._openSubMenu is { })
         {
             foreach (Menu menu in _host._openSubMenu)
             {
@@ -1192,7 +1192,7 @@ internal sealed class Menu : View
 
         _host._handled = false;
         bool disabled;
-        int meY = me.Y - (Border == null ? 0 : Border.Thickness.Top);
+        int meY = me.Y - (Border is null ? 0 : Border.Thickness.Top);
 
         if (me.Flags == MouseFlags.Button1Clicked)
         {
@@ -1210,7 +1210,7 @@ internal sealed class Menu : View
 
             MenuItem item = _barItems.Children [meY];
 
-            if (item == null || !item.IsEnabled ())
+            if (item is null || !item.IsEnabled ())
             {
                 disabled = true;
             }
@@ -1245,7 +1245,7 @@ internal sealed class Menu : View
 
             MenuItem item = _barItems.Children [meY];
 
-            if (item == null)
+            if (item is null)
             {
                 return true;
             }
@@ -1276,18 +1276,18 @@ internal sealed class Menu : View
 
     internal bool CheckSubMenu ()
     {
-        if (_currentChild == -1 || _barItems.Children [_currentChild] == null)
+        if (_currentChild == -1 || _barItems.Children [_currentChild] is null)
         {
             return true;
         }
 
         MenuBarItem subMenu = _barItems.SubMenu (_barItems.Children [_currentChild]);
 
-        if (subMenu != null)
+        if (subMenu is { })
         {
             int pos = -1;
 
-            if (_host._openSubMenu != null)
+            if (_host._openSubMenu is { })
             {
                 pos = _host._openSubMenu.FindIndex (o => o?._barItems == subMenu);
             }
@@ -1334,7 +1334,7 @@ internal sealed class Menu : View
             }
         }
 
-        if (v != null)
+        if (v is { })
         {
             pos = Subviews.IndexOf (v);
         }
@@ -1352,7 +1352,7 @@ internal sealed class Menu : View
 
     protected override void Dispose (bool disposing)
     {
-        if (Application.Current != null)
+        if (Application.Current is { })
         {
             Application.Current.DrawContentComplete -= Current_DrawContentComplete;
             Application.Current.SizeChanging -= Current_TerminalResized;

+ 56 - 56
Terminal.Gui/Views/Menu/MenuBar.cs

@@ -49,7 +49,7 @@ public class MenuBarItem : MenuItem
     /// <value>The children.</value>
     public MenuItem [] Children { get; set; }
 
-    internal bool IsTopLevel => Parent == null && (Children == null || Children.Length == 0) && Action != null;
+    internal bool IsTopLevel => Parent is null && (Children is null || Children.Length == 0) && Action != null;
 
     /// <summary>Get the index of a child <see cref="MenuItem"/>.</summary>
     /// <param name="children"></param>
@@ -58,7 +58,7 @@ public class MenuBarItem : MenuItem
     {
         var i = 0;
 
-        if (Children != null)
+        if (Children is { })
         {
             foreach (MenuItem child in Children)
             {
@@ -97,12 +97,12 @@ public class MenuBarItem : MenuItem
 
     internal void AddKeyBindings (MenuBar menuBar)
     {
-        if (Children == null)
+        if (Children is null)
         {
             return;
         }
 
-        foreach (MenuItem menuItem in Children.Where (m => m != null))
+        foreach (MenuItem menuItem in Children.Where (m => m is { }))
         {
             if (menuItem.HotKey != default (Rune))
             {
@@ -126,7 +126,7 @@ public class MenuBarItem : MenuItem
 
     private void SetInitialProperties (string title, object children, MenuItem parent = null, bool isTopLevel = false)
     {
-        if (!isTopLevel && children == null)
+        if (!isTopLevel && children is null)
         {
             throw new ArgumentNullException (
                                              nameof (children),
@@ -136,7 +136,7 @@ public class MenuBarItem : MenuItem
 
         SetTitle (title ?? "");
 
-        if (parent != null)
+        if (parent is { })
         {
             Parent = parent;
         }
@@ -345,7 +345,7 @@ public class MenuBar : View
         {
             _menus = value;
 
-            if (Menus == null)
+            if (Menus is null)
             {
                 return;
             }
@@ -353,7 +353,7 @@ public class MenuBar : View
             // TODO: Bindings (esp for hotkey) should be added across and then down. This currently does down then across. 
             // TODO: As a result, _File._Save will have precedence over in "_File _Edit _ScrollbarView"
             // TODO: Also: Hotkeys should not work for sub-menus if they are not visible!
-            foreach (MenuBarItem menuBarItem in Menus?.Where (m => m != null)!)
+            foreach (MenuBarItem menuBarItem in Menus?.Where (m => m is { })!)
             {
                 if (menuBarItem.HotKey != default (Rune))
                 {
@@ -381,7 +381,7 @@ public class MenuBar : View
             // Enable the Alt key as a menu activator
             Initialized += (s, e) =>
                            {
-                               if (SuperView != null)
+                               if (SuperView is { })
                                {
                                    SuperView.KeyUp += SuperView_KeyUp;
                                }
@@ -445,7 +445,7 @@ public class MenuBar : View
             {
                 _ocm = value;
 
-                if (_ocm != null && _ocm._currentChild > -1)
+                if (_ocm is { } && _ocm._currentChild > -1)
                 {
                     OnMenuOpened ();
                 }
@@ -575,12 +575,12 @@ public class MenuBar : View
     {
         MenuBar mbar = GetMouseGrabViewInstance (this);
 
-        if (mbar != null)
+        if (mbar is { })
         {
             mbar.CleanUp ();
         }
 
-        if (!Enabled || _openMenu != null)
+        if (!Enabled || _openMenu is { })
         {
             return;
         }
@@ -588,7 +588,7 @@ public class MenuBar : View
         _selected = 0;
         SetNeedsDisplay ();
 
-        _previousFocused = SuperView == null ? Application.Current.Focused : SuperView.Focused;
+        _previousFocused = SuperView is null ? Application.Current.Focused : SuperView.Focused;
         OpenMenu (_selected);
 
         if (!SelectEnabledItem (
@@ -645,9 +645,9 @@ public class MenuBar : View
         _selected = idx;
         _selectedSub = sIdx;
 
-        if (_openMenu == null)
+        if (_openMenu is null)
         {
-            _previousFocused = SuperView == null ? Application.Current?.Focused ?? null : SuperView.Focused;
+            _previousFocused = SuperView is null ? Application.Current?.Focused ?? null : SuperView.Focused;
         }
 
         OpenMenu (idx, sIdx, subMenu);
@@ -661,7 +661,7 @@ public class MenuBar : View
             e.Handled = true;
 
             // User pressed Alt 
-            if (!IsMenuOpen && _openMenu == null && !_openedByAltKey)
+            if (!IsMenuOpen && _openMenu is null && !_openedByAltKey)
             {
                 // There's no open menu, the first menu item should be highlighted.
                 // The right way to do this is to SetFocus(MenuBar), but for some reason
@@ -698,7 +698,7 @@ public class MenuBar : View
     {
         _isCleaning = true;
 
-        if (_openMenu != null)
+        if (_openMenu is { })
         {
             CloseAllMenus ();
         }
@@ -709,7 +709,7 @@ public class MenuBar : View
         _selected = -1;
         CanFocus = _initialCanFocus;
 
-        if (_lastFocused != null)
+        if (_lastFocused is { })
         {
             _lastFocused.SetFocus ();
         }
@@ -723,7 +723,7 @@ public class MenuBar : View
     {
         if (!_isMenuOpening && !_isMenuClosing)
         {
-            if (_openSubMenu != null && !CloseMenu (false, true, true))
+            if (_openSubMenu is { } && !CloseMenu (false, true, true))
             {
                 return;
             }
@@ -733,7 +733,7 @@ public class MenuBar : View
                 return;
             }
 
-            if (LastFocused != null && LastFocused != this)
+            if (LastFocused is { } && LastFocused != this)
             {
                 _selected = -1;
             }
@@ -741,7 +741,7 @@ public class MenuBar : View
             Application.UngrabMouse ();
         }
 
-        if (openCurrentMenu != null)
+        if (openCurrentMenu is { })
         {
             openCurrentMenu = null;
         }
@@ -756,7 +756,7 @@ public class MenuBar : View
     {
         MenuBarItem mbi = isSubMenu ? openCurrentMenu.BarItems : _openMenu?.BarItems;
 
-        if (UseSubMenusSingleFrame && mbi != null && !ignoreUseSubMenusSingleFrame && mbi.Parent != null)
+        if (UseSubMenusSingleFrame && mbi is { } && !ignoreUseSubMenusSingleFrame && mbi.Parent is { })
         {
             return false;
         }
@@ -769,7 +769,7 @@ public class MenuBar : View
         {
             _isMenuClosing = false;
 
-            if (args.CurrentMenu.Parent != null)
+            if (args.CurrentMenu.Parent is { })
             {
                 _openMenu._currentChild =
                     ((MenuBarItem)args.CurrentMenu.Parent).Children.IndexOf (args.CurrentMenu);
@@ -781,14 +781,14 @@ public class MenuBar : View
         switch (isSubMenu)
         {
             case false:
-                if (_openMenu != null)
+                if (_openMenu is { })
                 {
                     Application.Current.Remove (_openMenu);
                 }
 
                 SetNeedsDisplay ();
 
-                if (_previousFocused != null && _previousFocused is Menu && _openMenu != null && _previousFocused.ToString () != openCurrentMenu.ToString ())
+                if (_previousFocused is { } && _previousFocused is Menu && _openMenu is { } && _previousFocused.ToString () != openCurrentMenu.ToString ())
                 {
                     _previousFocused.SetFocus ();
                 }
@@ -804,19 +804,19 @@ public class MenuBar : View
                 LastFocused = _lastFocused;
                 _lastFocused = null;
 
-                if (LastFocused != null && LastFocused.CanFocus)
+                if (LastFocused is { } && LastFocused.CanFocus)
                 {
                     if (!reopen)
                     {
                         _selected = -1;
                     }
 
-                    if (_openSubMenu != null)
+                    if (_openSubMenu is { })
                     {
                         _openSubMenu = null;
                     }
 
-                    if (openCurrentMenu != null)
+                    if (openCurrentMenu is { })
                     {
                         Application.Current.Remove (openCurrentMenu);
                         openCurrentMenu.Dispose ();
@@ -825,7 +825,7 @@ public class MenuBar : View
 
                     LastFocused.SetFocus ();
                 }
-                else if (_openSubMenu == null || _openSubMenu.Count == 0)
+                else if (_openSubMenu is null || _openSubMenu.Count == 0)
                 {
                     CloseAllMenus ();
                 }
@@ -860,13 +860,13 @@ public class MenuBar : View
     /// <returns>The location offset.</returns>
     internal Point GetScreenOffset ()
     {
-        if (Driver == null)
+        if (Driver is null)
         {
             return Point.Empty;
         }
 
-        Rect superViewFrame = SuperView == null ? Driver.Bounds : SuperView.Frame;
-        View sv = SuperView == null ? Application.Current : SuperView;
+        Rect superViewFrame = SuperView is null ? Driver.Bounds : SuperView.Frame;
+        View sv = SuperView is null ? Application.Current : SuperView;
         Point boundsOffset = sv.GetBoundsOffset ();
 
         return new Point (
@@ -937,9 +937,9 @@ public class MenuBar : View
                                                                                  )
                                               : null;
 
-                    if ((_selectedSub == -1 || _openSubMenu == null || _openSubMenu?.Count - 1 == _selectedSub) && subMenu == null)
+                    if ((_selectedSub == -1 || _openSubMenu is null || _openSubMenu?.Count - 1 == _selectedSub) && subMenu is null)
                     {
-                        if (_openSubMenu != null && !CloseMenu (false, true))
+                        if (_openSubMenu is { } && !CloseMenu (false, true))
                         {
                             return;
                         }
@@ -989,7 +989,7 @@ public class MenuBar : View
             return;
         }
 
-        if (newMenu.NewMenuBarItem != null)
+        if (newMenu.NewMenuBarItem is { })
         {
             Menus [index] = newMenu.NewMenuBarItem;
         }
@@ -1000,14 +1000,14 @@ public class MenuBar : View
         {
             case null:
                 // Open a submenu below a MenuBar
-                _lastFocused ??= SuperView == null ? Application.Current?.MostFocused : SuperView.MostFocused;
+                _lastFocused ??= SuperView is null ? Application.Current?.MostFocused : SuperView.MostFocused;
 
-                if (_openSubMenu != null && !CloseMenu (false, true))
+                if (_openSubMenu is { } && !CloseMenu (false, true))
                 {
                     return;
                 }
 
-                if (_openMenu != null)
+                if (_openMenu is { })
                 {
                     Application.Current.Remove (_openMenu);
                     _openMenu.Dispose ();
@@ -1024,12 +1024,12 @@ public class MenuBar : View
                 var locationOffset = Point.Empty;
 
                 // if SuperView is null then it's from a ContextMenu
-                if (SuperView == null)
+                if (SuperView is null)
                 {
                     locationOffset = GetScreenOffset ();
                 }
 
-                if (SuperView != null && SuperView != Application.Current)
+                if (SuperView is { } && SuperView != Application.Current)
                 {
                     locationOffset.X += SuperView.Border.Thickness.Left;
                     locationOffset.Y += SuperView.Border.Thickness.Top;
@@ -1052,7 +1052,7 @@ public class MenuBar : View
                 break;
             default:
                 // Opens a submenu next to another submenu (openSubMenu)
-                if (_openSubMenu == null)
+                if (_openSubMenu is null)
                 {
                     _openSubMenu = new List<Menu> ();
                 }
@@ -1176,7 +1176,7 @@ public class MenuBar : View
 
     internal void RemoveAllOpensSubMenus ()
     {
-        if (_openSubMenu != null)
+        if (_openSubMenu is { })
         {
             foreach (Menu item in _openSubMenu)
             {
@@ -1188,7 +1188,7 @@ public class MenuBar : View
 
     internal bool Run (Action action)
     {
-        if (action == null)
+        if (action is null)
         {
             return false;
         }
@@ -1212,7 +1212,7 @@ public class MenuBar : View
         bool forward = true
     )
     {
-        if (chldren == null)
+        if (chldren is null)
         {
             newCurrent = -1;
 
@@ -1258,7 +1258,7 @@ public class MenuBar : View
                 }
             }
 
-            if (child == null || !child.IsEnabled ())
+            if (child is null || !child.IsEnabled ())
             {
                 if (forward)
                 {
@@ -1286,7 +1286,7 @@ public class MenuBar : View
     /// <param name="item"></param>
     internal bool SelectItem (MenuItem item)
     {
-        if (item?.Action == null)
+        if (item?.Action is null)
         {
             return false;
         }
@@ -1422,7 +1422,7 @@ public class MenuBar : View
             openCurrentMenu = menu;
             openCurrentMenu.SetFocus ();
 
-            if (_openSubMenu != null)
+            if (_openSubMenu is { })
             {
                 menu = _openSubMenu [i];
                 Application.Current.Remove (menu);
@@ -1534,13 +1534,13 @@ public class MenuBar : View
         {
             Activate (_menuBarItemToActivate);
         }
-        else if (_menuItemToSelect != null)
+        else if (_menuItemToSelect is { })
         {
             Run (_menuItemToSelect.Action);
         }
         else
         {
-            if (IsMenuOpen && _openMenu != null)
+            if (IsMenuOpen && _openMenu is { })
             {
                 CloseAllMenus ();
             }
@@ -1636,7 +1636,7 @@ public class MenuBar : View
     {
         menuItemToSelect = null;
 
-        if (key == KeyCode.Null || menuBarItem?.Children == null)
+        if (key == KeyCode.Null || menuBarItem?.Children is null)
         {
             return false;
         }
@@ -1654,7 +1654,7 @@ public class MenuBar : View
 
             MenuBarItem subMenu = menuBarItem.SubMenu (menuItem);
 
-            if (subMenu != null)
+            if (subMenu is { })
             {
                 if (FindShortcutInChildMenu (key, subMenu, out menuItemToSelect))
                 {
@@ -1681,7 +1681,7 @@ public class MenuBar : View
     /// <inheritdoc/>
     public override bool OnLeave (View view)
     {
-        if (((!(view is MenuBar) && !(view is Menu)) || (!(view is MenuBar) && !(view is Menu) && _openMenu != null)) && !_isCleaning && !_reopen)
+        if (((!(view is MenuBar) && !(view is Menu)) || (!(view is MenuBar) && !(view is Menu) && _openMenu is { })) && !_isCleaning && !_reopen)
         {
             CleanUp ();
         }
@@ -1709,7 +1709,7 @@ public class MenuBar : View
             int pos = _xOrigin;
             Point locationOffset = default;
 
-            if (SuperView != null)
+            if (SuperView is { })
             {
                 locationOffset.X += SuperView.Border.Thickness.Left;
                 locationOffset.Y += SuperView.Border.Thickness.Top;
@@ -1801,13 +1801,13 @@ public class MenuBar : View
 
     internal bool HandleGrabView (MouseEvent me, View current)
     {
-        if (Application.MouseGrabView != null)
+        if (Application.MouseGrabView is { })
         {
             if (me.View is MenuBar || me.View is Menu)
             {
                 MenuBar mbar = GetMouseGrabViewInstance (me.View);
 
-                if (mbar != null)
+                if (mbar is { })
                 {
                     if (me.Flags == MouseFlags.Button1Clicked)
                     {
@@ -1905,7 +1905,7 @@ public class MenuBar : View
 
     private MenuBar GetMouseGrabViewInstance (View view)
     {
-        if (view == null || Application.MouseGrabView == null)
+        if (view is null || Application.MouseGrabView is null)
         {
             return null;
         }

+ 1 - 1
Terminal.Gui/Views/MessageBox.cs

@@ -316,7 +316,7 @@ public static class MessageBox
         var count = 0;
         List<Button> buttonList = new ();
 
-        if (buttons != null)
+        if (buttons is { })
         {
             if (defaultButton > buttons.Length - 1)
             {

+ 1 - 1
Terminal.Gui/Views/ProgressBar.cs

@@ -213,7 +213,7 @@ public class ProgressBar : View
     /// </remarks>
     public void Pulse ()
     {
-        if (_activityPos == null || _activityPos.Length == 0)
+        if (_activityPos is null || _activityPos.Length == 0)
         {
             PopulateActivityPos ();
         }

+ 1 - 1
Terminal.Gui/Views/RadioGroup.cs

@@ -400,7 +400,7 @@ public class RadioGroup : View
 
     private static Rect MakeRect (int x, int y, List<string> radioLabels)
     {
-        if (radioLabels == null)
+        if (radioLabels is null)
         {
             return new Rect (x, y, 0, 0);
         }

+ 30 - 30
Terminal.Gui/Views/ScrollBarView.cs

@@ -57,12 +57,12 @@ public class ScrollBarView : View
     /// </param>
     public ScrollBarView (View host, bool isVertical, bool showBothScrollIndicator = true)
     {
-        if (host == null)
+        if (host is null)
         {
             throw new ArgumentNullException ("The host parameter can't be null.");
         }
 
-        if (host.SuperView == null)
+        if (host.SuperView is null)
         {
             throw new ArgumentNullException ("The host SuperView parameter can't be null.");
         }
@@ -167,7 +167,7 @@ public class ScrollBarView : View
                     Position = pos;
                 }
 
-                if (OtherScrollBarView != null && OtherScrollBarView._keepContentAlwaysInViewport != value)
+                if (OtherScrollBarView is { } && OtherScrollBarView._keepContentAlwaysInViewport != value)
                 {
                     OtherScrollBarView.KeepContentAlwaysInViewport = value;
                 }
@@ -186,7 +186,7 @@ public class ScrollBarView : View
         get => _otherScrollBarView;
         set
         {
-            if (value != null && ((value.IsVertical && _vertical) || (!value.IsVertical && !_vertical)))
+            if (value is { } && ((value.IsVertical && _vertical) || (!value.IsVertical && !_vertical)))
             {
                 throw new ArgumentException (
                                              $"There is already a {(_vertical ? "vertical" : "horizontal")} ScrollBarView."
@@ -307,11 +307,11 @@ public class ScrollBarView : View
         barsize -= 2;
         int pos = Position;
 
-        if (mouseEvent.Flags != MouseFlags.Button1Released && (Application.MouseGrabView == null || Application.MouseGrabView != this))
+        if (mouseEvent.Flags != MouseFlags.Button1Released && (Application.MouseGrabView is null || Application.MouseGrabView != this))
         {
             Application.GrabMouse (this);
         }
-        else if (mouseEvent.Flags == MouseFlags.Button1Released && Application.MouseGrabView != null && Application.MouseGrabView == this)
+        else if (mouseEvent.Flags == MouseFlags.Button1Released && Application.MouseGrabView is { } && Application.MouseGrabView == this)
         {
             _lastLocation = -1;
             Application.UngrabMouse ();
@@ -451,7 +451,7 @@ public class ScrollBarView : View
     /// <inheritdoc/>
     public override void OnDrawContent (Rect contentArea)
     {
-        if (ColorScheme == null || ((!_showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible))
+        if (ColorScheme is null || ((!_showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible))
         {
             if ((!_showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible)
             {
@@ -720,7 +720,7 @@ public class ScrollBarView : View
                 scrollBarView.Visible = false;
             }
         }
-        else if (barsize > 0 && barsize == scrollBarView._size && scrollBarView.OtherScrollBarView != null && pending)
+        else if (barsize > 0 && barsize == scrollBarView._size && scrollBarView.OtherScrollBarView is { } && pending)
         {
             if (scrollBarView._showScrollIndicator)
             {
@@ -732,7 +732,7 @@ public class ScrollBarView : View
                 scrollBarView.Visible = false;
             }
 
-            if (scrollBarView.OtherScrollBarView != null && scrollBarView._showBothScrollIndicator)
+            if (scrollBarView.OtherScrollBarView is { } && scrollBarView._showBothScrollIndicator)
             {
                 scrollBarView.OtherScrollBarView.ShowScrollIndicator = false;
             }
@@ -742,13 +742,13 @@ public class ScrollBarView : View
                 scrollBarView.OtherScrollBarView.Visible = false;
             }
         }
-        else if (barsize > 0 && barsize == _size && scrollBarView.OtherScrollBarView != null && !pending)
+        else if (barsize > 0 && barsize == _size && scrollBarView.OtherScrollBarView is { } && !pending)
         {
             pending = true;
         }
         else
         {
-            if (scrollBarView.OtherScrollBarView != null && pending)
+            if (scrollBarView.OtherScrollBarView is { } && pending)
             {
                 if (!scrollBarView._showBothScrollIndicator)
                 {
@@ -788,7 +788,7 @@ public class ScrollBarView : View
     //private void Host_CanFocusChanged ()
     //{
     //	CanFocus = Host.CanFocus;
-    //	if (otherScrollBarView != null) {
+    //	if (otherScrollBarView is { }) {
     //		otherScrollBarView.CanFocus = CanFocus;
     //	}
     //}
@@ -818,8 +818,8 @@ public class ScrollBarView : View
         }
 
         if (Host != null
-            && ((_contentBottomRightCorner == null && OtherScrollBarView == null)
-                || (_contentBottomRightCorner == null && OtherScrollBarView != null && OtherScrollBarView._contentBottomRightCorner == null)))
+            && ((_contentBottomRightCorner is null && OtherScrollBarView is null)
+                || (_contentBottomRightCorner is null && OtherScrollBarView is { } && OtherScrollBarView._contentBottomRightCorner is null)))
         {
             _contentBottomRightCorner = new ContentBottomRightCorner { Visible = Host.Visible };
 
@@ -860,7 +860,7 @@ public class ScrollBarView : View
     {
         Enabled = Host.Enabled;
 
-        if (_otherScrollBarView != null)
+        if (_otherScrollBarView is { })
         {
             _otherScrollBarView.Enabled = Enabled;
         }
@@ -874,7 +874,7 @@ public class ScrollBarView : View
         {
             Visible = Host.Visible;
 
-            if (_otherScrollBarView != null)
+            if (_otherScrollBarView is { })
             {
                 _otherScrollBarView.Visible = Visible;
             }
@@ -892,7 +892,7 @@ public class ScrollBarView : View
         SetWidthHeight ();
         SetRelativeLayout (SuperView?.Frame ?? Host?.Frame ?? Frame);
 
-        if (OtherScrollBarView == null)
+        if (OtherScrollBarView is null)
         {
             // Only do this once if both scrollbars are enabled
             ShowHideScrollBars ();
@@ -973,7 +973,7 @@ public class ScrollBarView : View
     {
         if (!_hosted || (_hosted && !_autoHideScrollBars))
         {
-            if (_contentBottomRightCorner != null && _contentBottomRightCorner.Visible)
+            if (_contentBottomRightCorner is { } && _contentBottomRightCorner.Visible)
             {
                 _contentBottomRightCorner.Visible = false;
             }
@@ -989,7 +989,7 @@ public class ScrollBarView : View
 
         bool pending = CheckBothScrollBars (this);
 
-        if (_otherScrollBarView != null)
+        if (_otherScrollBarView is { })
         {
             CheckBothScrollBars (_otherScrollBarView, pending);
         }
@@ -997,43 +997,43 @@ public class ScrollBarView : View
         SetWidthHeight ();
         SetRelativeLayout (SuperView?.Frame ?? Host.Frame);
 
-        if (_otherScrollBarView != null)
+        if (_otherScrollBarView is { })
         {
             OtherScrollBarView.SetRelativeLayout (SuperView?.Frame ?? Host.Frame);
         }
 
         if (_showBothScrollIndicator)
         {
-            if (_contentBottomRightCorner != null)
+            if (_contentBottomRightCorner is { })
             {
                 _contentBottomRightCorner.Visible = true;
             }
-            else if (_otherScrollBarView != null && _otherScrollBarView._contentBottomRightCorner != null)
+            else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { })
             {
                 _otherScrollBarView._contentBottomRightCorner.Visible = true;
             }
         }
         else if (!_showScrollIndicator)
         {
-            if (_contentBottomRightCorner != null)
+            if (_contentBottomRightCorner is { })
             {
                 _contentBottomRightCorner.Visible = false;
             }
-            else if (_otherScrollBarView != null && _otherScrollBarView._contentBottomRightCorner != null)
+            else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { })
             {
                 _otherScrollBarView._contentBottomRightCorner.Visible = false;
             }
 
-            if (Application.MouseGrabView != null && Application.MouseGrabView == this)
+            if (Application.MouseGrabView is { } && Application.MouseGrabView == this)
             {
                 Application.UngrabMouse ();
             }
         }
-        else if (_contentBottomRightCorner != null)
+        else if (_contentBottomRightCorner is { })
         {
             _contentBottomRightCorner.Visible = false;
         }
-        else if (_otherScrollBarView != null && _otherScrollBarView._contentBottomRightCorner != null)
+        else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { })
         {
             _otherScrollBarView._contentBottomRightCorner.Visible = false;
         }
@@ -1058,16 +1058,16 @@ public class ScrollBarView : View
             Draw ();
         }
 
-        if (_otherScrollBarView != null && _otherScrollBarView._showScrollIndicator)
+        if (_otherScrollBarView is { } && _otherScrollBarView._showScrollIndicator)
         {
             _otherScrollBarView.Draw ();
         }
 
-        if (_contentBottomRightCorner != null && _contentBottomRightCorner.Visible)
+        if (_contentBottomRightCorner is { } && _contentBottomRightCorner.Visible)
         {
             _contentBottomRightCorner.Draw ();
         }
-        else if (_otherScrollBarView != null && _otherScrollBarView._contentBottomRightCorner != null && _otherScrollBarView._contentBottomRightCorner.Visible)
+        else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { } && _otherScrollBarView._contentBottomRightCorner.Visible)
         {
             _otherScrollBarView._contentBottomRightCorner.Draw ();
         }

+ 3 - 3
Terminal.Gui/Views/ScrollView.cs

@@ -420,7 +420,7 @@ public class ScrollView : View
 
         bool? result = InvokeKeyBindings (a);
 
-        if (result != null)
+        if (result is { })
         {
             return (bool)result;
         }
@@ -445,7 +445,7 @@ public class ScrollView : View
     /// <param name="view">The view to remove from the scrollview.</param>
     public override void Remove (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return;
         }
@@ -728,7 +728,7 @@ public class ScrollView : View
 
     private void View_MouseLeave (object sender, MouseEventEventArgs e)
     {
-        if (Application.MouseGrabView != null && Application.MouseGrabView != _vertical && Application.MouseGrabView != _horizontal)
+        if (Application.MouseGrabView is { } && Application.MouseGrabView != _vertical && Application.MouseGrabView != _horizontal)
         {
             Application.UngrabMouse ();
         }

+ 4 - 4
Terminal.Gui/Views/Slider.cs

@@ -327,7 +327,7 @@ public class Slider<T> : View
     /// <param name="orientation">Initial slider orientation.</param>
     public Slider (List<T> options, Orientation orientation = Orientation.Horizontal)
     {
-        if (options == null)
+        if (options is null)
         {
             SetInitialProperties (null, orientation);
         }
@@ -664,7 +664,7 @@ public class Slider<T> : View
         if (AutoSize)
         {
             // Max size is SuperView's Bounds. Min Size is size that will fit.
-            if (SuperView != null)
+            if (SuperView is { })
             {
                 // Calculate the size of the slider based on the size of the SuperView's Bounds.
                 if (_config._sliderOrientation == Orientation.Horizontal)
@@ -998,7 +998,7 @@ public class Slider<T> : View
     {
         // TODO: make this more surgical to reduce repaint
 
-        if (_options == null && _options.Count > 0)
+        if (_options is null && _options.Count > 0)
         {
             return;
         }
@@ -1033,7 +1033,7 @@ public class Slider<T> : View
 
     private string AlignText (string text, int width, TextAlignment textAlignment)
     {
-        if (text == null)
+        if (text is null)
         {
             return "";
         }

+ 2 - 2
Terminal.Gui/Views/SpinnerView/SpinnerView.cs

@@ -189,7 +189,7 @@ public class SpinnerView : View
 
     private void AddAutoSpinTimeout ()
     {
-        if (_timeout != null)
+        if (_timeout is { })
         {
             return;
         }
@@ -251,7 +251,7 @@ public class SpinnerView : View
 
     private void RemoveAutoSpinTimeout ()
     {
-        if (_timeout != null)
+        if (_timeout is { })
         {
             Application.RemoveTimeout (_timeout);
             _timeout = null;

+ 3 - 3
Terminal.Gui/Views/StatusBar.cs

@@ -83,7 +83,7 @@ public class StatusBar : View
     /// <param name="items">A list of status bar items.</param>
     public StatusBar (StatusItem [] items)
     {
-        if (items != null)
+        if (items is { })
         {
             Items = items;
         }
@@ -265,7 +265,7 @@ public class StatusBar : View
 
     private Attribute DetermineColorSchemeFor (StatusItem item)
     {
-        if (item != null)
+        if (item is { })
         {
             if (item.IsEnabled ())
             {
@@ -309,7 +309,7 @@ public class StatusBar : View
 
     private void Run (Action action)
     {
-        if (action == null)
+        if (action is null)
         {
             return;
         }

+ 17 - 17
Terminal.Gui/Views/TabView.cs

@@ -151,9 +151,9 @@ public class TabView : View
 
             Tab old = _selectedTab;
 
-            if (_selectedTab != null)
+            if (_selectedTab is { })
             {
-                if (_selectedTab.View != null)
+                if (_selectedTab.View is { })
                 {
                     // remove old content
                     _contentView.Remove (_selectedTab.View);
@@ -162,10 +162,10 @@ public class TabView : View
 
             _selectedTab = value;
 
-            if (value != null)
+            if (value is { })
             {
                 // add new content
-                if (_selectedTab.View != null)
+                if (_selectedTab.View is { })
                 {
                     _contentView.Add (_selectedTab.View);
                 }
@@ -214,7 +214,7 @@ public class TabView : View
         _tabs.Add (tab);
         _tabsBar.Add (tab);
 
-        if (SelectedTab == null || andSelect)
+        if (SelectedTab is null || andSelect)
         {
             SelectedTab = tab;
 
@@ -291,7 +291,7 @@ public class TabView : View
     /// <summary>Updates <see cref="TabScrollOffset"/> to ensure that <see cref="SelectedTab"/> is visible.</summary>
     public void EnsureSelectedTabIsVisible ()
     {
-        if (!IsInitialized || SelectedTab == null)
+        if (!IsInitialized || SelectedTab is null)
         {
             return;
         }
@@ -335,7 +335,7 @@ public class TabView : View
     /// <param name="tab"></param>
     public void RemoveTab (Tab tab)
     {
-        if (tab == null || !_tabs.Contains (tab))
+        if (tab is null || !_tabs.Contains (tab))
         {
             return;
         }
@@ -346,7 +346,7 @@ public class TabView : View
         _tabs.Remove (tab);
 
         // if the currently selected tab is no longer a member of Tabs
-        if (SelectedTab == null || !Tabs.Contains (SelectedTab))
+        if (SelectedTab is null || !Tabs.Contains (SelectedTab))
         {
             // select the tab closest to the one that disappeared
             int toSelect = Math.Max (idx - 1, 0);
@@ -381,7 +381,7 @@ public class TabView : View
         }
 
         // if there is only one tab anyway or nothing is selected
-        if (Tabs.Count == 1 || SelectedTab == null)
+        if (Tabs.Count == 1 || SelectedTab is null)
         {
             SelectedTab = Tabs.ElementAt (0);
             SetNeedsDisplay ();
@@ -447,7 +447,7 @@ public class TabView : View
         // Starting at the first or scrolled to tab
         foreach (Tab tab in Tabs.Skip (TabScrollOffset))
         {
-            if (prevTab != null)
+            if (prevTab is { })
             {
                 tab.X = Pos.Right (prevTab);
             }
@@ -537,7 +537,7 @@ public class TabView : View
 
     private void UnSetCurrentTabs ()
     {
-        if (_tabLocations != null)
+        if (_tabLocations is { })
         {
             foreach (TabToRender tabToRender in _tabLocations)
             {
@@ -627,11 +627,11 @@ public class TabView : View
             {
                 var scrollIndicatorHit = 0;
 
-                if (me.View != null && me.View.Id == "rightScrollIndicator")
+                if (me.View is { } && me.View.Id == "rightScrollIndicator")
                 {
                     scrollIndicatorHit = 1;
                 }
-                else if (me.View != null && me.View.Id == "leftScrollIndicator")
+                else if (me.View is { } && me.View.Id == "leftScrollIndicator")
                 {
                     scrollIndicatorHit = -1;
                 }
@@ -645,7 +645,7 @@ public class TabView : View
                     return true;
                 }
 
-                if (hit != null)
+                if (hit is { })
                 {
                     _host.SelectedTab = hit;
                     SetNeedsDisplay ();
@@ -672,7 +672,7 @@ public class TabView : View
 
         public override void OnDrawContentComplete (Rect contentArea)
         {
-            if (_host._tabLocations == null)
+            if (_host._tabLocations is null)
             {
                 return;
             }
@@ -1259,7 +1259,7 @@ public class TabView : View
                         tab.Margin.Thickness = new Thickness (0, 0, 0, topLine);
                     }
                 }
-                else if (selected == null)
+                else if (selected is null)
                 {
                     if (_host.Style.TabsOnBottom)
                     {
@@ -1332,7 +1332,7 @@ public class TabView : View
 
             TabToRender selected = _host._tabLocations.FirstOrDefault (t => t.IsSelected);
 
-            if (selected == null)
+            if (selected is null)
             {
                 return;
             }

+ 2 - 2
Terminal.Gui/Views/TableView/ColumnStyle.cs

@@ -76,7 +76,7 @@ public class ColumnStyle
     /// <returns></returns>
     public TextAlignment GetAlignment (object cellValue)
     {
-        if (AlignmentGetter != null)
+        if (AlignmentGetter is { })
         {
             return AlignmentGetter (cellValue);
         }
@@ -100,7 +100,7 @@ public class ColumnStyle
             }
         }
 
-        if (RepresentationGetter != null)
+        if (RepresentationGetter is { })
         {
             return RepresentationGetter (value);
         }

+ 1 - 1
Terminal.Gui/Views/TableView/ListTableSource.cs

@@ -124,7 +124,7 @@ public class ListTableSource : ITableSource
     /// <returns></returns>
     private int CalculateMaxLength ()
     {
-        if (List == null || Count == 0)
+        if (List is null || Count == 0)
         {
             return 0;
         }

+ 12 - 12
Terminal.Gui/Views/TableView/TableView.cs

@@ -489,7 +489,7 @@ public class TableView : View
         ColumnToRender colHit = viewPort.FirstOrDefault (c => c.Column == tableColumn);
 
         // current column is outside the scroll area
-        if (colHit == null)
+        if (colHit is null)
         {
             return null;
         }
@@ -571,7 +571,7 @@ public class TableView : View
     /// </remarks>
     public void EnsureSelectedCellIsVisible ()
     {
-        if (Table == null || Table.Columns <= 0)
+        if (Table is null || Table.Columns <= 0)
         {
             return;
         }
@@ -865,7 +865,7 @@ public class TableView : View
 
             Point? hit = ScreenToCell (boundsX, boundsY);
 
-            if (hit != null)
+            if (hit is { })
             {
                 if (MultiSelect && HasControlOrAlt (me))
                 {
@@ -885,7 +885,7 @@ public class TableView : View
         {
             Point? hit = ScreenToCell (boundsX, boundsY);
 
-            if (hit != null)
+            if (hit is { })
             {
                 OnCellActivated (new CellActivatedEventArgs (Table, hit.Value.X, hit.Value.Y));
             }
@@ -1027,7 +1027,7 @@ public class TableView : View
 
         Point? screenPoint = CellToScreen (SelectedColumn, SelectedRow);
 
-        if (screenPoint != null)
+        if (screenPoint is { })
         {
             Move (screenPoint.Value.X, screenPoint.Value.Y);
         }
@@ -1082,7 +1082,7 @@ public class TableView : View
         if (clientY < headerHeight)
         {
             headerIfAny = col?.Column;
-            offsetX = col != null ? clientX - col.X : null;
+            offsetX = col is { } ? clientX - col.X : null;
 
             return null;
         }
@@ -1096,7 +1096,7 @@ public class TableView : View
             return null;
         }
 
-        if (col != null && rowIdx >= 0)
+        if (col is { } && rowIdx >= 0)
         {
             offsetX = clientX - col.X;
 
@@ -1303,7 +1303,7 @@ public class TableView : View
         }
 
         // Don't require more space than the style allows
-        if (colStyle != null)
+        if (colStyle is { })
         {
             // enforce maximum cell width based on style
             if (spaceRequired > colStyle.MaxWidth)
@@ -1586,12 +1586,12 @@ public class TableView : View
     /// <returns></returns>
     private string GetRepresentation (object value, ColumnStyle colStyle)
     {
-        if (value == null || value == DBNull.Value)
+        if (value is null || value == DBNull.Value)
         {
             return NullSymbol;
         }
 
-        return colStyle != null ? colStyle.GetRepresentation (value) : value.ToString ();
+        return colStyle is { } ? colStyle.GetRepresentation (value) : value.ToString ();
     }
 
     private bool HasControlOrAlt (MouseEvent me) { return me.Flags.HasFlag (MouseFlags.ButtonAlt) || me.Flags.HasFlag (MouseFlags.ButtonCtrl); }
@@ -1870,7 +1870,7 @@ public class TableView : View
 
             ColorScheme scheme;
 
-            if (colorSchemeGetter != null)
+            if (colorSchemeGetter is { })
             {
                 // user has a delegate for defining row color per cell, call it
                 scheme = colorSchemeGetter (
@@ -1885,7 +1885,7 @@ public class TableView : View
                                            );
 
                 // if users custom color getter returned null, use the row scheme
-                if (scheme == null)
+                if (scheme is null)
                 {
                     scheme = rowScheme;
                 }

+ 2 - 2
Terminal.Gui/Views/TableView/TreeTableSource.cs

@@ -136,7 +136,7 @@ public class TreeTableSource<T> : IEnumerableTableSource<T>, IDisposable where T
 
         T obj = _tree.GetObjectOnRow (_tableView.SelectedRow);
 
-        if (obj == null)
+        if (obj is null)
         {
             return;
         }
@@ -170,7 +170,7 @@ public class TreeTableSource<T> : IEnumerableTableSource<T>, IDisposable where T
     {
         Point? hit = _tableView.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out int? headerIfAny, out int? offsetX);
 
-        if (hit == null || headerIfAny != null || !IsInTreeColumn (hit.Value.X, false) || offsetX == null)
+        if (hit is null || headerIfAny is { } || !IsInTreeColumn (hit.Value.X, false) || offsetX is null)
         {
             return;
         }

+ 15 - 15
Terminal.Gui/Views/TextField.cs

@@ -755,7 +755,7 @@ public class TextField : View
     {
         ColorScheme cs = ColorScheme;
 
-        if (ColorScheme == null)
+        if (ColorScheme is null)
         {
             cs = new ColorScheme ();
         }
@@ -796,7 +796,7 @@ public class TextField : View
         ClearAllSelection ();
         (int col, int row)? newPos = GetModel ().WordBackward (_cursorPosition, 0);
 
-        if (newPos == null)
+        if (newPos is null)
         {
             return;
         }
@@ -819,7 +819,7 @@ public class TextField : View
         ClearAllSelection ();
         (int col, int row)? newPos = GetModel ().WordForward (_cursorPosition, 0);
 
-        if (newPos == null)
+        if (newPos is null)
         {
             return;
         }
@@ -883,7 +883,7 @@ public class TextField : View
             _isButtonReleased = false;
             PrepareSelection (x);
 
-            if (Application.MouseGrabView == null)
+            if (Application.MouseGrabView is null)
             {
                 Application.GrabMouse (this);
             }
@@ -906,7 +906,7 @@ public class TextField : View
             {
                 (int col, int row)? newPosBw = GetModel ().WordBackward (x, 0);
 
-                if (newPosBw == null)
+                if (newPosBw is null)
                 {
                     return true;
                 }
@@ -922,7 +922,7 @@ public class TextField : View
 
             (int col, int row)? newPosFw = GetModel ().WordForward (x, 0);
 
-            if (newPosFw == null)
+            if (newPosFw is null)
             {
                 return true;
             }
@@ -1078,7 +1078,7 @@ public class TextField : View
     /// <inheritdoc/>
     public override bool OnLeave (View view)
     {
-        if (Application.MouseGrabView != null && Application.MouseGrabView == this)
+        if (Application.MouseGrabView is { } && Application.MouseGrabView == this)
         {
             Application.UngrabMouse ();
         }
@@ -1232,7 +1232,7 @@ public class TextField : View
         //if (string.IsNullOrEmpty (Clipboard.Contents))
         //	return true;
         //var clip = TextModel.ToRunes (Clipboard.Contents);
-        //if (clip == null)
+        //if (clip is null)
         //	return true;
 
         //if (point == text.Count) {
@@ -1449,7 +1449,7 @@ public class TextField : View
     {
         ColorScheme cs = ColorScheme;
 
-        if (ColorScheme == null)
+        if (ColorScheme is null)
         {
             cs = new ColorScheme ();
         }
@@ -1472,7 +1472,7 @@ public class TextField : View
 
     private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItem obj)
     {
-        if (obj == null)
+        if (obj is null)
         {
             return;
         }
@@ -1663,7 +1663,7 @@ public class TextField : View
         ClearAllSelection ();
         (int col, int row)? newPos = GetModel ().WordBackward (_cursorPosition, 0);
 
-        if (newPos == null)
+        if (newPos is null)
         {
             return;
         }
@@ -1689,7 +1689,7 @@ public class TextField : View
             {
                 (int col, int row)? newPos = GetModel ().WordBackward (x, 0);
 
-                if (newPos == null)
+                if (newPos is null)
                 {
                     return;
                 }
@@ -1709,7 +1709,7 @@ public class TextField : View
         ClearAllSelection ();
         (int col, int row)? newPos = GetModel ().WordForward (_cursorPosition, 0);
 
-        if (newPos == null)
+        if (newPos is null)
         {
             return;
         }
@@ -1729,7 +1729,7 @@ public class TextField : View
             int x = _start > -1 && _start > _cursorPosition ? _start : _cursorPosition;
             (int col, int row)? newPos = GetModel ().WordForward (x, 0);
 
-            if (newPos == null)
+            if (newPos is null)
             {
                 return;
             }
@@ -1840,7 +1840,7 @@ public class TextField : View
 
             SetNeedsDisplay ();
         }
-        else if (SelectedLength > 0 || _selectedText != null)
+        else if (SelectedLength > 0 || _selectedText is { })
         {
             ClearAllSelection ();
         }

+ 6 - 6
Terminal.Gui/Views/TextValidateField.cs

@@ -365,7 +365,7 @@ namespace Terminal.Gui
 
             private void SetupText ()
             {
-                if (_text != null && IsValid)
+                if (_text is { } && IsValid)
                 {
                     return;
                 }
@@ -478,7 +478,7 @@ namespace Terminal.Gui
         {
             get
             {
-                if (_provider == null)
+                if (_provider is null)
                 {
                     return false;
                 }
@@ -512,7 +512,7 @@ namespace Terminal.Gui
         {
             get
             {
-                if (_provider == null)
+                if (_provider is null)
                 {
                     return string.Empty;
                 }
@@ -521,7 +521,7 @@ namespace Terminal.Gui
             }
             set
             {
-                if (_provider == null)
+                if (_provider is null)
                 {
                     return;
                 }
@@ -557,7 +557,7 @@ namespace Terminal.Gui
         /// <inheritdoc/>
         public override void OnDrawContent (Rect contentArea)
         {
-            if (_provider == null)
+            if (_provider is null)
             {
                 Move (0, 0);
                 Driver.AddStr ("Error: ITextValidateProvider not set!");
@@ -617,7 +617,7 @@ namespace Terminal.Gui
         /// <inheritdoc/>
         public override bool OnProcessKeyDown (Key a)
         {
-            if (_provider == null)
+            if (_provider is null)
             {
                 return false;
             }

+ 47 - 47
Terminal.Gui/Views/TextView.cs

@@ -61,7 +61,7 @@ internal class TextModel
 
     public bool CloseFile ()
     {
-        if (FilePath == null)
+        if (FilePath is null)
         {
             throw new ArgumentNullException (nameof (FilePath));
         }
@@ -148,7 +148,7 @@ internal class TextModel
 
     public void LoadStream (Stream input)
     {
-        if (input == null)
+        if (input is null)
         {
             throw new ArgumentNullException (nameof (input));
         }
@@ -296,7 +296,7 @@ internal class TextModel
             RuneCell? cell = RuneAt (col, row);
             Rune rune;
 
-            if (cell != null)
+            if (cell is { })
             {
                 rune = cell.Rune;
             }
@@ -565,7 +565,7 @@ internal class TextModel
     // Returns the left column in a range of the string.
     internal static int CalculateLeftColumn (List<Rune> t, int start, int end, int width, int tabWidth = 0)
     {
-        if (t == null || t.Count == 0)
+        if (t is null || t.Count == 0)
         {
             return 0;
         }
@@ -632,7 +632,7 @@ internal class TextModel
         int tabWidth = 0
     )
     {
-        if (t == null || t.Count == 0)
+        if (t is null || t.Count == 0)
         {
             return (0, 0);
         }
@@ -687,7 +687,7 @@ internal class TextModel
         bool matchWholeWord = false
     )
     {
-        if (text == null || _lines.Count == 0)
+        if (text is null || _lines.Count == 0)
         {
             gaveFullTurn = false;
 
@@ -730,7 +730,7 @@ internal class TextModel
         bool matchWholeWord = false
     )
     {
-        if (text == null || _lines.Count == 0)
+        if (text is null || _lines.Count == 0)
         {
             gaveFullTurn = false;
 
@@ -1328,7 +1328,7 @@ internal partial class HistoryText
     {
         HistoryTextItem? found = _historyTextItems.FindLast (x => x.LineStatus == lineStatus);
 
-        if (found != null)
+        if (found is { })
         {
             found.Lines = lines;
             found.CursorPosition = curPos;
@@ -2744,7 +2744,7 @@ public class TextView : View
 
                 SetNeedsDisplay ();
             }
-            else if (_multiline && _savedHeight != null)
+            else if (_multiline && _savedHeight is { })
             {
                 //var lyout = LayoutStyle;
                 //if (LayoutStyle == LayoutStyle.Computed) {
@@ -2932,7 +2932,7 @@ public class TextView : View
                 _wrapManager = new WordWrapManager (_model);
                 _model = _wrapManager.WrapModel (_frameWidth, out _, out _, out _, out _);
             }
-            else if (!_wordWrap && _wrapManager != null)
+            else if (!_wordWrap && _wrapManager is { })
             {
                 _model = _wrapManager.Model;
             }
@@ -3218,7 +3218,7 @@ public class TextView : View
     {
         ColorScheme? cs = ColorScheme;
 
-        if (ColorScheme == null)
+        if (ColorScheme is null)
         {
             cs = new ColorScheme ();
         }
@@ -3485,7 +3485,7 @@ public class TextView : View
             _lastWasKill = false;
             _columnTrack = CurrentColumn;
 
-            if (Application.MouseGrabView == null)
+            if (Application.MouseGrabView is null)
             {
                 Application.GrabMouse (this);
             }
@@ -3529,7 +3529,7 @@ public class TextView : View
 
             newPos = _model.WordForward (CurrentColumn, CurrentRow);
 
-            if (newPos != null && newPos.HasValue)
+            if (newPos is { } && newPos.HasValue)
             {
                 CurrentColumn = CurrentRow == newPos.Value.row ? newPos.Value.col : line.Count;
             }
@@ -3737,7 +3737,7 @@ public class TextView : View
     /// <inheritdoc/>
     public override bool OnLeave (View view)
     {
-        if (Application.MouseGrabView != null && Application.MouseGrabView == this)
+        if (Application.MouseGrabView is { } && Application.MouseGrabView == this)
         {
             Application.UngrabMouse ();
         }
@@ -3770,10 +3770,10 @@ public class TextView : View
     /// <summary>Invoke the <see cref="UnwrappedCursorPosition"/> event with the unwrapped <see cref="CursorPosition"/>.</summary>
     public virtual void OnUnwrappedCursorPosition (int? cRow = null, int? cCol = null)
     {
-        int? row = cRow == null ? CurrentRow : cRow;
-        int? col = cCol == null ? CurrentColumn : cCol;
+        int? row = cRow is null ? CurrentRow : cRow;
+        int? col = cCol is null ? CurrentColumn : cCol;
 
-        if (cRow == null && cCol == null && _wordWrap)
+        if (cRow is null && cCol is null && _wordWrap)
         {
             row = _wrapManager!.GetModelLineFromWrappedLines (CurrentRow);
             col = _wrapManager.GetModelColFromWrappedLines (CurrentRow, CurrentColumn);
@@ -3795,7 +3795,7 @@ public class TextView : View
 
         if (_copyWithoutSelection && contents.FirstOrDefault (x => x == '\n' || x == '\r') == 0)
         {
-            List<RuneCell> runeList = contents == null ? new List<RuneCell> () : TextModel.ToRuneCellList (contents);
+            List<RuneCell> runeList = contents is null ? new List<RuneCell> () : TextModel.ToRuneCellList (contents);
             List<RuneCell> currentLine = GetCurrentLine ();
 
             _historyText.Add (new List<List<RuneCell>> { new (currentLine) }, CursorPosition);
@@ -3852,7 +3852,7 @@ public class TextView : View
     {
         ProcessAutocomplete ();
 
-        if (!CanFocus || !Enabled || Application.Driver == null)
+        if (!CanFocus || !Enabled || Application.Driver is null)
         {
             return;
         }
@@ -4028,7 +4028,7 @@ public class TextView : View
         var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
         DrawNormalColor?.Invoke (this, ev);
 
-        if (line [idxCol].ColorScheme != null)
+        if (line [idxCol].ColorScheme is { })
         {
             ColorScheme? colorScheme = line [idxCol].ColorScheme;
             Driver.SetAttribute (Enabled ? colorScheme!.Focus : colorScheme!.Disabled);
@@ -4054,7 +4054,7 @@ public class TextView : View
         var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
         DrawReadOnlyColor?.Invoke (this, ev);
 
-        ColorScheme? colorScheme = line [idxCol].ColorScheme != null ? line [idxCol].ColorScheme : ColorScheme;
+        ColorScheme? colorScheme = line [idxCol].ColorScheme is { } ? line [idxCol].ColorScheme : ColorScheme;
         Attribute attribute;
 
         if (colorScheme!.Disabled.Foreground == colorScheme.Focus.Background)
@@ -4084,7 +4084,7 @@ public class TextView : View
         var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
         DrawSelectionColor?.Invoke (this, ev);
 
-        if (line [idxCol].ColorScheme != null)
+        if (line [idxCol].ColorScheme is { })
         {
             ColorScheme? colorScheme = line [idxCol].ColorScheme;
 
@@ -4118,7 +4118,7 @@ public class TextView : View
         var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
         DrawUsedColor?.Invoke (this, ev);
 
-        if (line [idxCol].ColorScheme != null)
+        if (line [idxCol].ColorScheme is { })
         {
             ColorScheme? colorScheme = line [idxCol].ColorScheme;
             SetValidUsedColor (colorScheme!);
@@ -4628,7 +4628,7 @@ public class TextView : View
         long selection;
         long point;
 
-        if (startRow == null || startCol == null || cRow == null || cCol == null)
+        if (startRow is null || startCol is null || cRow is null || cCol is null)
         {
             selection = ((long)(uint)_selectionStartRow << 32) | (uint)_selectionStartColumn;
             point = ((long)(uint)CurrentRow << 32) | (uint)CurrentColumn;
@@ -4675,7 +4675,7 @@ public class TextView : View
         var maxrow = (int)(end >> 32);
         var startCol = (int)(start & 0xffffffff);
         var endCol = (int)(end & 0xffffffff);
-        List<RuneCell> line = model == null ? _model.GetLine (startRow) : model.GetLine (startRow);
+        List<RuneCell> line = model is null ? _model.GetLine (startRow) : model.GetLine (startRow);
 
         if (startRow == maxrow)
         {
@@ -4695,7 +4695,7 @@ public class TextView : View
                                     );
         }
 
-        line = model == null ? _model.GetLine (maxrow) : model.GetLine (maxrow);
+        line = model is null ? _model.GetLine (maxrow) : model.GetLine (maxrow);
         res = res + Environment.NewLine + StringFromRunes (line.GetRange (0, endCol));
 
         return res;
@@ -4742,11 +4742,11 @@ public class TextView : View
     {
         SetWrapModel ();
 
-        if (obj != null)
+        if (obj is { })
         {
             int startLine = obj.CursorPosition.Y;
 
-            if (obj.RemovedOnAdded != null)
+            if (obj.RemovedOnAdded is { })
             {
                 int offset;
 
@@ -4908,7 +4908,7 @@ public class TextView : View
             addedLines.Add (new List<RuneCell> (lines [i]));
         }
 
-        if (rest != null)
+        if (rest is { })
         {
             List<RuneCell> last = _model.GetLine (CurrentRow + lines.Count - 1);
             lastp = last.Count;
@@ -4921,7 +4921,7 @@ public class TextView : View
 
         // Now adjust column and row positions
         CurrentRow += lines.Count - 1;
-        CurrentColumn = rest != null ? lastp : lines [lines.Count - 1].Count;
+        CurrentColumn = rest is { } ? lastp : lines [lines.Count - 1].Count;
         Adjust ();
 
         _historyText.Add (
@@ -5424,7 +5424,7 @@ public class TextView : View
 
     private bool MoveNextView ()
     {
-        if (Application.OverlappedTop != null)
+        if (Application.OverlappedTop is { })
         {
             return SuperView?.FocusNext () == true;
         }
@@ -5490,7 +5490,7 @@ public class TextView : View
 
     private bool MovePreviousView ()
     {
-        if (Application.OverlappedTop != null)
+        if (Application.OverlappedTop is { })
         {
             return SuperView?.FocusPrev () == true;
         }
@@ -5760,7 +5760,7 @@ public class TextView : View
         RuneCell cell = line [colWithColor];
         int colWithoutColor = Math.Max (col - 1, 0);
 
-        if (cell.ColorScheme != null && colWithColor == 0 && lineToSet [colWithoutColor].ColorScheme != null)
+        if (cell.ColorScheme is { } && colWithColor == 0 && lineToSet [colWithoutColor].ColorScheme is { })
         {
             for (int r = row - 1; r > -1; r--)
             {
@@ -5768,7 +5768,7 @@ public class TextView : View
 
                 for (int c = l.Count - 1; c > -1; c--)
                 {
-                    if (l [c].ColorScheme == null)
+                    if (l [c].ColorScheme is null)
                     {
                         l [c].ColorScheme = cell.ColorScheme;
                     }
@@ -5782,7 +5782,7 @@ public class TextView : View
             return;
         }
 
-        if (cell.ColorScheme == null)
+        if (cell.ColorScheme is null)
         {
             for (int r = row; r > -1; r--)
             {
@@ -5793,7 +5793,7 @@ public class TextView : View
                                                 rc => rc.ColorScheme != null
                                                );
 
-                if (colWithColor > -1 && l [colWithColor].ColorScheme != null)
+                if (colWithColor > -1 && l [colWithColor].ColorScheme is { })
                 {
                     cell = l [colWithColor];
 
@@ -5805,9 +5805,9 @@ public class TextView : View
         {
             int cRow = row;
 
-            while (cell.ColorScheme == null)
+            while (cell.ColorScheme is null)
             {
-                if ((colWithColor == 0 || cell.ColorScheme == null) && cRow > 0)
+                if ((colWithColor == 0 || cell.ColorScheme is null) && cRow > 0)
                 {
                     line = GetLine (--cRow);
                     colWithColor = line.Count - 1;
@@ -5820,9 +5820,9 @@ public class TextView : View
             }
         }
 
-        if (cell.ColorScheme != null && colWithColor > -1 && colWithoutColor < lineToSet.Count && lineToSet [colWithoutColor].ColorScheme == null)
+        if (cell.ColorScheme is { } && colWithColor > -1 && colWithoutColor < lineToSet.Count && lineToSet [colWithoutColor].ColorScheme is null)
         {
-            while (lineToSet [colWithoutColor].ColorScheme == null)
+            while (lineToSet [colWithoutColor].ColorScheme is null)
             {
                 lineToSet [colWithoutColor].ColorScheme = cell.ColorScheme;
                 colWithoutColor--;
@@ -6288,7 +6288,7 @@ public class TextView : View
 
     private void SetClipboard (string text)
     {
-        if (text != null)
+        if (text is { })
         {
             Clipboard.Contents = text;
         }
@@ -6362,7 +6362,7 @@ public class TextView : View
     /// <summary>Restore from original model.</summary>
     private void SetWrapModel ([CallerMemberName] string? caller = null)
     {
-        if (_currentCaller != null)
+        if (_currentCaller is { })
         {
             return;
         }
@@ -6415,7 +6415,7 @@ public class TextView : View
 
     private string StringFromRunes (List<RuneCell> cells)
     {
-        if (cells == null)
+        if (cells is null)
         {
             throw new ArgumentNullException (nameof (cells));
         }
@@ -6442,7 +6442,7 @@ public class TextView : View
     {
         Autocomplete.HostControl = this;
 
-        if (Application.Top != null)
+        if (Application.Top is { })
         {
             Application.Top.AlternateForwardKeyChanged += Top_AlternateForwardKeyChanged!;
             Application.Top.AlternateBackwardKeyChanged += Top_AlternateBackwardKeyChanged!;
@@ -6493,7 +6493,7 @@ public class TextView : View
     /// <summary>Update the original model.</summary>
     private void UpdateWrapModel ([CallerMemberName] string? caller = null)
     {
-        if (_currentCaller != null && _currentCaller != caller)
+        if (_currentCaller is { } && _currentCaller != caller)
         {
             return;
         }
@@ -6523,7 +6523,7 @@ public class TextView : View
             SetNeedsDisplay ();
         }
 
-        if (_currentCaller != null)
+        if (_currentCaller is { })
         {
             throw new InvalidOperationException (
                                                  $"WordWrap settings was changed after the {_currentCaller} call."
@@ -6533,7 +6533,7 @@ public class TextView : View
 
     private void WrapTextModel ()
     {
-        if (_wordWrap && _wrapManager != null)
+        if (_wordWrap && _wrapManager is { })
         {
             _model = _wrapManager.WrapModel (
                                              _frameWidth,

+ 3 - 3
Terminal.Gui/Views/TileView.cs

@@ -312,7 +312,7 @@ public class TileView : View
         _tiles = new List<Tile> ();
         _splitterDistances = new List<Pos> ();
 
-        if (_splitterLines != null)
+        if (_splitterLines is { })
         {
             foreach (TileViewLineView sl in _splitterLines)
             {
@@ -580,7 +580,7 @@ public class TileView : View
     {
         TileView root = this;
 
-        while (root.parentTileView != null)
+        while (root.parentTileView is { })
         {
             root = root.parentTileView;
         }
@@ -891,7 +891,7 @@ public class TileView : View
 
         public void DrawSplitterSymbol ()
         {
-            if (dragPosition != null || CanFocus)
+            if (dragPosition is { } || CanFocus)
             {
                 Point location = moveRuneRenderLocation ?? new Point (Bounds.Width / 2, Bounds.Height / 2);
 

+ 32 - 32
Terminal.Gui/Views/Toplevel.cs

@@ -143,7 +143,7 @@ public partial class Toplevel : View
 
     /// <summary>Gets or sets a value indicating whether this <see cref="Toplevel"/> can focus.</summary>
     /// <value><c>true</c> if can focus; otherwise, <c>false</c>.</value>
-    public override bool CanFocus => SuperView == null ? true : base.CanFocus;
+    public override bool CanFocus => SuperView is null ? true : base.CanFocus;
 
     /// <summary>
     ///     <see langword="true"/> if was already loaded by the <see cref="Application.Begin(Toplevel)"/>
@@ -276,7 +276,7 @@ public partial class Toplevel : View
         {
             if (_dragPosition.HasValue)
             {
-                if (SuperView == null)
+                if (SuperView is null)
                 {
                     // Redraw the entire app window using just our Frame. Since we are 
                     // Application.Top, and our Frame always == our Bounds (Location is always (0,0))
@@ -393,7 +393,7 @@ public partial class Toplevel : View
             base.OnDrawContent (contentArea);
 
             // This is causing the menus drawn incorrectly if UseSubMenusSingleFrame is true
-            //if (this.MenuBar != null && this.MenuBar.IsMenuOpen && this.MenuBar.openMenu != null) {
+            //if (this.MenuBar is { } && this.MenuBar.IsMenuOpen && this.MenuBar.openMenu is { }) {
             //	// TODO: Hack until we can get compositing working right.
             //	this.MenuBar.openMenu.Redraw (this.MenuBar.openMenu.Bounds);
             //}
@@ -437,11 +437,11 @@ public partial class Toplevel : View
         {
             base.PositionCursor ();
 
-            if (Focused == null)
+            if (Focused is null)
             {
                 EnsureFocus ();
 
-                if (Focused == null)
+                if (Focused is null)
                 {
                     Driver.SetCursorVisibility (CursorVisibility.Invisible);
                 }
@@ -450,7 +450,7 @@ public partial class Toplevel : View
             return;
         }
 
-        if (Focused == null)
+        if (Focused is null)
         {
             foreach (Toplevel top in Application.OverlappedChildren)
             {
@@ -465,7 +465,7 @@ public partial class Toplevel : View
 
         base.PositionCursor ();
 
-        if (Focused == null)
+        if (Focused is null)
         {
             Driver.SetCursorVisibility (CursorVisibility.Invisible);
         }
@@ -490,23 +490,23 @@ public partial class Toplevel : View
         var layoutSubviews = false;
         var maxWidth = 0;
 
-        if (superView.Margin != null && superView == top.SuperView)
+        if (superView.Margin is { } && superView == top.SuperView)
         {
             maxWidth -= superView.GetAdornmentsThickness ().Left + superView.GetAdornmentsThickness ().Right;
         }
 
-        if ((superView != top || top?.SuperView != null || (top != Application.Top && top.Modal) || (top?.SuperView == null && top.IsOverlapped))
+        if ((superView != top || top?.SuperView is { } || (top != Application.Top && top.Modal) || (top?.SuperView is null && top.IsOverlapped))
 
             // BUGBUG: Prevously PositionToplevel required LayotuStyle.Computed
             && (top.Frame.X + top.Frame.Width > maxWidth || ny > top.Frame.Y) /*&& top.LayoutStyle == LayoutStyle.Computed*/)
         {
-            if ((top.X == null || top.X is Pos.PosAbsolute) && top.Frame.X != nx)
+            if ((top.X is null || top.X is Pos.PosAbsolute) && top.Frame.X != nx)
             {
                 top.X = nx;
                 layoutSubviews = true;
             }
 
-            if ((top.Y == null || top.Y is Pos.PosAbsolute) && top.Frame.Y != ny)
+            if ((top.Y is null || top.Y is Pos.PosAbsolute) && top.Frame.Y != ny)
             {
                 top.Y = ny;
                 layoutSubviews = true;
@@ -551,7 +551,7 @@ public partial class Toplevel : View
     /// <inheritdoc/>
     public override void Remove (View view)
     {
-        if (this is Toplevel Toplevel && Toplevel.MenuBar != null)
+        if (this is Toplevel Toplevel && Toplevel.MenuBar is { })
         {
             RemoveMenuStatusBar (view);
         }
@@ -703,7 +703,7 @@ public partial class Toplevel : View
         int maxWidth;
         View superView;
 
-        if (top?.SuperView == null || top == Application.Top || top?.SuperView == Application.Top)
+        if (top?.SuperView is null || top == Application.Top || top?.SuperView == Application.Top)
         {
             maxWidth = Driver.Cols;
             superView = Application.Top;
@@ -715,7 +715,7 @@ public partial class Toplevel : View
             superView = top.SuperView;
         }
 
-        if (superView.Margin != null && superView == top.SuperView)
+        if (superView.Margin is { } && superView == top.SuperView)
         {
             maxWidth -= superView.GetAdornmentsThickness ().Left + superView.GetAdornmentsThickness ().Right;
         }
@@ -738,7 +738,7 @@ public partial class Toplevel : View
         //System.Diagnostics.Debug.WriteLine ($"nx:{nx}, rWidth:{rWidth}");
         bool menuVisible, statusVisible;
 
-        if (top?.SuperView == null || top == Application.Top || top?.SuperView == Application.Top)
+        if (top?.SuperView is null || top == Application.Top || top?.SuperView == Application.Top)
         {
             menuVisible = Application.Top.MenuBar?.Visible == true;
             menuBar = Application.Top.MenuBar;
@@ -756,7 +756,7 @@ public partial class Toplevel : View
             menuBar = ((Toplevel)t).MenuBar;
         }
 
-        if (top?.SuperView == null || top == Application.Top || top?.SuperView == Application.Top)
+        if (top?.SuperView is null || top == Application.Top || top?.SuperView == Application.Top)
         {
             maxWidth = menuVisible ? 1 : 0;
         }
@@ -767,7 +767,7 @@ public partial class Toplevel : View
 
         ny = Math.Max (targetY, maxWidth);
 
-        if (top?.SuperView == null || top == Application.Top || top?.SuperView == Application.Top)
+        if (top?.SuperView is null || top == Application.Top || top?.SuperView == Application.Top)
         {
             statusVisible = Application.Top.StatusBar?.Visible == true;
             statusBar = Application.Top.StatusBar;
@@ -785,7 +785,7 @@ public partial class Toplevel : View
             statusBar = ((Toplevel)t).StatusBar;
         }
 
-        if (top?.SuperView == null || top == Application.Top || top?.SuperView == Application.Top)
+        if (top?.SuperView is null || top == Application.Top || top?.SuperView == Application.Top)
         {
             maxWidth = statusVisible ? Driver.Rows - 1 : Driver.Rows;
         }
@@ -794,7 +794,7 @@ public partial class Toplevel : View
             maxWidth = statusVisible ? top.SuperView.Frame.Height - 1 : top.SuperView.Frame.Height;
         }
 
-        if (superView.Margin != null && superView == top.SuperView)
+        if (superView.Margin is { } && superView == top.SuperView)
         {
             maxWidth -= superView.GetAdornmentsThickness ().Top + superView.GetAdornmentsThickness ().Bottom;
         }
@@ -919,7 +919,7 @@ public partial class Toplevel : View
 
     private void FocusNearestView (IEnumerable<View> views, NavigationDirection direction)
     {
-        if (views == null)
+        if (views is null)
         {
             return;
         }
@@ -948,7 +948,7 @@ public partial class Toplevel : View
 
                 focusProcessed = true;
 
-                if (SuperView.Focused != null && SuperView.Focused != this)
+                if (SuperView.Focused is { } && SuperView.Focused != this)
                 {
                     return;
                 }
@@ -964,7 +964,7 @@ public partial class Toplevel : View
 
     private View GetDeepestFocusedSubview (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return null;
         }
@@ -1002,12 +1002,12 @@ public partial class Toplevel : View
 
     private void MoveNextViewOrTop ()
     {
-        if (Application.OverlappedTop == null)
+        if (Application.OverlappedTop is null)
         {
             Toplevel top = Modal ? this : Application.Top;
             top.FocusNext ();
 
-            if (top.Focused == null)
+            if (top.Focused is null)
             {
                 top.FocusNext ();
             }
@@ -1043,12 +1043,12 @@ public partial class Toplevel : View
 
     private void MovePreviousViewOrTop ()
     {
-        if (Application.OverlappedTop == null)
+        if (Application.OverlappedTop is null)
         {
             Toplevel top = Modal ? this : Application.Top;
             top.FocusPrev ();
 
-            if (top.Focused == null)
+            if (top.Focused is null)
             {
                 top.FocusPrev ();
             }
@@ -1074,7 +1074,7 @@ public partial class Toplevel : View
 
     private void QuitToplevel ()
     {
-        if (Application.OverlappedTop != null)
+        if (Application.OverlappedTop is { })
         {
             Application.OverlappedTop.RequestStop ();
         }
@@ -1097,12 +1097,12 @@ public class ToplevelEqualityComparer : IEqualityComparer<Toplevel>
     /// <returns><see langword="true"/> if the specified objects are equal; otherwise, <see langword="false"/>.</returns>
     public bool Equals (Toplevel x, Toplevel y)
     {
-        if (y == null && x == null)
+        if (y is null && x is null)
         {
             return true;
         }
 
-        if (x == null || y == null)
+        if (x is null || y is null)
         {
             return false;
         }
@@ -1124,7 +1124,7 @@ public class ToplevelEqualityComparer : IEqualityComparer<Toplevel>
     /// </exception>
     public int GetHashCode (Toplevel obj)
     {
-        if (obj == null)
+        if (obj is null)
         {
             throw new ArgumentNullException ();
         }
@@ -1165,12 +1165,12 @@ public sealed class ToplevelComparer : IComparer<Toplevel>
             return 0;
         }
 
-        if (x == null)
+        if (x is null)
         {
             return -1;
         }
 
-        if (y == null)
+        if (y is null)
         {
             return 1;
         }

+ 12 - 12
Terminal.Gui/Views/ToplevelOverlapped.cs

@@ -3,7 +3,7 @@
 public partial class Toplevel
 {
     /// <summary>Gets or sets if this Toplevel is in overlapped mode within a Toplevel container.</summary>
-    public bool IsOverlapped => Application.OverlappedTop != null && Application.OverlappedTop != this && !Modal;
+    public bool IsOverlapped => Application.OverlappedTop is { } && Application.OverlappedTop != this && !Modal;
 
     /// <summary>Gets or sets if this Toplevel is a container for overlapped children.</summary>
     public bool IsOverlappedContainer { get; set; }
@@ -19,7 +19,7 @@ public static partial class Application
     {
         get
         {
-            if (OverlappedTop != null)
+            if (OverlappedTop is { })
             {
                 List<Toplevel> _overlappedChildren = new ();
 
@@ -58,14 +58,14 @@ public static partial class Application
     /// <summary>Brings the superview of the most focused overlapped view is on front.</summary>
     public static void BringOverlappedTopToFront ()
     {
-        if (OverlappedTop != null)
+        if (OverlappedTop is { })
         {
             return;
         }
 
         View top = FindTopFromView (Top?.MostFocused);
 
-        if (top != null && Top.Subviews.Count > 1 && Top.Subviews [Top.Subviews.Count - 1] != top)
+        if (top is { } && Top.Subviews.Count > 1 && Top.Subviews [Top.Subviews.Count - 1] != top)
         {
             Top.BringSubviewToFront (top);
         }
@@ -77,19 +77,19 @@ public static partial class Application
     /// <returns>The matched view.</returns>
     public static Toplevel GetTopOverlappedChild (Type type = null, string [] exclude = null)
     {
-        if (OverlappedTop == null)
+        if (OverlappedTop is null)
         {
             return null;
         }
 
         foreach (Toplevel top in OverlappedChildren)
         {
-            if (type != null && top.GetType () == type && exclude?.Contains (top.Data.ToString ()) == false)
+            if (type is { } && top.GetType () == type && exclude?.Contains (top.Data.ToString ()) == false)
             {
                 return top;
             }
 
-            if ((type != null && top.GetType () != type) || exclude?.Contains (top.Data.ToString ()) == true)
+            if ((type is { } && top.GetType () != type) || exclude?.Contains (top.Data.ToString ()) == true)
             {
                 continue;
             }
@@ -108,7 +108,7 @@ public static partial class Application
     /// <returns></returns>
     public static bool MoveToOverlappedChild (Toplevel top)
     {
-        if (top.Visible && OverlappedTop != null && Current?.Modal == false)
+        if (top.Visible && OverlappedTop is { } && Current?.Modal == false)
         {
             lock (_topLevels)
             {
@@ -125,7 +125,7 @@ public static partial class Application
     /// <summary>Move to the next Overlapped child from the <see cref="OverlappedTop"/>.</summary>
     public static void OverlappedMoveNext ()
     {
-        if (OverlappedTop != null && !Current.Modal)
+        if (OverlappedTop is { } && !Current.Modal)
         {
             lock (_topLevels)
             {
@@ -156,7 +156,7 @@ public static partial class Application
     /// <summary>Move to the previous Overlapped child from the <see cref="OverlappedTop"/>.</summary>
     public static void OverlappedMovePrevious ()
     {
-        if (OverlappedTop != null && !Current.Modal)
+        if (OverlappedTop is { } && !Current.Modal)
         {
             lock (_topLevels)
             {
@@ -186,7 +186,7 @@ public static partial class Application
 
     private static bool OverlappedChildNeedsDisplay ()
     {
-        if (OverlappedTop == null)
+        if (OverlappedTop is null)
         {
             return false;
         }
@@ -206,7 +206,7 @@ public static partial class Application
 
     private static bool SetCurrentOverlappedAsTop ()
     {
-        if (OverlappedTop == null && Current != Top && Current?.SuperView == null && Current?.Modal == false)
+        if (OverlappedTop is null && Current != Top && Current?.SuperView is null && Current?.Modal == false)
         {
             Top = Current;
 

+ 12 - 12
Terminal.Gui/Views/TreeView/Branch.cs

@@ -16,7 +16,7 @@ internal class Branch<T> where T : class
         this.tree = tree;
         Model = model;
 
-        if (parentBranchIfAny != null)
+        if (parentBranchIfAny is { })
         {
             Depth = parentBranchIfAny.Depth + 1;
             Parent = parentBranchIfAny;
@@ -49,7 +49,7 @@ internal class Branch<T> where T : class
     public bool CanExpand ()
     {
         // if we do not know the children yet
-        if (ChildBranches == null)
+        if (ChildBranches is null)
         {
             //if there is a rapid method for determining whether there are children
             if (tree.TreeBuilder.SupportsCanExpand)
@@ -194,12 +194,12 @@ internal class Branch<T> where T : class
         Attribute modelColor = textColor;
 
         // if custom color delegate invoke it
-        if (tree.ColorGetter != null)
+        if (tree.ColorGetter is { })
         {
             ColorScheme modelScheme = tree.ColorGetter (Model);
 
             // if custom color scheme is defined for this Model
-            if (modelScheme != null)
+            if (modelScheme is { })
             {
                 // use it
                 modelColor = isSelected ? modelScheme.Focus : modelScheme.Normal;
@@ -252,7 +252,7 @@ internal class Branch<T> where T : class
     /// <summary>Expands the current branch if possible.</summary>
     public void Expand ()
     {
-        if (ChildBranches == null)
+        if (ChildBranches is null)
         {
             FetchChildren ();
         }
@@ -266,7 +266,7 @@ internal class Branch<T> where T : class
     /// <summary>Fetch the children of this branch. This method populates <see cref="ChildBranches"/>.</summary>
     public virtual void FetchChildren ()
     {
-        if (tree.TreeBuilder == null)
+        if (tree.TreeBuilder is null)
         {
             return;
         }
@@ -331,7 +331,7 @@ internal class Branch<T> where T : class
 
         // we don't want to loose the state of our children so lets be selective about how we refresh
         //if we don't know about any children yet just use the normal method
-        if (ChildBranches == null)
+        if (ChildBranches is null)
         {
             FetchChildren ();
         }
@@ -379,7 +379,7 @@ internal class Branch<T> where T : class
     {
         Collapse ();
 
-        if (ChildBranches != null)
+        if (ChildBranches is { })
         {
             foreach (KeyValuePair<T, Branch<T>> child in ChildBranches)
             {
@@ -393,7 +393,7 @@ internal class Branch<T> where T : class
     {
         Expand ();
 
-        if (ChildBranches != null)
+        if (ChildBranches is { })
         {
             foreach (KeyValuePair<T, Branch<T>> child in ChildBranches)
             {
@@ -482,7 +482,7 @@ internal class Branch<T> where T : class
         Refresh (false);
 
         // if we know about our children
-        if (ChildBranches != null)
+        if (ChildBranches is { })
         {
             if (IsExpanded)
             {
@@ -506,7 +506,7 @@ internal class Branch<T> where T : class
     {
         Branch<T> cur = Parent;
 
-        while (cur != null)
+        while (cur is { })
         {
             yield return cur;
 
@@ -521,7 +521,7 @@ internal class Branch<T> where T : class
     /// <returns></returns>
     private bool IsLast ()
     {
-        if (Parent == null)
+        if (Parent is null)
         {
             return this == tree.roots.Values.LastOrDefault ();
         }

+ 23 - 23
Terminal.Gui/Views/TreeView/TreeView.cs

@@ -35,7 +35,7 @@ public class TreeView : TreeView<ITreeNode>
     public TreeView ()
     {
         TreeBuilder = new TreeNodeBuilder ();
-        AspectGetter = o => o == null ? "Null" : o.Text ?? o?.ToString () ?? "Unamed Node";
+        AspectGetter = o => o is null ? "Null" : o.Text ?? o?.ToString () ?? "Unamed Node";
     }
 }
 
@@ -463,7 +463,7 @@ public class TreeView<T> : View, ITreeView where T : class
     {
         T o = SelectedObject;
 
-        if (o != null)
+        if (o is { })
         {
             OnObjectActivated (new ObjectActivatedEventArgs<T> (this, o));
             PositionCursor ();
@@ -526,7 +526,7 @@ public class TreeView<T> : View, ITreeView where T : class
             multiSelectedRegions.Clear ();
         }
 
-        if (SelectedObject == null)
+        if (SelectedObject is null)
         {
             SelectedObject = roots.Keys.FirstOrDefault ();
         }
@@ -577,7 +577,7 @@ public class TreeView<T> : View, ITreeView where T : class
     {
         T o = SelectedObject;
 
-        if (o == null)
+        if (o is null)
         {
             return;
         }
@@ -619,7 +619,7 @@ public class TreeView<T> : View, ITreeView where T : class
     {
         T o = SelectedObject;
 
-        if (o == null)
+        if (o is null)
         {
             return;
         }
@@ -755,7 +755,7 @@ public class TreeView<T> : View, ITreeView where T : class
     /// <param name="toExpand">The object to expand.</param>
     public void Expand (T toExpand)
     {
-        if (toExpand == null)
+        if (toExpand is null)
         {
             return;
         }
@@ -769,7 +769,7 @@ public class TreeView<T> : View, ITreeView where T : class
     /// <param name="toExpand">The object to expand.</param>
     public void ExpandAll (T toExpand)
     {
-        if (toExpand == null)
+        if (toExpand is null)
         {
             return;
         }
@@ -815,7 +815,7 @@ public class TreeView<T> : View, ITreeView where T : class
         }
         else
         {
-            if (SelectedObject != null)
+            if (SelectedObject is { })
             {
                 yield return SelectedObject;
             }
@@ -832,7 +832,7 @@ public class TreeView<T> : View, ITreeView where T : class
     {
         Branch<T> branch = ObjectToBranch (o);
 
-        if (branch == null || !branch.IsExpanded)
+        if (branch is null || !branch.IsExpanded)
         {
             return new T [0];
         }
@@ -949,7 +949,7 @@ public class TreeView<T> : View, ITreeView where T : class
     /// <param name="toSelect"></param>
     public void GoTo (T toSelect)
     {
-        if (ObjectToBranch (toSelect) == null)
+        if (ObjectToBranch (toSelect) is null)
         {
             return;
         }
@@ -1052,7 +1052,7 @@ public class TreeView<T> : View, ITreeView where T : class
             // The line they clicked on a branch
             Branch<T> clickedBranch = HitTest (me.Y);
 
-            if (clickedBranch == null)
+            if (clickedBranch is null)
             {
                 return false;
             }
@@ -1102,7 +1102,7 @@ public class TreeView<T> : View, ITreeView where T : class
             // The line they clicked on a branch
             Branch<T> clickedBranch = HitTest (me.Y);
 
-            if (clickedBranch == null)
+            if (clickedBranch is null)
             {
                 return false;
             }
@@ -1141,12 +1141,12 @@ public class TreeView<T> : View, ITreeView where T : class
     ///<inheritdoc/>
     public override void OnDrawContent (Rect contentArea)
     {
-        if (roots == null)
+        if (roots is null)
         {
             return;
         }
 
-        if (TreeBuilder == null)
+        if (TreeBuilder is null)
         {
             Move (0, 0);
             Driver.AddStr (NoBuilderError);
@@ -1181,7 +1181,7 @@ public class TreeView<T> : View, ITreeView where T : class
     {
         Application.Driver.SetCursorVisibility (DesiredCursorVisibility);
 
-        if (SelectedObject == null && Objects.Any ())
+        if (SelectedObject is null && Objects.Any ())
         {
             SelectedObject = Objects.First ();
         }
@@ -1237,7 +1237,7 @@ public class TreeView<T> : View, ITreeView where T : class
     /// <summary>Positions the cursor at the start of the selected objects line (if visible).</summary>
     public override void PositionCursor ()
     {
-        if (CanFocus && HasFocus && Visible && SelectedObject != null)
+        if (CanFocus && HasFocus && Visible && SelectedObject is { })
         {
             IReadOnlyCollection<Branch<T>> map = BuildLineMap ();
             int idx = map.IndexOf (b => b.Model.Equals (SelectedObject));
@@ -1288,7 +1288,7 @@ public class TreeView<T> : View, ITreeView where T : class
     {
         Branch<T> branch = ObjectToBranch (o);
 
-        if (branch != null)
+        if (branch is { })
         {
             branch.Refresh (startAtTop);
             InvalidateLineMap ();
@@ -1369,7 +1369,7 @@ public class TreeView<T> : View, ITreeView where T : class
     /// <param name="all"></param>
     protected void CollapseImpl (T toCollapse, bool all)
     {
-        if (toCollapse == null)
+        if (toCollapse is null)
         {
             return;
         }
@@ -1377,7 +1377,7 @@ public class TreeView<T> : View, ITreeView where T : class
         Branch<T> branch = ObjectToBranch (toCollapse);
 
         // Nothing to collapse
-        if (branch == null)
+        if (branch is null)
         {
             return;
         }
@@ -1391,7 +1391,7 @@ public class TreeView<T> : View, ITreeView where T : class
             branch.Collapse ();
         }
 
-        if (SelectedObject != null && ObjectToBranch (SelectedObject) == null)
+        if (SelectedObject is { } && ObjectToBranch (SelectedObject) is null)
         {
             // If the old selection suddenly became invalid then clear it
             SelectedObject = null;
@@ -1422,7 +1422,7 @@ public class TreeView<T> : View, ITreeView where T : class
         {
             T parent = GetParent (SelectedObject);
 
-            if (parent != null)
+            if (parent is { })
             {
                 SelectedObject = parent;
                 AdjustSelection (0);
@@ -1458,7 +1458,7 @@ public class TreeView<T> : View, ITreeView where T : class
     /// <returns></returns>
     internal IReadOnlyCollection<Branch<T>> BuildLineMap ()
     {
-        if (cachedLineMap != null)
+        if (cachedLineMap is { })
         {
             return cachedLineMap;
         }
@@ -1541,7 +1541,7 @@ public class TreeView<T> : View, ITreeView where T : class
         var idxStart = 0;
 
         // or the current selected branch
-        if (SelectedObject != null)
+        if (SelectedObject is { })
         {
             idxStart = map.IndexOf (b => Equals (b.Model, SelectedObject));
         }

+ 12 - 12
Terminal.Gui/Views/Wizard/Wizard.cs

@@ -68,7 +68,7 @@ public class Wizard : Dialog
     //	}
     //	set {
     //		wizardTitle = value;
-    //		base.Title = $"{wizardTitle}{(steps.Count > 0 && currentStep != null ? " - " + currentStep.Title : string.Empty)}";
+    //		base.Title = $"{wizardTitle}{(steps.Count > 0 && currentStep is { } ? " - " + currentStep.Title : string.Empty)}";
     //	}
     //}
     private string _wizardTitle = string.Empty;
@@ -169,7 +169,7 @@ public class Wizard : Dialog
             }
             else
             {
-                if (SuperView != null)
+                if (SuperView is { })
                 {
                     ColorScheme = SuperView.ColorScheme;
                 }
@@ -247,7 +247,7 @@ public class Wizard : Dialog
     {
         LinkedListNode<WizardStep> step = null;
 
-        if (CurrentStep == null)
+        if (CurrentStep is null)
         {
             // Get first step, assume it is next
             step = _steps.First;
@@ -257,14 +257,14 @@ public class Wizard : Dialog
             // Get the step after current
             step = _steps.Find (CurrentStep);
 
-            if (step != null)
+            if (step is { })
             {
                 step = step.Next;
             }
         }
 
         // step now points to the potential next step
-        while (step != null)
+        while (step is { })
         {
             if (step.Value.Enabled)
             {
@@ -289,7 +289,7 @@ public class Wizard : Dialog
     {
         LinkedListNode<WizardStep> step = null;
 
-        if (CurrentStep == null)
+        if (CurrentStep is null)
         {
             // Get last step, assume it is previous
             step = _steps.Last;
@@ -299,14 +299,14 @@ public class Wizard : Dialog
             // Get the step before current
             step = _steps.Find (CurrentStep);
 
-            if (step != null)
+            if (step is { })
             {
                 step = step.Previous;
             }
         }
 
         // step now points to the potential previous step
-        while (step != null)
+        while (step is { })
         {
             if (step.Value.Enabled)
             {
@@ -327,7 +327,7 @@ public class Wizard : Dialog
     {
         WizardStep previous = GetPreviousStep ();
 
-        if (previous != null)
+        if (previous is { })
         {
             GoToStep (previous);
         }
@@ -341,7 +341,7 @@ public class Wizard : Dialog
     {
         WizardStep nextStep = GetNextStep ();
 
-        if (nextStep != null)
+        if (nextStep is { })
         {
             GoToStep (nextStep);
         }
@@ -352,7 +352,7 @@ public class Wizard : Dialog
     /// <returns>True if the transition to the step succeeded. False if the step was not found or the operation was cancelled.</returns>
     public bool GoToStep (WizardStep newStep)
     {
-        if (OnStepChanging (_currentStep, newStep) || (newStep != null && !newStep.Enabled))
+        if (OnStepChanging (_currentStep, newStep) || (newStep is { } && !newStep.Enabled))
         {
             return false;
         }
@@ -532,7 +532,7 @@ public class Wizard : Dialog
 
     private void UpdateButtonsAndTitle ()
     {
-        if (CurrentStep == null)
+        if (CurrentStep is null)
         {
             return;
         }

+ 2 - 2
Terminal.Gui/Views/Wizard/WizardStep.cs

@@ -90,7 +90,7 @@ public class WizardStep : FrameView
         //helpTextView.DrawContent += (s,e) => {
         //	scrollBar.Size = helpTextView.Lines;
         //	scrollBar.Position = helpTextView.TopRow;
-        //	if (scrollBar.OtherScrollBarView != null) {
+        //	if (scrollBar.OtherScrollBarView is { }) {
         //		scrollBar.OtherScrollBarView.Size = helpTextView.Maxlength;
         //		scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn;
         //	}
@@ -143,7 +143,7 @@ public class WizardStep : FrameView
     /// <remarks></remarks>
     public override void Remove (View view)
     {
-        if (view == null)
+        if (view is null)
         {
             return;
         }

+ 0 - 13
UnitTests/Drawing/AttributeTests.cs

@@ -344,19 +344,6 @@ public class AttributeTests
         Assert.False (attr2.Equals (attr1));
     }
 
-    [Fact]
-    public void PlatformColorConstructor ()
-    {
-        // Arrange & Act
-        var attribute = new Attribute (42);
-
-        // Assert
-        //Assert.True (attribute.Initialized);
-        Assert.Equal (42, attribute.PlatformColor);
-        Assert.Equal (new Color (Color.White), attribute.Foreground);
-        Assert.Equal (new Color (Color.Black), attribute.Background);
-    }
-
     [Fact]
     public void ToString_ShouldReturnFormattedStringWithForegroundAndBackground ()
     {

+ 14 - 1
UnitTests/Input/ResponderTests.cs

@@ -23,8 +23,10 @@ public class ResponderTests
     [Fact]
     public void Disposing_Event_Notify_All_Subscribers_On_The_First_Container ()
     {
+    #if DEBUG_IDISPOSABLE
         // Only clear before because need to test after assert
         Responder.Instances.Clear ();
+    #endif
 
         var container1 = new View { Id = "Container1" };
         var count = 0;
@@ -57,14 +59,18 @@ public class ResponderTests
 
         container1.Dispose ();
 
+    #if DEBUG_IDISPOSABLE
         Assert.Empty (Responder.Instances);
+    #endif
     }
 
     [Fact]
     public void Disposing_Event_Notify_All_Subscribers_On_The_Second_Container ()
     {
+    #if DEBUG_IDISPOSABLE
         // Only clear before because need to test after assert
         Responder.Instances.Clear ();
+    #endif
 
         var container1 = new View { Id = "Container1" };
 
@@ -97,7 +103,9 @@ public class ResponderTests
 
         container2.Dispose ();
 
+    #if DEBUG_IDISPOSABLE
         Assert.Empty (Responder.Instances);
+    #endif
     }
 
     [Fact]
@@ -256,8 +264,9 @@ public class ResponderTests
     public void Responder_Not_Notifying_Dispose ()
     {
         // Only clear before because need to test after assert
+    #if DEBUG_IDISPOSABLE
         Responder.Instances.Clear ();
-
+    #endif
         var container1 = new View { Id = "Container1" };
 
         var view = new View { Id = "View" };
@@ -279,7 +288,9 @@ public class ResponderTests
         Assert.Null (view.SuperView);
 
         // Trying access disposed properties
+    #if DEBUG_IDISPOSABLE
         Assert.True (container2.Subviews [0].WasDisposed);
+    #endif
         Assert.False (container2.Subviews [0].CanFocus);
         Assert.Null (container2.Subviews [0].Margin);
         Assert.Null (container2.Subviews [0].Border);
@@ -288,7 +299,9 @@ public class ResponderTests
 
         container2.Dispose ();
 
+    #if DEBUG_IDISPOSABLE
         Assert.Empty (Responder.Instances);
+    #endif
     }
 
     public class DerivedView : View

+ 60 - 49
UnitTests/View/Layout/DimTests.cs

@@ -615,31 +615,45 @@ public class DimTests
 
         t.Ready += (s, e) =>
                    {
-                       Assert.Equal ("Absolute(100)", w.Width.ToString ());
-                       Assert.Equal ("Absolute(100)", w.Height.ToString ());
-                       Assert.Equal (100, w.Frame.Width);
-                       Assert.Equal (100, w.Frame.Height);
-
-                       Assert.Equal ("Factor(0.5,False)", f1.Width.ToString ());
-                       Assert.Equal ("Absolute(5)", f1.Height.ToString ());
-                       Assert.Equal (49, f1.Frame.Width); // 50-1=49
-                       Assert.Equal (5, f1.Frame.Height);
-
-                       Assert.Equal ("Fill(0)", f2.Width.ToString ());
-                       Assert.Equal ("Absolute(5)", f2.Height.ToString ());
-                       Assert.Equal (49, f2.Frame.Width); // 50-1=49
-                       Assert.Equal (5, f2.Frame.Height);
-
+                                            Assert.Equal ("Absolute(100)", w.Width.ToString ());
+                                            Assert.Equal ("Absolute(100)", w.Height.ToString ());
+                                            Assert.Equal (100, w.Frame.Width);
+                                            Assert.Equal (100, w.Frame.Height);
+
+                                            Assert.Equal ("Factor(0.5,False)", f1.Width.ToString ());
+                                            Assert.Equal ("Absolute(5)", f1.Height.ToString ());
+                                            Assert.Equal (49, f1.Frame.Width); // 50-1=49
+                                            Assert.Equal (5, f1.Frame.Height);
+
+                                            Assert.Equal ("Fill(0)", f2.Width.ToString ());
+                                            Assert.Equal ("Absolute(5)", f2.Height.ToString ());
+                                            Assert.Equal (49, f2.Frame.Width); // 50-1=49
+                                            Assert.Equal (5, f2.Frame.Height);
+
+                    #if DEBUG
                        Assert.Equal ("Combine(View(Width,FrameView(f1)(0,0,49,5))-Absolute(2))", v1.Width.ToString ());
+                    #else
+                       Assert.Equal ("Combine(View(Width,FrameView()(0,0,49,5))-Absolute(2))", v1.Width.ToString ());
+                    #endif
                        Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ());
                        Assert.Equal (47, v1.Frame.Width); // 49-2=47
                        Assert.Equal (89, v1.Frame.Height); // 98-5-2-2=89
 
+                   #if DEBUG
                        Assert.Equal (
                                      "Combine(View(Width,FrameView(f2)(49,0,49,5))-Absolute(2))",
                                      v2.Width.ToString ()
+                   #else
+                       Assert.Equal (
+                                     "Combine(View(Width,FrameView()(49,0,49,5))-Absolute(2))",
+                                     v2.Width.ToString ()
+                   #endif
                                     );
+                   #if DEBUG
+                       Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ());
+                   #else
                        Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ());
+                   #endif
                        Assert.Equal (47, v2.Frame.Width); // 49-2=47
                        Assert.Equal (89, v2.Frame.Height); // 98-5-2-2=89
 
@@ -652,22 +666,17 @@ public class DimTests
                        Assert.Equal ("Absolute(50)", v4.Height.ToString ());
                        Assert.Equal (50, v4.Frame.Width);
                        Assert.Equal (50, v4.Frame.Height);
-
-                       Assert.Equal (
-                                     "Combine(View(Width,Button(v1)(2,7,47,89))-View(Width,Button(v3)(0,0,9,9)))",
-                                     v5.Width.ToString ()
-                                    );
-
-                       Assert.Equal (
-                                     "Combine(View(Height,Button(v1)(2,7,47,89))-View(Height,Button(v3)(0,0,9,9)))",
-                                     v5.Height.ToString ()
-                                    );
-                       Assert.Equal (38, v5.Frame.Width); // 47-9=38
+                   #if DEBUG
+                       Assert.Equal ("Combine(View(Width,Button(v1)(2,7,47,89))-View(Width,Button(v3)(0,0,9,9)))", v5.Width.ToString ());
+                    #else
+                       Assert.Equal ("Combine(View(Height,Button()(2,7,47,89))-View(Height,Button()(0,0,9,9)))", v5.Height.ToString ( ));
+                   #endif
+                       Assert.Equal (38, v5.Frame.Width);  // 47-9=38
                        Assert.Equal (80, v5.Frame.Height); // 89-9=80
 
                        Assert.Equal ("Factor(0.2,True)", v6.Width.ToString ());
                        Assert.Equal ("Factor(0.2,True)", v6.Height.ToString ());
-                       Assert.Equal (9, v6.Frame.Width); // 47*20%=9
+                       Assert.Equal (9, v6.Frame.Width);   // 47*20%=9
                        Assert.Equal (18, v6.Frame.Height); // 89*20%=18
 
                        w.Width = 200;
@@ -693,31 +702,34 @@ public class DimTests
                        Assert.Equal (5, f2.Frame.Height);
 
                        v1.Text = "Button1";
+                   #if DEBUG
                        Assert.Equal ("Combine(View(Width,FrameView(f1)(0,0,99,5))-Absolute(2))", v1.Width.ToString ());
+                   #else
+                       Assert.Equal ("Combine(View(Width,FrameView()(0,0,99,5))-Absolute(2))", v1.Width.ToString ());
+                   #endif
                        Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ());
-                       Assert.Equal (97, v1.Frame.Width); // 99-2=97
+                       Assert.Equal (97, v1.Frame.Width);   // 99-2=97
                        Assert.Equal (189, v1.Frame.Height); // 198-2-7=189
 
                        v2.Text = "Button2";
 
-                       Assert.Equal (
-                                     "Combine(View(Width,FrameView(f2)(99,0,99,5))-Absolute(2))",
-                                     v2.Width.ToString ()
-                                    );
+                   #if DEBUG
+                   Assert.Equal ( "Combine(View(Width,FrameView(f2)(99,0,99,5))-Absolute(2))", v2.Width.ToString ());
+                   #else
+                       Assert.Equal ( "Combine(View(Width,FrameView()(99,0,99,5))-Absolute(2))", v2.Width.ToString ());
+                   #endif
                        Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ());
-                       Assert.Equal (97, v2.Frame.Width); // 99-2=97
+                       Assert.Equal (97, v2.Frame.Width);   // 99-2=97
                        Assert.Equal (189, v2.Frame.Height); // 198-2-7=189
 
                        v3.Text = "Button3";
                        Assert.Equal ("Factor(0.1,False)", v3.Width.ToString ());
                        Assert.Equal ("Factor(0.1,False)", v3.Height.ToString ());
 
-                       Assert.Equal (
-                                     19,
-                                     v3.Frame
-                                       .Width
-                                    ); // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
-                       Assert.Equal (19, v3.Frame.Height); // 199*10%=19
+                       // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
+                       Assert.Equal (19, v3.Frame.Width );
+                       // 199*10%=19
+                       Assert.Equal (19, v3.Frame.Height);
 
                        v4.Text = "Button4";
                        v4.AutoSize = false;
@@ -733,22 +745,21 @@ public class DimTests
 
                        v5.Text = "Button5";
 
-                       Assert.Equal (
-                                     "Combine(View(Width,Button(v1)(2,7,97,189))-View(Width,Button(v3)(0,0,19,19)))",
-                                     v5.Width.ToString ()
-                                    );
+                   #if DEBUG
+                       Assert.Equal ("Combine(View(Width,Button(v1)(2,7,97,189))-View(Width,Button(v3)(0,0,19,19)))", v5.Width.ToString ());
+                       Assert.Equal ("Combine(View(Height,Button(v1)(2,7,97,189))-View(Height,Button(v3)(0,0,19,19)))", v5.Height.ToString ());
+                   #else
+                       Assert.Equal ("Combine(View(Width,Button()(2,7,97,189))-View(Width,Button()(0,0,19,19)))", v5.Width.ToString ());
+                       Assert.Equal ("Combine(View(Height,Button()(2,7,97,189))-View(Height,Button()(0,0,19,19)))", v5.Height.ToString ());
+                   #endif
 
-                       Assert.Equal (
-                                     "Combine(View(Height,Button(v1)(2,7,97,189))-View(Height,Button(v3)(0,0,19,19)))",
-                                     v5.Height.ToString ()
-                                    );
-                       Assert.Equal (78, v5.Frame.Width); // 97-9=78
+                       Assert.Equal (78, v5.Frame.Width);   // 97-9=78
                        Assert.Equal (170, v5.Frame.Height); // 189-19=170
 
                        v6.Text = "Button6";
                        Assert.Equal ("Factor(0.2,True)", v6.Width.ToString ());
                        Assert.Equal ("Factor(0.2,True)", v6.Height.ToString ());
-                       Assert.Equal (19, v6.Frame.Width); // 99*20%=19
+                       Assert.Equal (19, v6.Frame.Width);  // 99*20%=19
                        Assert.Equal (38, v6.Frame.Height); // 198-7*20=18
                    };
 

+ 8 - 0
UnitTests/View/ViewTests.cs

@@ -1166,7 +1166,11 @@ At 0,0
         // BUGBUG: IsInitialized must be true to process calculation
         r.BeginInit ();
         r.EndInit ();
+    #if DEBUG
         Assert.Equal ("View(Vertical View)(0,0,1,13)", r.ToString ());
+    #else
+        Assert.Equal ("View()(0,0,1,13)", r.ToString ());
+    #endif
         Assert.False (r.CanFocus);
         Assert.False (r.HasFocus);
         Assert.Equal (new Rect (0, 0, 1, 13), r.Bounds);
@@ -1174,7 +1178,11 @@ At 0,0
         Assert.Null (r.Focused);
         Assert.Null (r.ColorScheme);
         Assert.False (r.IsCurrentTop);
+    #if DEBUG
         Assert.Equal ("Vertical View", r.Id);
+    #else
+        Assert.Equal (string.Empty, r.Id);
+    #endif
         Assert.Empty (r.Subviews);
         Assert.False (r.WantContinuousButtonPressed);
         Assert.False (r.WantMousePositionReports);

+ 85 - 70
UnitTests/Views/WindowTests.cs

@@ -124,84 +124,99 @@ public class WindowTests
     public void New_Initializes ()
     {
         // Parameterless
-        var r = new Window ();
-        Assert.NotNull (r);
-        Assert.Equal (string.Empty, r.Title);
+        using var defaultWindow = new Window ();
+        Assert.NotNull (defaultWindow);
+        Assert.Equal (string.Empty, defaultWindow.Title);
 
         // Toplevels have Width/Height set to Dim.Fill
-        Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
+        Assert.Equal (LayoutStyle.Computed, defaultWindow.LayoutStyle);
 
         // If there's no SuperView, Top, or Driver, the default Fill width is int.MaxValue
-        Assert.Equal ("Window()(0,0,2147483647,2147483647)", r.ToString ());
-        Assert.True (r.CanFocus);
-        Assert.False (r.HasFocus);
-        Assert.Equal (new Rect (0, 0, 2147483645, 2147483645), r.Bounds);
-        Assert.Equal (new Rect (0, 0, 2147483647, 2147483647), r.Frame);
-        Assert.Null (r.Focused);
-        Assert.NotNull (r.ColorScheme);
-        Assert.Equal (0, r.X);
-        Assert.Equal (0, r.Y);
-        Assert.Equal (Dim.Fill (), r.Width);
-        Assert.Equal (Dim.Fill (), r.Height);
-        Assert.False (r.IsCurrentTop);
-        Assert.Empty (r.Id);
-        Assert.False (r.WantContinuousButtonPressed);
-        Assert.False (r.WantMousePositionReports);
-        Assert.Null (r.SuperView);
-        Assert.Null (r.MostFocused);
-        Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
+        Assert.Equal ("Window()(0,0,2147483647,2147483647)", defaultWindow.ToString ());
+        Assert.True (defaultWindow.CanFocus);
+        Assert.False (defaultWindow.HasFocus);
+        Assert.Equal (new Rect (0, 0, 2147483645, 2147483645), defaultWindow.Bounds);
+        Assert.Equal (new Rect (0, 0, 2147483647, 2147483647), defaultWindow.Frame);
+        Assert.Null (defaultWindow.Focused);
+        Assert.NotNull (defaultWindow.ColorScheme);
+        Assert.Equal (0, defaultWindow.X);
+        Assert.Equal (0, defaultWindow.Y);
+        Assert.Equal (Dim.Fill (), defaultWindow.Width);
+        Assert.Equal (Dim.Fill (), defaultWindow.Height);
+        Assert.False (defaultWindow.IsCurrentTop);
+        Assert.Empty (defaultWindow.Id);
+        Assert.False (defaultWindow.WantContinuousButtonPressed);
+        Assert.False (defaultWindow.WantMousePositionReports);
+        Assert.Null (defaultWindow.SuperView);
+        Assert.Null (defaultWindow.MostFocused);
+        Assert.Equal (TextDirection.LeftRight_TopBottom, defaultWindow.TextDirection);
 
         // Empty Rect
-        r = new Window { Frame = Rect.Empty, Title = "title" };
-        Assert.NotNull (r);
-        Assert.Equal ("title", r.Title);
-        Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
-        Assert.Equal ("title", r.Title);
-        Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
-        Assert.Equal ("Window(title)(0,0,0,0)", r.ToString ());
-        Assert.True (r.CanFocus);
-        Assert.False (r.HasFocus);
-        Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
-        Assert.Equal (new Rect (0, 0, 0, 0), r.Frame);
-        Assert.Null (r.Focused);
-        Assert.NotNull (r.ColorScheme);
-        Assert.Equal (0, r.X);
-        Assert.Equal (0, r.Y);
-        Assert.Equal (0, r.Width);
-        Assert.Equal (0, r.Height);
-        Assert.False (r.IsCurrentTop);
-        Assert.Equal (r.Title, r.Id);
-        Assert.False (r.WantContinuousButtonPressed);
-        Assert.False (r.WantMousePositionReports);
-        Assert.Null (r.SuperView);
-        Assert.Null (r.MostFocused);
-        Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
+        using var windowWithFrameRectEmpty = new Window { Frame = Rect.Empty, Title = "title" };
+        Assert.NotNull (windowWithFrameRectEmpty);
+        Assert.Equal ("title", windowWithFrameRectEmpty.Title);
+        Assert.Equal (LayoutStyle.Absolute, windowWithFrameRectEmpty.LayoutStyle);
+        Assert.Equal ("title", windowWithFrameRectEmpty.Title);
+        Assert.Equal (LayoutStyle.Absolute, windowWithFrameRectEmpty.LayoutStyle);
+        // TODO: Fix things so that this works in release and debug
+        // BUG: This also looks like it might be unintended behavior.
+    #if DEBUG
+        Assert.Equal ("Window(title)(0,0,0,0)", windowWithFrameRectEmpty.ToString ());
+    #else
+        Assert.Equal ("Window()(0,0,0,0)", windowWithFrameRectEmpty.ToString ());
+    #endif
+        Assert.True (windowWithFrameRectEmpty.CanFocus);
+        Assert.False (windowWithFrameRectEmpty.HasFocus);
+        Assert.Equal (new Rect (0, 0, 0, 0), windowWithFrameRectEmpty.Bounds);
+        Assert.Equal (new Rect (0, 0, 0, 0), windowWithFrameRectEmpty.Frame);
+        Assert.Null (windowWithFrameRectEmpty.Focused);
+        Assert.NotNull (windowWithFrameRectEmpty.ColorScheme);
+        Assert.Equal (0, windowWithFrameRectEmpty.X);
+        Assert.Equal (0, windowWithFrameRectEmpty.Y);
+        Assert.Equal (0, windowWithFrameRectEmpty.Width);
+        Assert.Equal (0, windowWithFrameRectEmpty.Height);
+        Assert.False (windowWithFrameRectEmpty.IsCurrentTop);
+    #if DEBUG
+        Assert.Equal (windowWithFrameRectEmpty.Title, windowWithFrameRectEmpty.Id);
+    #endif
+        Assert.False (windowWithFrameRectEmpty.WantContinuousButtonPressed);
+        Assert.False (windowWithFrameRectEmpty.WantMousePositionReports);
+        Assert.Null (windowWithFrameRectEmpty.SuperView);
+        Assert.Null (windowWithFrameRectEmpty.MostFocused);
+        Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrameRectEmpty.TextDirection);
 
         // Rect with values
-        r = new Window { Frame = new Rect (1, 2, 3, 4), Title = "title" };
-        Assert.Equal ("title", r.Title);
-        Assert.NotNull (r);
-        Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
-        Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
-        Assert.Equal ("Window(title)(1,2,3,4)", r.ToString ());
-        Assert.True (r.CanFocus);
-        Assert.False (r.HasFocus);
-        Assert.Equal (new Rect (0, 0, 1, 2), r.Bounds);
-        Assert.Equal (new Rect (1, 2, 3, 4), r.Frame);
-        Assert.Null (r.Focused);
-        Assert.NotNull (r.ColorScheme);
-        Assert.Equal (1, r.X);
-        Assert.Equal (2, r.Y);
-        Assert.Equal (3, r.Width);
-        Assert.Equal (4, r.Height);
-        Assert.False (r.IsCurrentTop);
-        Assert.Equal (r.Title, r.Id);
-        Assert.False (r.WantContinuousButtonPressed);
-        Assert.False (r.WantMousePositionReports);
-        Assert.Null (r.SuperView);
-        Assert.Null (r.MostFocused);
-        Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
-        r.Dispose ();
+        using var windowWithFrame1234 = new Window ( );
+        windowWithFrame1234.Frame = new  (1, 2, 3, 4);
+        windowWithFrame1234.Title = "title";
+        Assert.Equal ("title", windowWithFrame1234.Title);
+        Assert.NotNull (windowWithFrame1234);
+        Assert.Equal (LayoutStyle.Absolute, windowWithFrame1234.LayoutStyle);
+        Assert.Equal (LayoutStyle.Absolute, windowWithFrame1234.LayoutStyle);
+    #if DEBUG
+        Assert.Equal ("Window(title)(1,2,3,4)", windowWithFrame1234.ToString ());
+    #else
+        Assert.Equal ("Window()(1,2,3,4)", windowWithFrame1234.ToString ());
+    #endif
+        Assert.True (windowWithFrame1234.CanFocus);
+        Assert.False (windowWithFrame1234.HasFocus);
+        Assert.Equal (new Rect (0, 0, 1, 2), windowWithFrame1234.Bounds);
+        Assert.Equal (new Rect (1, 2, 3, 4), windowWithFrame1234.Frame);
+        Assert.Null (windowWithFrame1234.Focused);
+        Assert.NotNull (windowWithFrame1234.ColorScheme);
+        Assert.Equal (1, windowWithFrame1234.X);
+        Assert.Equal (2, windowWithFrame1234.Y);
+        Assert.Equal (3, windowWithFrame1234.Width);
+        Assert.Equal (4, windowWithFrame1234.Height);
+        Assert.False (windowWithFrame1234.IsCurrentTop);
+    #if DEBUG
+        Assert.Equal (windowWithFrame1234.Title, windowWithFrame1234.Id);
+    #endif
+        Assert.False (windowWithFrame1234.WantContinuousButtonPressed);
+        Assert.False (windowWithFrame1234.WantMousePositionReports);
+        Assert.Null (windowWithFrame1234.SuperView);
+        Assert.Null (windowWithFrame1234.MostFocused);
+        Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrame1234.TextDirection);
     }
 
     [Fact]