Forráskód Böngészése

Fixed nullable warnings 7

Tig 1 éve
szülő
commit
022050db73

+ 1 - 1
CommunityToolkitExample/Program.cs

@@ -12,7 +12,7 @@ public static class Program
         Services = ConfigureServices ();
         Application.Init ();
         Application.Run (Services.GetRequiredService<LoginView> ());
-        Application.Top.Dispose();
+        Application.Top?.Dispose();
         Application.Shutdown ();
     }
 

+ 9 - 8
Terminal.Gui/Application/Application.Initialization.cs

@@ -38,8 +38,8 @@ public static partial class Application // Initialization (Init/Shutdown)
     [RequiresDynamicCode ("AOT")]
     public static void Init (ConsoleDriver? driver = null, string? driverName = null) { InternalInit (driver, driverName); }
 
-    internal static bool _initialized;
-    internal static int _mainThreadId = -1;
+    internal static bool IsInitialized { get; set; }
+    internal static int MainThreadId { get; set; } = -1;
 
     // INTERNAL function for initializing an app with a Toplevel factory object, driver, and mainloop.
     //
@@ -58,12 +58,12 @@ public static partial class Application // Initialization (Init/Shutdown)
         bool calledViaRunT = false
     )
     {
-        if (_initialized && driver is null)
+        if (IsInitialized && driver is null)
         {
             return;
         }
 
-        if (_initialized)
+        if (IsInitialized)
         {
             throw new InvalidOperationException ("Init has already been called and must be bracketed by Shutdown.");
         }
@@ -154,9 +154,9 @@ public static partial class Application // Initialization (Init/Shutdown)
         SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext ());
 
         SupportedCultures = GetSupportedCultures ();
-        _mainThreadId = Thread.CurrentThread.ManagedThreadId;
-        _initialized = true;
-        InitializedChanged?.Invoke (null, new (in _initialized));
+        MainThreadId = Thread.CurrentThread.ManagedThreadId;
+        bool init = IsInitialized = true;
+        InitializedChanged?.Invoke (null, new (init));
     }
 
     private static void Driver_SizeChanged (object? sender, SizeChangedEventArgs e) { OnSizeChanging (e); }
@@ -198,7 +198,8 @@ public static partial class Application // Initialization (Init/Shutdown)
         // TODO: Throw an exception if Init hasn't been called.
         ResetState ();
         PrintJsonErrors ();
-        InitializedChanged?.Invoke (null, new (in _initialized));
+        bool init = IsInitialized;
+        InitializedChanged?.Invoke (null, new (in init));
     }
 
     /// <summary>

+ 2 - 2
Terminal.Gui/Application/Application.Keyboard.cs

@@ -110,7 +110,7 @@ public static partial class Application // Keyboard handling
     /// <returns><see langword="true"/> if the key was handled.</returns>
     public static bool OnKeyDown (Key keyEvent)
     {
-        if (!_initialized)
+        if (!IsInitialized)
         {
             return true;
         }
@@ -210,7 +210,7 @@ public static partial class Application // Keyboard handling
     /// <returns><see langword="true"/> if the key was handled.</returns>
     public static bool OnKeyUp (Key a)
     {
-        if (!_initialized)
+        if (!IsInitialized)
         {
             return true;
         }

+ 11 - 11
Terminal.Gui/Application/Application.Mouse.cs

@@ -64,7 +64,7 @@ public static partial class Application // Mouse handling
         }
     }
 
