-
Notifications
You must be signed in to change notification settings - Fork 685
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
Fixes #3667. Null reference in v2 in FindDeepestView. #3668
Conversation
/// <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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ();
There was a problem hiding this 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); |
There was a problem hiding this comment.
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 ();
Also, you can use the generic form of the methods instead of explicit checking, and avoid the whole thing:
I prefer this one. Thanks. |
Yep. Nice stuff in there for use cases like this. 👍 |
Fixes
Proposed Changes/Todos
Pull Request checklist:
CTRL-K-D
to automatically reformat your files before committing.dotnet test
before commit///
style comments)