Skip to content

Commit

Permalink
Enable nullability in some Control members (#7309)
Browse files Browse the repository at this point in the history
## Proposed changes

- Enable nullability in some Control members.
  • Loading branch information
gpetrou authored Jun 17, 2022
1 parent 35c2cf7 commit 48616c4
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 145 deletions.
126 changes: 63 additions & 63 deletions src/System.Windows.Forms/src/PublicAPI.Shipped.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms.ButtonInternal;
Expand Down Expand Up @@ -645,6 +646,7 @@ internal bool ShowToolTip

[Editor("System.ComponentModel.Design.MultilineStringEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
SettingsBindable(true)]
[AllowNull]
public override string Text
{
get => base.Text;
Expand Down
148 changes: 74 additions & 74 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/System.Windows.Forms/src/System/Windows/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,7 @@ private void ApplyClientSize()
/// Assigns a new parent control. Sends out the appropriate property change
/// notifications for properties that are affected by the change of parent.
/// </summary>
internal override void AssignParent(Control value)
internal override void AssignParent(Control? value)
{
// If we are being unparented from the MDI client control, remove
// formMDIParent as well.
Expand Down
2 changes: 2 additions & 0 deletions src/System.Windows.Forms/src/System/Windows/Forms/GroupBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms.Layout;
Expand Down Expand Up @@ -240,6 +241,7 @@ public FlatStyle FlatStyle
}

[Localizable(true)]
[AllowNull]
public override string Text
{
get => base.Text;
Expand Down
7 changes: 4 additions & 3 deletions src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,19 +1088,20 @@ public bool Sorted
[EditorBrowsable(EditorBrowsableState.Advanced)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Bindable(false)]
public override string? Text
[AllowNull]
public override string Text
{
get
{
if (SelectionMode != SelectionMode.None && SelectedItem is not null)
{
if (FormattingEnabled)
{
return GetItemText(SelectedItem);
return GetItemText(SelectedItem) ?? string.Empty;
}
else
{
return FilterItemOnProperty(SelectedItem)?.ToString();
return FilterItemOnProperty(SelectedItem)?.ToString() ?? string.Empty;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
Expand Down Expand Up @@ -1649,6 +1650,7 @@ public ImageList? StateImageList
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Bindable(false)]
[AllowNull]
public override string Text
{
get => base.Text;
Expand Down Expand Up @@ -6131,7 +6133,7 @@ private unsafe bool WmNotify(ref Message m)
_columnHeaderClicked = null;
_columnHeaderClickedWidth = -1;

ISite site = Site;
ISite? site = Site;

if (site is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Printing;
using static Interop;
Expand Down Expand Up @@ -208,6 +209,7 @@ public override RightToLeft RightToLeft
[EditorBrowsable(EditorBrowsableState.Never)]
[Bindable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[AllowNull]
public override string Text
{
get => base.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ public int Step
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Bindable(false)]
[AllowNull]
public override string Text
{
get => base.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ public int SmallChange
[EditorBrowsable(EditorBrowsableState.Never)]
[Bindable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[AllowNull]
public override string Text
{
get => base.Text;
Expand Down
4 changes: 2 additions & 2 deletions src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ public string ToolTipText
/// Assigns a new parent control. Sends out the appropriate property change notifications for
/// properties that are affected by the change of parent.
/// </summary>
internal override void AssignParent(Control value)
internal override void AssignParent(Control? value)
{
if (value is not null && !(value is TabControl))
if (value is not null && value is not TabControl)
{
throw new ArgumentException(string.Format(SR.TabControlTabPageNotOnTabControl, value.GetType().FullName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ public int SmallChange
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Bindable(false)]
[AllowNull]
public override string Text
{
get => base.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected override void OnPaintAdornments(PaintEventArgs pe)
{
base.OnPaintAdornments(pe);

pe.Graphics.DrawString($"Design time \n{Control.Site.Name} !", Control.Font, SystemBrushes.WindowText, new PointF(12, 12));
pe.Graphics.DrawString($"Design time \n{Control.Site?.Name} !", Control.Font, SystemBrushes.WindowText, new PointF(12, 12));
}
}
}
Expand Down

0 comments on commit 48616c4

Please sign in to comment.