-    private static bool OnGrabbingMouse (View view)
+    private static bool OnGrabbingMouse (View? view)
     {
         if (view is null)
         {
@@ -77,7 +77,7 @@ public static partial class Application // Mouse handling
         return evArgs.Cancel;
     }
 
-    private static bool OnUnGrabbingMouse (View view)
+    private static bool OnUnGrabbingMouse (View? view)
     {
         if (view is null)
         {
@@ -90,7 +90,7 @@ public static partial class Application // Mouse handling
         return evArgs.Cancel;
     }
 
-    private static void OnGrabbedMouse (View view)
+    private static void OnGrabbedMouse (View? view)
     {
         if (view is null)
         {
@@ -100,7 +100,7 @@ public static partial class Application // Mouse handling
         GrabbedMouse?.Invoke (view, new (view));
     }
 
-    private static void OnUnGrabbedMouse (View view)
+    private static void OnUnGrabbedMouse (View? view)
     {
         if (view is null)
         {
@@ -113,7 +113,7 @@ public static partial class Application // Mouse handling
 #nullable enable
 
     // Used by OnMouseEvent to track the last view that was clicked on.
-    internal static View? _mouseEnteredView;
+    internal static View? MouseEnteredView { get; set; }
 
     /// <summary>Event fired when a mouse move or click occurs. Coordinates are screen relative.</summary>
     /// <remarks>
@@ -166,7 +166,7 @@ public static partial class Application // Mouse handling
             if ((MouseGrabView.Viewport with { Location = Point.Empty }).Contains (viewRelativeMouseEvent.Position) is false)
             {
                 // The mouse has moved outside the bounds of the view that grabbed the mouse
-                _mouseEnteredView?.NewMouseLeaveEvent (mouseEvent);
+                MouseEnteredView?.NewMouseLeaveEvent (mouseEvent);
             }
 
             //System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}");
@@ -242,16 +242,16 @@ public static partial class Application // Mouse handling
             return;
         }
 
-        if (_mouseEnteredView is null)
+        if (MouseEnteredView is null)
         {
-            _mouseEnteredView = view;
+            MouseEnteredView = view;
             view.NewMouseEnterEvent (me);
         }
-        else if (_mouseEnteredView != view)
+        else if (MouseEnteredView != view)
         {
-            _mouseEnteredView.NewMouseLeaveEvent (me);
+            MouseEnteredView.NewMouseLeaveEvent (me);
             view.NewMouseEnterEvent (me);
-            _mouseEnteredView = view;
+            MouseEnteredView = view;
         }
 
         if (!view.WantMousePositionReports && mouseEvent.Flags == MouseFlags.ReportMousePosition)

+ 176 - 21
Terminal.Gui/Application/Application.Navigation.cs

@@ -1,3 +1,4 @@
+#nullable enable
 namespace Terminal.Gui;
 
 public static partial class Application
@@ -6,30 +7,32 @@ public static partial class Application
     ///     Gets the list of the Overlapped children which are not modal <see cref="Toplevel"/> from the
     ///     <see cref="OverlappedTop"/>.
     /// </summary>
-    public static List<Toplevel> OverlappedChildren
+    public static List<Toplevel>? OverlappedChildren
     {
         get
         {
             if (OverlappedTop is { })
             {
-                List<Toplevel> _overlappedChildren = new ();
+                List<Toplevel> overlappedChildren = new ();
 
-                foreach (Toplevel top in _topLevels)
+                lock (_topLevels)
                 {
-                    if (top != OverlappedTop && !top.Modal)
+                    foreach (Toplevel top in _topLevels)
                     {
-                        _overlappedChildren.Add (top);
+                        if (top != OverlappedTop && !top.Modal)
+                        {
+                            overlappedChildren.Add (top);
+                        }
                     }
                 }
 
-                return _overlappedChildren;
+                return overlappedChildren;
             }
 
             return null;
         }
     }
 
-#nullable enable
     /// <summary>
     ///     The <see cref="Toplevel"/> object used for the application on startup which
     ///     <see cref="Toplevel.IsOverlappedContainer"/> is true.
@@ -46,7 +49,6 @@ public static partial class Application
             return null;
         }
     }
-#nullable restore
 
     /// <summary>Brings the superview of the most focused overlapped view is on front.</summary>
     public static void BringOverlappedTopToFront ()
@@ -56,9 +58,9 @@ public static partial class Application
             return;
         }
 
-        View top = FindTopFromView (Top?.MostFocused);
+        View? top = FindTopFromView (Top?.MostFocused);
 
-        if (top is Toplevel && Top.Subviews.Count > 1 && Top.Subviews [^1] != top)
+        if (top is Toplevel && Top?.Subviews.Count > 1 && Top.Subviews [^1] != top)
         {
             Top.BringSubviewToFront (top);
         }
@@ -68,9 +70,9 @@ public static partial class Application
     /// <param name="type">The type.</param>
     /// <param name="exclude">The strings to exclude.</param>
     /// <returns>The matched view.</returns>
-    public static Toplevel GetTopOverlappedChild (Type type = null, string [] exclude = null)
+    public static Toplevel? GetTopOverlappedChild (Type? type = null, string []? exclude = null)
     {
-        if (OverlappedTop is null)
+        if (OverlappedChildren is null || OverlappedTop is null)
         {
             return null;
         }
@@ -118,7 +120,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 is { } && !Current.Modal)
+        if (OverlappedTop is { } && !Current!.Modal)
         {
             lock (_topLevels)
             {
@@ -133,7 +135,7 @@ public static partial class Application
                     }
                     else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
                     {
-                        MoveCurrent (Top);
+                        MoveCurrent (Top!);
 
                         break;
                     }
@@ -149,7 +151,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 is { } && !Current.Modal)
+        if (OverlappedTop is { } && !Current!.Modal)
         {
             lock (_topLevels)
             {
@@ -164,7 +166,7 @@ public static partial class Application
                     }
                     else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
                     {
-                        MoveCurrent (Top);
+                        MoveCurrent (Top!);
 
                         break;
                     }
@@ -184,13 +186,16 @@ public static partial class Application
             return false;
         }
 
-        foreach (Toplevel top in _topLevels)
+        lock (_topLevels)
         {
-            if (top != Current && top.Visible && (top.NeedsDisplay || top.SubViewNeedsDisplay || top.LayoutNeeded))
+            foreach (Toplevel top in _topLevels)
             {
-                OverlappedTop.SetSubViewNeedsDisplay ();
+                if (top != Current && top.Visible && (top.NeedsDisplay || top.SubViewNeedsDisplay || top.LayoutNeeded))
+                {
+                    OverlappedTop.SetSubViewNeedsDisplay ();
 
-                return true;
+                    return true;
+                }
             }
         }
 
@@ -208,4 +213,154 @@ public static partial class Application
 
         return false;
     }
