Browse Source

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

Brandon Thetford 1 year ago
parent
commit
142b621395
62 changed files with 343 additions and 343 deletions
  1. 25 25
      Terminal.Gui/Application.cs
  2. 5 5
      Terminal.Gui/Configuration/ConfigProperty.cs
  3. 3 3
      Terminal.Gui/Configuration/ConfigurationManager.cs
  4. 1 1
      Terminal.Gui/Configuration/KeyCodeJsonConverter.cs
  5. 1 1
      Terminal.Gui/Configuration/Scope.cs
  6. 5 5
      Terminal.Gui/Configuration/ScopeJsonConverter.cs
  7. 1 1
      Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
  8. 7 7
      Terminal.Gui/ConsoleDrivers/ConsoleKeyMapping.cs
  9. 1 1
      Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
  10. 4 4
      Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqReq.cs
  11. 4 4
      Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs
  12. 2 2
      Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
  13. 2 2
      Terminal.Gui/ConsoleDrivers/NetDriver.cs
  14. 10 10
      Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
  15. 1 1
      Terminal.Gui/Drawing/ColorScheme.cs
  16. 5 5
      Terminal.Gui/Drawing/LineCanvas.cs
  17. 2 2
      Terminal.Gui/FileServices/FileDialogHistory.cs
  18. 2 2
      Terminal.Gui/FileServices/FileDialogState.cs
  19. 1 1
      Terminal.Gui/RunState.cs
  20. 4 4
      Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs
  21. 3 3
      Terminal.Gui/Text/TextFormatter.cs
  22. 1 1
      Terminal.Gui/View/Adornment/Adornment.cs
  23. 3 3
      Terminal.Gui/View/Adornment/Border.cs
  24. 1 1
      Terminal.Gui/View/Adornment/Margin.cs
  25. 1 1
      Terminal.Gui/View/Adornment/Padding.cs
  26. 1 1
      Terminal.Gui/View/Layout/PosDim.cs
  27. 12 12
      Terminal.Gui/View/Layout/ViewLayout.cs
  28. 3 3
      Terminal.Gui/View/View.cs
  29. 6 6
      Terminal.Gui/View/ViewDrawing.cs
  30. 5 5
      Terminal.Gui/View/ViewKeyboard.cs
  31. 1 1
      Terminal.Gui/View/ViewMouse.cs
  32. 14 14
      Terminal.Gui/View/ViewSubViews.cs
  33. 2 2
      Terminal.Gui/View/ViewText.cs
  34. 5 5
      Terminal.Gui/Views/ComboBox.cs
  35. 13 13
      Terminal.Gui/Views/FileDialog.cs
  36. 2 2
      Terminal.Gui/Views/GraphView/Series.cs
  37. 1 1
      Terminal.Gui/Views/HexView.cs
  38. 1 1
      Terminal.Gui/Views/Label.cs
  39. 4 4
      Terminal.Gui/Views/ListView.cs
  40. 4 4
      Terminal.Gui/Views/Menu/ContextMenu.cs
  41. 15 15
      Terminal.Gui/Views/Menu/Menu.cs
  42. 34 34
      Terminal.Gui/Views/Menu/MenuBar.cs
  43. 1 1
      Terminal.Gui/Views/MessageBox.cs
  44. 24 24
      Terminal.Gui/Views/ScrollBarView.cs
  45. 2 2
      Terminal.Gui/Views/ScrollView.cs
  46. 1 1
      Terminal.Gui/Views/Slider.cs
  47. 2 2
      Terminal.Gui/Views/SpinnerView/SpinnerView.cs
  48. 2 2
      Terminal.Gui/Views/StatusBar.cs
  49. 9 9
      Terminal.Gui/Views/TabView.cs
  50. 2 2
      Terminal.Gui/Views/TableView/ColumnStyle.cs
  51. 8 8
      Terminal.Gui/Views/TableView/TableView.cs
  52. 1 1
      Terminal.Gui/Views/TableView/TreeTableSource.cs
  53. 2 2
      Terminal.Gui/Views/TextField.cs
  54. 1 1
      Terminal.Gui/Views/TextValidateField.cs
  55. 25 25
      Terminal.Gui/Views/TextView.cs
  56. 3 3
      Terminal.Gui/Views/TileView.cs
  57. 8 8
      Terminal.Gui/Views/Toplevel.cs
  58. 9 9
      Terminal.Gui/Views/ToplevelOverlapped.cs
  59. 7 7
      Terminal.Gui/Views/TreeView/Branch.cs
  60. 8 8
      Terminal.Gui/Views/TreeView/TreeView.cs
  61. 9 9
      Terminal.Gui/Views/Wizard/Wizard.cs
  62. 1 1
      Terminal.Gui/Views/Wizard/WizardStep.cs

