-
Notifications
You must be signed in to change notification settings - Fork 975
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
Enable nullability in ToolStripItemInternalLayout #7298
Conversation
src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.ToolStripItemInternalLayout.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.ToolStripItemInternalLayout.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.ToolStripItemInternalLayout.cs
Outdated
Show resolved
Hide resolved
@@ -169,7 +166,7 @@ public virtual Size GetPreferredSize(Size constrainingSize) | |||
|
|||
if (_ownerItem is not null) | |||
{ | |||
_lastPreferredSize = _currentLayoutOptions.GetPreferredSizeCore(constrainingSize); | |||
_lastPreferredSize = _currentLayoutOptions!.GetPreferredSizeCore(constrainingSize); |
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.
GetLayoutData()
must be annotated with MemeberNotNull
. Though I'm not sure, if the analyzer will see it.
_currentLayoutOptions
will always be initialised if EnsureLayout()
is called, because it will get called at least once (for _layoutData is null
) and, in turn, it'll invoke PerformLayout()
that'll unconditionally invoke GetLayoutData()
. So EnsureLayout()
must be annotated with MemeberNotNull(_currentLayoutOptions)
.
Please add a comment above EnsureLayout
explaining this.
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.
Unfortunately, adding MemberNotNull
for _currentLayoutOptions
will not work, so I added a comment instead.
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.
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.
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.
👍
We still need to do this:
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.ToolStripItemInternalLayout.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.ToolStripItemInternalLayout.cs
index 6019222bb..469a5a04c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.ToolStripItemInternalLayout.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.ToolStripItemInternalLayout.cs
@@ -135,17 +135,15 @@ namespace System.Windows.Forms
}
[MemberNotNull(nameof(_layoutData))]
- private bool EnsureLayout()
+ private void EnsureLayout()
{
if (_layoutData is null || _parentLayoutData is null || !_parentLayoutData.IsCurrent(ParentInternal))
{
PerformLayout();
- return true;
}
-
- return false;
}
+ [MemberNotNull(nameof(_currentLayoutOptions))]
private ButtonBaseAdapter.LayoutData GetLayoutData()
{
_currentLayoutOptions = CommonLayoutOptions();
@@ -181,6 +179,7 @@ namespace System.Windows.Forms
}
[MemberNotNull(nameof(_layoutData))]
+ [MemberNotNull(nameof(_currentLayoutOptions))]
internal void PerformLayout()
{
_layoutData = GetLayoutData();
8df1e42
to
d6bcf36
Compare
d6bcf36
to
096472f
Compare
096472f
to
4aacaab
Compare
4aacaab
to
4d745ee
Compare
4d745ee
to
915add7
Compare
Thank you |
Proposed changes
Microsoft Reviewers: Open in CodeFlow