-}
+
+    /// <summary>
+    ///     Finds the first Toplevel in the stack that is Visible and who's Frame contains the <paramref name="location"/>.
+    /// </summary>
+    /// <param name="start"></param>
+    /// <param name="location"></param>
+    /// <returns></returns>
+    private static Toplevel? FindDeepestTop (Toplevel start, in Point location)
+    {
+        if (!start.Frame.Contains (location))
+        {
+            return null;
+        }
+
+        lock (_topLevels)
+        {
+            if (_topLevels is not { Count: > 0 })
+            {
+                return start;
+            }
+
+            int rx = location.X - start.Frame.X;
+            int ry = location.Y - start.Frame.Y;
+
+            foreach (Toplevel t in _topLevels)
+            {
+                if (t == Current)
+                {
+                    continue;
+                }
+
+                if (t != start && t.Visible && t.Frame.Contains (rx, ry))
+                {
+                    start = t;
+
+                    break;
+                }
+            }
+        }
+
+        return start;
+    }
+
+    /// <summary>
+    ///     Given <paramref name="view"/>, returns the first Superview up the chain that is <see cref="Top"/>.
+    /// </summary>
+    private static View? FindTopFromView (View? view)
+    {
+        if (view is null)
+        {
+            return null;
+        }
+
+        View top = view.SuperView is { } && view.SuperView != Top
+                       ? view.SuperView
+                       : view;
+
+        while (top?.SuperView is { } && top?.SuperView != Top)
+        {
+            top = top!.SuperView;
+        }
+
+        return top;
+    }
+
+    /// <summary>
+    ///     If the <see cref="Current"/> is not the <paramref name="top"/> then <paramref name="top"/> is moved to the top of
+    ///     the Toplevel stack and made Current.
+    /// </summary>
+    /// <param name="top"></param>
+    /// <returns></returns>
+    private static bool MoveCurrent (Toplevel top)
+    {
+        // The Current is modal and the top is not modal Toplevel then
+        // the Current must be moved above the first not modal Toplevel.
+        if (OverlappedTop is { }
+            && top != OverlappedTop
+            && top != Current
+            && Current?.Modal == true
+            && !_topLevels.Peek ().Modal)
+        {
+            lock (_topLevels)
+            {
+                _topLevels.MoveTo (Current, 0, new ToplevelEqualityComparer ());
+            }
+
+            var index = 0;
+            Toplevel [] savedToplevels = _topLevels.ToArray ();
+
+            foreach (Toplevel t in savedToplevels)
+            {
+                if (!t!.Modal && t != Current && t != top && t != savedToplevels [index])
+                {
+                    lock (_topLevels)
+                    {
+                        _topLevels.MoveTo (top, index, new ToplevelEqualityComparer ());
+                    }
+                }
+
+                index++;
+            }
+
+            return false;
+        }
+
+        // The Current and the top are both not running Toplevel then
+        // the top must be moved above the first not running Toplevel.
+        if (OverlappedTop is { }
+            && top != OverlappedTop
+            && top != Current
+            && Current?.Running == false
+            && top?.Running == false)
+        {
+            lock (_topLevels)
+            {
+                _topLevels.MoveTo (Current, 0, new ToplevelEqualityComparer ());
+            }
+
+            var index = 0;
+
+            foreach (Toplevel t in _topLevels.ToArray ())
+            {
+                if (!t.Running && t != Current && index > 0)
+                {
+                    lock (_topLevels)
+                    {
+                        _topLevels.MoveTo (top, index - 1, new ToplevelEqualityComparer ());
+                    }
+                }
+
+                index++;
+            }
+
+            return false;
+        }
+
+        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)
+            {
+                _topLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
+                Current = top;
+            }
+        }
+
+        return true;
+    }
+}