+ 25 - 25
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;
@@ -216,7 +216,7 @@ public static partial class Application
         }
 
         // For UnitTests
-        if (driver != null)
+        if (driver is { })
         {
             Driver = driver;
         }
@@ -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);
                 }
@@ -382,7 +382,7 @@ public static partial class Application
             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 ();
@@ -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 ();
@@ -885,7 +885,7 @@ public static partial class Application
     /// </remarks>
     public static void RequestStop (Toplevel top = null)
     {
-        if (OverlappedTop is null || top is null || (OverlappedTop is null && top != null))
+        if (OverlappedTop is null || top is null || (OverlappedTop is null && top is { }))
         {
             top = Current;
         }
@@ -1016,7 +1016,7 @@ public static partial class Application
             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)
             {
@@ -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.
@@ -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
@@ -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;
                     }

+ 5 - 5
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;
@@ -103,7 +103,7 @@ public class ConfigProperty
 
         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);
         }

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

@@ -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));
@@ -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")

+ 1 - 1
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);
 

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

@@ -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,
@@ -561,7 +561,7 @@ public static class ConsoleKeyMapping
             scode = GetScanCode ("VirtualKey", decodedChar, mod);
         }
 
-        if (isConsoleKey && scode != null)
+        if (isConsoleKey && scode is { })
         {
             consoleKey = (uint)scode.VirtualKey;
             keyChar = scode.UnicodeChar;
@@ -572,7 +572,7 @@ public static class ConsoleKeyMapping
         {
             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;
             }

+ 1 - 1
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);
         }

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

@@ -52,7 +52,7 @@ public class EscSeqRequests
             {
                 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);
             }
@@ -76,7 +76,7 @@ public class EscSeqRequests
                 return false;
             }
 
-            if (found != null && found.NumOutstanding > 0)
+            if (found is { } && found.NumOutstanding > 0)
             {
                 return true;
             }
@@ -107,11 +107,11 @@ public class EscSeqRequests
                 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--;
 

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

@@ -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);
@@ -867,7 +867,7 @@ public static class EscSeqUtils
                  || buttonState == MouseFlags.Button3Pressed
                  || buttonState == MouseFlags.Button4Pressed)
              && lastMouseButtonPressed is null)
-            || (isButtonPressed && lastMouseButtonPressed != null && buttonState.HasFlag (MouseFlags.ReportMousePosition)))
+            || (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
                     {
@@ -1237,7 +1237,7 @@ public static class EscSeqUtils
                 break;
             }
 
-            if (isButtonPressed && lastMouseButtonPressed != null && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
+            if (isButtonPressed && lastMouseButtonPressed is { } && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
             {
                 Application.Invoke (() => continuousButtonPressedHandler (mouseFlag, point ?? Point.Empty));
             }

+ 2 - 2
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;
             }
@@ -528,7 +528,7 @@ public class FakeDriver : ConsoleDriver
                 throw new ArgumentNullException (nameof (text));
             }
 
-            if (FakeException != null)
+            if (FakeException is { })
             {
                 throw FakeException;
             }

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

@@ -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;
@@ -1727,7 +1727,7 @@ internal class NetMainLoop : IMainLoopDriver
 
     private void NetInputHandler ()
     {
-        while (_mainLoop != null)
+        while (_mainLoop is { })
         {
             try
             {

+ 10 - 10
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)
         {
@@ -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);
         }
@@ -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
@@ -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;
 
@@ -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 _);

+ 1 - 1
Terminal.Gui/Drawing/ColorScheme.cs

@@ -215,7 +215,7 @@ public static class Colors
     {
         public bool Equals (string x, string y)
         {
-            if (x != null && y != null)
+            if (x is { } && y is { })
             {
                 return string.Equals (x, y, StringComparison.InvariantCultureIgnoreCase);
             }

+ 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/FileServices/FileDialogHistory.cs

@@ -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);
         }
@@ -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/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"

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

@@ -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;
@@ -467,7 +467,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
         {
             SelectedIdx = me.Y - ScrollOffset;
 
-            if (LastPopupPos != null)
+            if (LastPopupPos is { })
             {
                 RenderOverlay ((Point)LastPopupPos);
             }
@@ -522,7 +522,7 @@ public abstract class PopupAutocomplete : AutocompleteBase
             top?.Add (popup);
         }
 
-        if (!Visible && popup != null)
+        if (!Visible && popup is { })
         {
             top?.Remove (popup);
             popup.Dispose ();

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

@@ -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
@@ -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)
@@ -618,7 +618,7 @@ public class TextFormatter
 
                             int foundIdx = lastZeroWidthPos.IndexOf (
                                                                      p =>
-                                                                         p != null && p.Value.Y == current
+                                                                         p is { } && p.Value.Y == current
                                                                     );
 
                             if (foundIdx == -1)

+ 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;
             }

