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

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

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

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

The members they depend on do not exist in Release configuration

* Split these up and dispose properly

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

* Fix release configuration tests

* Declare interface these already support

* Annotate constructor properly and use throw helper

* Move class to its own file

* Rename these files so they nest in the solution explorer

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

* Reference passing to avoid some struct copies

* Simplify this

* Carry reference passing through as appropriate

* Turn this into a record struct

* Remove unused internal constructor and its test

It was only used by that test.

* Simplify this constructor

* This should be a property

* Simplify constructor

* Simplify GetHashCode

* Mark this ignored just in case

* Missed a couple of opportunities for reference passing

* record struct already does this by value

* Remove unused class

* Simplify the type initializer and Reset method

* Implement INotifyCollectionChanged and IDictionary by delegating to ColorSchemes

* Fix for reflection-based configuration

* Make CI  build happy by disambiguiating this attribute
This commit is contained in:
dodexahedron
2024-02-16 16:46:25 -07:00
committed by GitHub
parent 7a041fcc73
commit 34bef2c839
94 changed files with 1020 additions and 966 deletions

View File

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