+ 3 - 3
Terminal.Gui/Application/Application.Run.cs

@@ -333,7 +333,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
     public static T Run<T> (Func<Exception, bool>? errorHandler = null, ConsoleDriver? driver = null)
         where T : Toplevel, new ()
     {
-        if (!_initialized)
+        if (!IsInitialized)
         {
             // Init() has NOT been called.
             InternalInit (driver, null, true);
@@ -388,7 +388,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
     {
         ArgumentNullException.ThrowIfNull (view);
 
-        if (_initialized)
+        if (IsInitialized)
         {
             if (Driver is null)
             {
@@ -824,7 +824,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         }
         else
         {
-            if (_topLevels.Count > 1 && _topLevels.Peek () == OverlappedTop && OverlappedChildren.Any (t => t.Visible) is { })
+            if (_topLevels.Count > 1 && _topLevels.Peek () == OverlappedTop && OverlappedChildren?.Any (t => t.Visible) != null)
             {
                 OverlappedMoveNext ();
             }

+ 0 - 142
Terminal.Gui/Application/Application.Toplevel.cs

@@ -53,148 +53,6 @@ public static partial class Application // Toplevel handling
         }
     }
 
-    /// <summary>
-    ///    Finds the first Toplevel in the stack that is Visible and who's Frame contains the <paramref name="location"/>.
-    /// </summary>
-    /// <param name="start"></param>
-    /// <param name="location"></param>
-    /// <returns></returns>
-    private static Toplevel? FindDeepestTop (Toplevel start, in Point location)
-    {
-        if (!start.Frame.Contains (location))
-        {
-            return null;
-        }
-
-        if (_topLevels is { Count: > 0 })
-        {
-            int rx = location.X - start.Frame.X;
-            int ry = location.Y - start.Frame.Y;
-
-            foreach (Toplevel t in _topLevels)
-            {
-                if (t != Current)
-                {
-                    if (t != start && t.Visible && t.Frame.Contains (rx, ry))
-                    {
-                        start = t;
-
-                        break;
-                    }
-                }
-            }
-        }
-
-        return start;
-    }
-
-    /// <summary>
-    /// Given <paramref name="view"/>, returns the first Superview up the chain that is <see cref="Top"/>.
-    /// </summary>
-    private static View? FindTopFromView (View? view)
-    {
-        if (view is null)
-        {
-            return null;
-        }
-
-        View top = view.SuperView is { } && view.SuperView != Top
-                       ? view.SuperView
-                       : view;
-
-        while (top?.SuperView is { } && top?.SuperView != Top)
-        {
-            top = top!.SuperView;
-        }
-
-        return top;
-    }
-
-    /// <summary>
-    ///    If the <see cref="Current"/> is not the <paramref name="top"/> then <paramref name="top"/> is moved to the top of the Toplevel stack and made Current.
-    /// </summary>
-    /// <param name="top"></param>
-    /// <returns></returns>
-    private static bool MoveCurrent (Toplevel top)
-    {
-        // The Current is modal and the top is not modal Toplevel then
-        // the Current must be moved above the first not modal Toplevel.
-        if (OverlappedTop is { }
-            && top != OverlappedTop
-            && top != Current
-            && Current?.Modal == true
-            && !_topLevels.Peek ().Modal)
-        {
-            lock (_topLevels)
-            {
-                _topLevels.MoveTo (Current, 0, new ToplevelEqualityComparer ());
-            }
-
-            var index = 0;
-            Toplevel [] savedToplevels = _topLevels.ToArray ();
-
-            foreach (Toplevel t in savedToplevels)
-            {
-                if (!t!.Modal && t != Current && t != top && t != savedToplevels [index])
-                {
-                    lock (_topLevels)
-                    {
-                        _topLevels.MoveTo (top, index, new ToplevelEqualityComparer ());
-                    }
-                }
-
-                index++;
-            }
-
-            return false;
-        }
-
-        // The Current and the top are both not running Toplevel then
-        // the top must be moved above the first not running Toplevel.
-        if (OverlappedTop is { }
-            && top != OverlappedTop
-            && top != Current
-            && Current?.Running == false
-            && top?.Running == false)
-        {
-            lock (_topLevels)
-            {
-                _topLevels.MoveTo (Current, 0, new ToplevelEqualityComparer ());
-            }
-
-            var index = 0;
-
-            foreach (Toplevel t in _topLevels.ToArray ())
-            {
-                if (!t.Running && t != Current && index > 0)
-                {
-                    lock (_topLevels)
-                    {
-                        _topLevels.MoveTo (top, index - 1, new ToplevelEqualityComparer ());
-                    }
-                }
-
-                index++;
-            }
-
-            return false;
-        }
-
-        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)
-            {
-                _topLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
-                Current = top;
-            }
-        }
-
-        return true;
-    }
-
     /// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
     /// <remarks>
     ///     Event handlers can set <see cref="SizeChangedEventArgs.Cancel"/> to <see langword="true"/> to prevent

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

@@ -84,7 +84,7 @@ public static partial class Application
         // MainLoop stuff
         MainLoop?.Dispose ();
         MainLoop = null;
-        _mainThreadId = -1;
+        MainThreadId = -1;
         Iteration = null;
         EndAfterFirstIteration = false;
 
@@ -108,10 +108,10 @@ public static partial class Application
         NotifyNewRunState = null;
         NotifyStopRunState = null;
         MouseGrabView = null;
-        _initialized = false;
+        IsInitialized = false;
 
         // Mouse
-        _mouseEnteredView = null;
+        MouseEnteredView = null;
         WantContinuousButtonPressedView = null;
         MouseEvent = null;
         GrabbedMouse = null;

+ 1 - 1
Terminal.Gui/Application/MainLoopSyncContext.cs

@@ -23,7 +23,7 @@ internal sealed class MainLoopSyncContext : SynchronizationContext
     //_mainLoop.Driver.Wakeup ();
     public override void Send (SendOrPostCallback d, object state)
     {
-        if (Thread.CurrentThread.ManagedThreadId == Application._mainThreadId)
+        if (Thread.CurrentThread.ManagedThreadId == Application.MainThreadId)
         {
             d (state);
         }

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

@@ -351,7 +351,7 @@ public abstract class ConsoleDriver
                 {
                     Contents [row, c].IsDirty = true;
                 }
-                _dirtyLines [row] = true;
+                _dirtyLines! [row] = true;
             }
         }
     }