+ 1 - 1
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 ();
         }

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

@@ -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;
@@ -563,7 +563,7 @@ public partial class View
 
         Rect startFrame = start.Frame;
 
-        if (start.InternalSubviews != null)
+        if (start.InternalSubviews is { })
         {
             int count = start.InternalSubviews.Count;
 
@@ -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);
@@ -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;
@@ -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 ())
                 {

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

@@ -157,7 +157,7 @@ public partial class View : Responder, ISupportInitializeNotification
                 OnEnabledChanged ();
                 SetNeedsDisplay ();
 
-                if (_subviews != null)
+                if (_subviews is { })
                 {
                     foreach (View view in _subviews)
                     {
@@ -198,7 +198,7 @@ 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;
                 }
@@ -438,7 +438,7 @@ public partial class View : Responder, ISupportInitializeNotification
 
         OnResizeNeeded ();
 
-        if (_subviews != null)
+        if (_subviews is { })
         {
             foreach (View view in _subviews)
             {

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

@@ -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;
         }
@@ -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
@@ -566,7 +566,7 @@ public partial class View
     {
         SubViewNeedsDisplay = true;
 
-        if (_superView != null && !_superView.SubViewNeedsDisplay)
+        if (_superView is { } && !_superView.SubViewNeedsDisplay)
         {
             _superView.SetSubViewNeedsDisplay ();
         }

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

@@ -199,7 +199,7 @@ public partial class View
     {
         get
         {
-            if (TextFormatter != null)
+            if (TextFormatter is { })
             {
                 return TextFormatter.HotKeySpecifier;
             }
@@ -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 ();

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

@@ -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 is null)
+                    if (SuperView is { } && SuperView.Focused is null)
                     {
                         SuperView.FocusNext ();
 
-                        if (SuperView.Focused is 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)
                     {
@@ -506,7 +506,7 @@ public partial class View
 
             View most = Focused.MostFocused;
 
-            if (most != null)
+            if (most is { })
             {
                 return most;
             }
@@ -561,7 +561,7 @@ public partial class View
             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);
         }
@@ -737,7 +737,7 @@ public partial class View
             }
         }
 
-        if (Focused != null)
+        if (Focused is { })
         {
             Focused.SetHasFocus (false, this);
             Focused = null;
@@ -802,7 +802,7 @@ public partial class View
             }
         }
 
-        if (Focused != null)
+        if (Focused is { })
         {
             Focused.SetHasFocus (false, this);
             Focused = null;
@@ -818,7 +818,7 @@ public partial class View
             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 is null && SuperView != null)
+        if (Focused is null && SuperView is { })
         {
             SuperView.EnsureFocus ();
         }

+ 2 - 2
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;
         }

+ 5 - 5
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 = "";
@@ -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);

+ 13 - 13
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 ();
         }
@@ -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);
@@ -1469,7 +1469,7 @@ public class FileDialog : Dialog
             return true;
         }
 
-        if (reason != null)
+        if (reason is { })
         {
             _feedback = reason;
             SetNeedsDisplay ();

+ 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];
             }

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

@@ -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)
                 {

+ 4 - 4
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++)
@@ -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);
@@ -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; }

+ 4 - 4
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);

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

@@ -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;
@@ -501,7 +501,7 @@ internal sealed class Menu : View
             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;
 
@@ -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;
         }
@@ -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;
@@ -828,13 +828,13 @@ internal sealed class Menu : View
                 {
                     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);
                 }
