Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3667. Null reference in v2 in FindDeepestView. #3668

Merged

Conversation

BDisp
Copy link
Collaborator

@BDisp BDisp commented Aug 18, 2024

Fixes

Proposed Changes/Todos

  • Make Toplevel's MenuBar and StatusBar properties read-only

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

@BDisp BDisp requested a review from tig as a code owner August 18, 2024 14:59
@tig tig merged commit 7574c7f into gui-cs:v2_develop Aug 19, 2024
3 checks passed
@BDisp BDisp deleted the v2_3667_toplevel-menubar-statusbar-remove-fix branch August 19, 2024 15:08
/// <summary>Gets or sets the menu for this Toplevel.</summary>
public MenuBar? MenuBar { get; set; }
/// <summary>Gets the latest <see cref="MenuBar"/> added into this Toplevel.</summary>
public MenuBar? MenuBar => (MenuBar?)Subviews?.LastOrDefault (s => s is MenuBar);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future cases like this, using the safe cast form (thingThatMightBeNull as ExpectedType) is a better pattern than an explicit cast.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you can use the generic form of the methods instead of explicit checking, and avoid the whole thing:

    public MenuBar? MenuBar => Subviews?.OfType<MenuBar>().LastOrDefault ();

Copy link
Collaborator

@dodexahedron dodexahedron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just follow-up comments since I missed this one while I was busy.

Notes for the future.

/// <summary>Gets or sets the menu for this Toplevel.</summary>
public MenuBar? MenuBar { get; set; }
/// <summary>Gets the latest <see cref="MenuBar"/> added into this Toplevel.</summary>
public MenuBar? MenuBar => (MenuBar?)Subviews?.LastOrDefault (s => s is MenuBar);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you can use the generic form of the methods instead of explicit checking, and avoid the whole thing:

    public MenuBar? MenuBar => Subviews?.OfType<MenuBar>().LastOrDefault ();

@BDisp
Copy link
Collaborator Author

BDisp commented Aug 19, 2024

Also, you can use the generic form of the methods instead of explicit checking, and avoid the whole thing:

public MenuBar? MenuBar => Subviews?.OfType<MenuBar>().LastOrDefault ();

I prefer this one. Thanks.

@dodexahedron
Copy link
Collaborator

Yep. Nice stuff in there for use cases like this. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Null reference in v2 in FindDeepestView
3 participants