@@ -380,7 +380,7 @@ public abstract class ConsoleDriver
                         Rune = (rune != default ? rune : (Rune)' '),
                         Attribute = CurrentAttribute, IsDirty = true
                     };
-                    _dirtyLines [r] = true;
+                    _dirtyLines! [r] = true;
                 }
             }
         }
@@ -561,7 +561,7 @@ public abstract class ConsoleDriver
     #region Mouse and Keyboard
 
     /// <summary>Event fired when a key is pressed down. This is a precursor to <see cref="KeyUp"/>.</summary>
-    public event EventHandler<Key> KeyDown;
+    public event EventHandler<Key>? KeyDown;
 
     /// <summary>
     ///     Called when a key is pressed down. Fires the <see cref="KeyDown"/> event. This is a precursor to
@@ -575,7 +575,7 @@ public abstract class ConsoleDriver
     ///     Drivers that do not support key release events will fire this event after <see cref="KeyDown"/> processing is
     ///     complete.
     /// </remarks>
-    public event EventHandler<Key> KeyUp;
+    public event EventHandler<Key>? KeyUp;
 
     /// <summary>Called when a key is released. Fires the <see cref="KeyUp"/> event.</summary>
     /// <remarks>
@@ -586,7 +586,7 @@ public abstract class ConsoleDriver
     public void OnKeyUp (Key a) { KeyUp?.Invoke (this, a); }
 
     /// <summary>Event fired when a mouse event occurs.</summary>
-    public event EventHandler<MouseEvent> MouseEvent;
+    public event EventHandler<MouseEvent>? MouseEvent;
 
     /// <summary>Called when a mouse event occurs. Fires the <see cref="MouseEvent"/> event.</summary>
     /// <param name="a"></param>