@@ -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
                     {
@@ -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)
             {
@@ -1283,11 +1283,11 @@ internal sealed class Menu : View
 
         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;

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

@@ -58,7 +58,7 @@ public class MenuBarItem : MenuItem
     {
         var i = 0;
 
-        if (Children != null)
+        if (Children is { })
         {
             foreach (MenuItem child in Children)
             {
@@ -102,7 +102,7 @@ public class MenuBarItem : MenuItem
             return;
         }
 
-        foreach (MenuItem menuItem in Children.Where (m => m != null))
+        foreach (MenuItem menuItem in Children.Where (m => m is { }))
         {
             if (menuItem.HotKey != default (Rune))
             {
@@ -136,7 +136,7 @@ public class MenuBarItem : MenuItem
 
         SetTitle (title ?? "");
 
-        if (parent != null)
+        if (parent is { })
         {
             Parent = parent;
         }
@@ -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;
         }
@@ -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 ();
@@ -939,7 +939,7 @@ public class MenuBar : View
 
                     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;
         }
@@ -1002,12 +1002,12 @@ public class MenuBar : View
                 // Open a submenu below a MenuBar
                 _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 ();
@@ -1029,7 +1029,7 @@ public class MenuBar : View
                     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;
@@ -1176,7 +1176,7 @@ public class MenuBar : View
 
     internal void RemoveAllOpensSubMenus ()
     {
-        if (_openSubMenu != null)
+        if (_openSubMenu is { })
         {
             foreach (Menu item in _openSubMenu)
             {
@@ -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 ();
             }
@@ -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)
                     {

+ 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)
             {

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

@@ -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."
@@ -311,7 +311,7 @@ public class ScrollBarView : View
         {
             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 ();
@@ -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;
     //	}
     //}
@@ -819,7 +819,7 @@ public class ScrollBarView : View
 
         if (Host != null
             && ((_contentBottomRightCorner is null && OtherScrollBarView is null)
-                || (_contentBottomRightCorner is null && OtherScrollBarView != null && OtherScrollBarView._contentBottomRightCorner 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;
             }
@@ -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 ();
         }

+ 2 - 2
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;
         }
@@ -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 ();
         }

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

@@ -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)

+ 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;

+ 2 - 2
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 ())
             {

+ 9 - 9
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);
                 }
@@ -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 ();

+ 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);
         }

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

@@ -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)
@@ -1591,7 +1591,7 @@ public class TableView : View
             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 (

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

@@ -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 is null || headerIfAny != null || !IsInTreeColumn (hit.Value.X, false) || offsetX is null)
+        if (hit is null || headerIfAny is { } || !IsInTreeColumn (hit.Value.X, false) || offsetX is null)
         {
             return;
         }

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

@@ -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 ();
         }
@@ -1840,7 +1840,7 @@ public class TextField : View
 
             SetNeedsDisplay ();
         }
-        else if (SelectedLength > 0 || _selectedText != null)
+        else if (SelectedLength > 0 || _selectedText is { })
         {
             ClearAllSelection ();
         }

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

@@ -365,7 +365,7 @@ namespace Terminal.Gui
 
             private void SetupText ()
             {
-                if (_text != null && IsValid)
+                if (_text is { } && IsValid)
                 {
                     return;
                 }

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

@@ -296,7 +296,7 @@ internal class TextModel
             RuneCell? cell = RuneAt (col, row);
             Rune rune;
 
-            if (cell != null)
+            if (cell is { })
             {
                 rune = cell.Rune;
             }
@@ -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;
             }
@@ -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 ();
         }
@@ -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!);
@@ -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--)
             {
@@ -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];
 
@@ -5820,7 +5820,7 @@ public class TextView : View
             }
         }
 
-        if (cell.ColorScheme != null && colWithColor > -1 && colWithoutColor < lineToSet.Count && lineToSet [colWithoutColor].ColorScheme is null)
+        if (cell.ColorScheme is { } && colWithColor > -1 && colWithoutColor < lineToSet.Count && lineToSet [colWithoutColor].ColorScheme is null)
         {
             while (lineToSet [colWithoutColor].ColorScheme is null)
             {
@@ -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;
         }
@@ -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);
 

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

@@ -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);
             //}
@@ -490,12 +490,12 @@ 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 is 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*/)
@@ -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);
         }
@@ -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;
         }
@@ -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;
         }
@@ -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;
                 }
@@ -1074,7 +1074,7 @@ public partial class Toplevel : View
 
     private void QuitToplevel ()
     {
-        if (Application.OverlappedTop != null)
+        if (Application.OverlappedTop is { })
         {
             Application.OverlappedTop.RequestStop ();
         }

+ 9 - 9
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);
         }
@@ -84,12 +84,12 @@ public static partial class Application
 
         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)
             {

+ 7 - 7
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;
@@ -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;
@@ -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;
 

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

@@ -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 ();
@@ -815,7 +815,7 @@ public class TreeView<T> : View, ITreeView where T : class
         }
         else
         {
-            if (SelectedObject != null)
+            if (SelectedObject is { })
             {
                 yield return SelectedObject;
             }
@@ -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 ();
@@ -1391,7 +1391,7 @@ public class TreeView<T> : View, ITreeView where T : class
             branch.Collapse ();
         }
 
-        if (SelectedObject != null && ObjectToBranch (SelectedObject) is 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));
         }

+ 9 - 9
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;
                 }
@@ -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)
             {
@@ -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;
         }

+ 1 - 1
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;
         //	}