+ 2 - 2
Terminal.Gui/View/Adornment/ShadowView.cs

@@ -109,7 +109,7 @@ internal class ShadowView : View
         for (int i = screen.X; i < screen.X + screen.Width - 1; i++)
         {
             Driver.Move (i, screen.Y);
-            Driver.AddRune (Driver.Contents [screen.Y, i].Rune);
+            Driver.AddRune (Driver.Contents! [screen.Y, i].Rune);
         }
     }
 
@@ -133,7 +133,7 @@ internal class ShadowView : View
         for (int i = screen.Y; i < screen.Y + viewport.Height; i++)
         {
             Driver.Move (screen.X, i);
-            Driver.AddRune (Driver.Contents [i, screen.X].Rune);
+            Driver.AddRune (Driver.Contents! [i, screen.X].Rune);
         }
     }
 }

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

@@ -11,7 +11,7 @@ public class EventArgs<T> : EventArgs where T : notnull
     /// <summary>Initializes a new instance of the <see cref="EventArgs{T}"/> class.</summary>
     /// <param name="currentValue">The current value of the property.</param>
     /// <typeparam name="T">The type of the value.</typeparam>
-    public EventArgs (ref readonly T currentValue) { CurrentValue = currentValue; }
+    public EventArgs (in T currentValue) { CurrentValue = currentValue; }
 
     /// <summary>The current value of the property.</summary>
     public T CurrentValue { get; }

+ 1 - 1
Terminal.Gui/View/Layout/Dim.cs

@@ -257,7 +257,7 @@ public abstract class Dim
         }
 
         var newDim = new DimCombine (AddOrSubtract.Subtract, left, right);
-        (left as DimView)?.Target.SetNeedsLayout ();
+        (left as DimView)?.Target?.SetNeedsLayout ();
 
         return newDim;
     }

+ 2 - 2
Terminal.Gui/View/Layout/DimView.cs

@@ -52,8 +52,8 @@ public class DimView : Dim
     {
         return Dimension switch
                {
-                   Dimension.Height => Target.Frame.Height,
-                   Dimension.Width => Target.Frame.Width,
+                   Dimension.Height => Target!.Frame.Height,
+                   Dimension.Width => Target!.Frame.Width,
                    _ => 0
                };
     }

+ 4 - 4
Terminal.Gui/View/Layout/PosView.cs

@@ -47,10 +47,10 @@ public class PosView (View? view, Side side) : Pos
     {
         return Side switch
                {
-                   Side.Left => Target.Frame.X,
-                   Side.Top => Target.Frame.Y,
-                   Side.Right => Target.Frame.Right,
-                   Side.Bottom => Target.Frame.Bottom,
+                   Side.Left => Target!.Frame.X,
+                   Side.Top => Target!.Frame.Y,
+                   Side.Right => Target!.Frame.Right,
+                   Side.Bottom => Target!.Frame.Bottom,
                    _ => 0
                };
     }

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

@@ -490,7 +490,7 @@ public partial class View : Responder, ISupportInitializeNotification
     /// <summary>Called when the <see cref="View.Title"/> has been changed. Invokes the <see cref="TitleChanged"/> event.</summary>
     protected void OnTitleChanged ()
     {
-        TitleChanged?.Invoke (this, new (ref _title));
+        TitleChanged?.Invoke (this, new (in _title));
     }
 
     /// <summary>

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

@@ -206,7 +206,7 @@ namespace Terminal.Gui
 
                 if (result)
                 {
-                    OnTextChanged (new EventArgs<string> (ref oldValue));
+                    OnTextChanged (new EventArgs<string> (in oldValue));
                 }
 
                 return result;
@@ -220,7 +220,7 @@ namespace Terminal.Gui
 
                 if (result)
                 {
-                    OnTextChanged (new EventArgs<string> (ref oldValue));
+                    OnTextChanged (new EventArgs<string> (in oldValue));
                 }
 
                 return result;
@@ -333,7 +333,7 @@ namespace Terminal.Gui
                 {
                     string oldValue = Text;
                     _text.RemoveAt (pos);
-                    OnTextChanged (new EventArgs<string> (ref oldValue));
+                    OnTextChanged (new EventArgs<string> (in oldValue));
                 }
 
                 return true;
@@ -349,7 +349,7 @@ namespace Terminal.Gui
                 {
                     string oldValue = Text;
                     _text.Insert (pos, (Rune)ch);
-                    OnTextChanged (new EventArgs<string> (ref oldValue));
+                    OnTextChanged (new EventArgs<string> (in oldValue));
 
                     return true;
                 }

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

@@ -62,7 +62,7 @@ public class Tile
     /// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
     public virtual void OnTitleChanged (string oldTitle, string newTitle)
     {
-        var args = new EventArgs<string> (ref newTitle);
+        var args = new EventArgs<string> (in newTitle);
         TitleChanged?.Invoke (this, args);
     }
 

+ 2 - 2
UICatalog/Scenarios/Buttons.cs

@@ -527,8 +527,8 @@ public class Buttons : Scenario
                 }
 
                 _value = value;
-                _number.Text = _value.ToString ();
-                ValueChanged?.Invoke (this, new (ref _value));
+                _number.Text = _value.ToString ()!;
+                ValueChanged?.Invoke (this, new (in _value));
             }
         }
 

+ 1 - 1
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -205,7 +205,7 @@ public class ListViewWithSelection : Scenario
 
         /// <inheritdoc />
         public event NotifyCollectionChangedEventHandler CollectionChanged;
-        public int Count => Scenarios != null ? Scenarios.Count : 0;
+        public int Count => Scenarios?.Count ?? 0;
         public int Length { get; private set; }
         public bool SuspendCollectionChangedEvent { get => throw new System.NotImplementedException (); set => throw new System.NotImplementedException (); }
 

+ 6 - 2
UICatalog/Scenarios/MenuBarScenario.cs

@@ -1,5 +1,6 @@
 using System;
 using Terminal.Gui;
+using static System.Runtime.InteropServices.JavaScript.JSType;
 
 namespace UICatalog.Scenarios;
 
@@ -64,14 +65,17 @@ public class MenuBarScenario : Scenario
         menuBar.Key = KeyCode.F9;
         menuBar.Title = "TestMenuBar";
 
-        bool fnAction (string s)
+        bool FnAction (string s)
         {
             _lastAction.Text = s;
 
             return true;
         }
+        
+        // Declare a variable for the function
+        Func<string, bool> fnActionVariable = FnAction;
 
-        menuBar.EnableForDesign ((Func<string, bool>)fnAction);
+        menuBar.EnableForDesign (ref fnActionVariable);
 
         menuBar.MenuOpening += (s, e) =>
                                {

+ 1 - 1
UICatalog/UICatalog.cs

@@ -104,7 +104,7 @@ internal class UICatalogApp
         // If no driver is provided, the default driver is used.
         Option<string> driverOption = new Option<string> ("--driver", "The ConsoleDriver to use.").FromAmong (
              Application.GetDriverTypes ()
-                        .Select (d => d.Name)
+                        .Select (d => d!.Name)
                         .ToArray ()
             );
 

+ 10 - 10
UnitTests/Application/ApplicationTests.cs

@@ -162,7 +162,7 @@ public class ApplicationTests
         // Set some values
 
         Application.Init (driverName: driverType.Name);
-        Application._initialized = true;
+        Application.IsInitialized = true;
 
         // Reset
         Application.ResetState ();
@@ -191,12 +191,12 @@ public class ApplicationTests
             Assert.Null (Application.OverlappedTop);
 
             // Internal properties
-            Assert.False (Application._initialized);
+            Assert.False (Application.IsInitialized);
             Assert.Equal (Application.GetSupportedCultures (), Application.SupportedCultures);
             Assert.False (Application._forceFakeConsole);
-            Assert.Equal (-1, Application._mainThreadId);
+            Assert.Equal (-1, Application.MainThreadId);
             Assert.Empty (Application._topLevels);
-            Assert.Null (Application._mouseEnteredView);
+            Assert.Null (Application.MouseEnteredView);
 
             // Keyboard
             Assert.Empty (Application.GetViewKeyBindings ());
@@ -218,12 +218,12 @@ public class ApplicationTests
         CheckReset ();
 
         // Set the values that can be set
-        Application._initialized = true;
+        Application.IsInitialized = true;
         Application._forceFakeConsole = true;
-        Application._mainThreadId = 1;
+        Application.MainThreadId = 1;
 
         //Application._topLevels = new List<Toplevel> ();
-        Application._mouseEnteredView = new ();
+        Application.MouseEnteredView = new ();
 
         //Application.SupportedCultures = new List<CultureInfo> ();
         Application.Force16Colors = true;
@@ -237,7 +237,7 @@ public class ApplicationTests
 
         //Application.OverlappedChildren = new List<View> ();
         //Application.OverlappedTop = 
-        Application._mouseEnteredView = new ();
+        Application.MouseEnteredView = new ();
 
         //Application.WantContinuousButtonPressedView = new View ();
 
@@ -413,7 +413,7 @@ public class ApplicationTests
     [AutoInitShutdown]
     public void Internal_Properties_Correct ()
     {
-        Assert.True (Application._initialized);
+        Assert.True (Application.IsInitialized);
         Assert.Null (Application.Top);
         RunState rs = Application.Begin (new ());
         Assert.Equal (Application.Top, rs.Toplevel);
@@ -1206,7 +1206,7 @@ public class ApplicationTests
             Thread.Sleep ((int)timeoutTime / 10);
 
             // Worst case scenario - something went wrong
-            if (Application._initialized && iteration > 25)
+            if (Application.IsInitialized && iteration > 25)
             {
                 _output.WriteLine ($"Too many iterations ({iteration}): Calling Application.RequestStop.");
                 Application.RequestStop ();

+ 1 - 1
UnitTests/Application/KeyboardTests.cs

@@ -169,7 +169,7 @@ public class KeyboardTests
             _output.WriteLine ("Iteration: {0}", iteration);
             iteration++;
             Assert.True (iteration < 2, "Too many iterations, something is wrong.");
-            if (Application._initialized)
+            if (Application.IsInitialized)
             {
                 _output.WriteLine ("  Pressing QuitKey");
                 Application.OnKeyDown (Application.QuitKey);

+ 1 - 1
UnitTests/UICatalog/ScenarioTests.cs

@@ -115,7 +115,7 @@ public class ScenarioTests : TestsAllViews
 
         void OnApplicationOnIteration (object s, IterationEventArgs a)
         {
-            if (Application._initialized)
+            if (Application.IsInitialized)
             {
                 // Press QuitKey 
                 //_output.WriteLine ($"Forcing Quit with {Application.QuitKey}");

+ 4 - 4
UnitTests/View/DrawTests.cs

@@ -48,16 +48,16 @@ public class DrawTests (ITestOutputHelper _output)
         view.Draw ();
 
         // Only valid location w/in Viewport is 0, 0 (view) - 2, 2 (screen)
-        Assert.Equal ((Rune)' ', Application.Driver?.Contents [2, 2].Rune);
+        Assert.Equal ((Rune)' ', Application.Driver?.Contents! [2, 2].Rune);
 
         view.AddRune (0, 0, Rune.ReplacementChar);
-        Assert.Equal (Rune.ReplacementChar, Application.Driver?.Contents [2, 2].Rune);
+        Assert.Equal (Rune.ReplacementChar, Application.Driver?.Contents! [2, 2].Rune);
 
         view.AddRune (-1, -1, Rune.ReplacementChar);
-        Assert.Equal ((Rune)'M', Application.Driver?.Contents [1, 1].Rune);
+        Assert.Equal ((Rune)'M', Application.Driver?.Contents! [1, 1].Rune);
 
         view.AddRune (1, 1, Rune.ReplacementChar);
-        Assert.Equal ((Rune)'M', Application.Driver?.Contents [3, 3].Rune);
+        Assert.Equal ((Rune)'M', Application.Driver?.Contents! [3, 3].Rune);
 
         View.Diagnostics = ViewDiagnosticFlags.Off;
     }

+ 11 - 10
UnitTests/Views/MenuBarTests.cs

@@ -1301,15 +1301,16 @@ wo
 
         var menu = new MenuBar ();
 
-        menu.EnableForDesign (
-                              new Func<object, bool> (
-                                                      s =>
-                                                      {
-                                                          miAction = s as string;
-
-                                                          return true;
-                                                      })
-                             );
+        bool FnAction (string s)
+        {
+            miAction = s;
+
+            return true;
+        }
+        // Declare a variable for the function
+        Func<string, bool> fnActionVariable = FnAction;
+
+        menu.EnableForDesign (ref fnActionVariable);
 
         menu.Key = KeyCode.F9;
         menu.MenuOpening += (s, e) => mbiCurrent = e.CurrentMenu;
@@ -1329,7 +1330,7 @@ wo
         foreach (KeyCode key in keys)
         {
             Assert.True (top.NewKeyDownEvent (new (key)));
-            Application.MainLoop.RunIteration ();
+            Application.MainLoop!.RunIteration ();
         }
 
         Assert.Equal (expectedAction, miAction);