Skip to content

Commit 2491c6d

Browse files
authored
Annotate System.ComponentModel.Primitives for nullable (dotnet/corefx#41185)
* Annotate System.ComponentModel.Primitives for nullable Commit migrated from dotnet/corefx@da147ec
1 parent f38db35 commit 2491c6d

27 files changed

Lines changed: 126 additions & 236 deletions

src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed partial class BrowsableAttribute : System.Attribute
1515
public static readonly System.ComponentModel.BrowsableAttribute Yes;
1616
public BrowsableAttribute(bool browsable) { }
1717
public bool Browsable { get { throw null; } }
18-
public override bool Equals(object obj) { throw null; }
18+
public override bool Equals(object? obj) { throw null; }
1919
public override int GetHashCode() { throw null; }
2020
public override bool IsDefaultAttribute() { throw null; }
2121
}
@@ -39,9 +39,9 @@ public CategoryAttribute(string category) { }
3939
public static System.ComponentModel.CategoryAttribute Layout { get { throw null; } }
4040
public static System.ComponentModel.CategoryAttribute Mouse { get { throw null; } }
4141
public static System.ComponentModel.CategoryAttribute WindowStyle { get { throw null; } }
42-
public override bool Equals(object obj) { throw null; }
42+
public override bool Equals(object? obj) { throw null; }
4343
public override int GetHashCode() { throw null; }
44-
protected virtual string GetLocalizedString(string value) { throw null; }
44+
protected virtual string? GetLocalizedString(string value) { throw null; }
4545
public override bool IsDefaultAttribute() { throw null; }
4646
}
4747
[System.ComponentModel.DesignerCategoryAttribute("Component")]
@@ -51,28 +51,28 @@ public Component() { }
5151
protected virtual bool CanRaiseEvents { get { throw null; } }
5252
[System.ComponentModel.BrowsableAttribute(false)]
5353
[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
54-
public System.ComponentModel.IContainer Container { get { throw null; } }
54+
public System.ComponentModel.IContainer? Container { get { throw null; } }
5555
[System.ComponentModel.BrowsableAttribute(false)]
5656
[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
5757
protected bool DesignMode { get { throw null; } }
5858
protected System.ComponentModel.EventHandlerList Events { get { throw null; } }
5959
[System.ComponentModel.BrowsableAttribute(false)]
6060
[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
61-
public virtual System.ComponentModel.ISite Site { get { throw null; } set { } }
61+
public virtual System.ComponentModel.ISite? Site { get { throw null; } set { } }
6262
[System.ComponentModel.BrowsableAttribute(false)]
6363
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
64-
public event System.EventHandler Disposed { add { } remove { } }
64+
public event System.EventHandler? Disposed { add { } remove { } }
6565
public void Dispose() { }
6666
protected virtual void Dispose(bool disposing) { }
6767
~Component() { }
68-
protected virtual object GetService(System.Type service) { throw null; }
68+
protected virtual object? GetService(System.Type service) { throw null; }
6969
public override string ToString() { throw null; }
7070
}
7171
public partial class ComponentCollection : System.Collections.ReadOnlyCollectionBase
7272
{
7373
public ComponentCollection(System.ComponentModel.IComponent[] components) { }
74-
public virtual System.ComponentModel.IComponent this[int index] { get { throw null; } }
75-
public virtual System.ComponentModel.IComponent this[string name] { get { throw null; } }
74+
public virtual System.ComponentModel.IComponent? this[int index] { get { throw null; } }
75+
public virtual System.ComponentModel.IComponent? this[string? name] { get { throw null; } }
7676
public void CopyTo(System.ComponentModel.IComponent[] array, int index) { }
7777
}
7878
[System.AttributeUsageAttribute(System.AttributeTargets.All)]
@@ -83,7 +83,7 @@ public DescriptionAttribute() { }
8383
public DescriptionAttribute(string description) { }
8484
public virtual string Description { get { throw null; } }
8585
protected string DescriptionValue { get { throw null; } set { } }
86-
public override bool Equals(object obj) { throw null; }
86+
public override bool Equals(object? obj) { throw null; }
8787
public override int GetHashCode() { throw null; }
8888
public override bool IsDefaultAttribute() { throw null; }
8989
}
@@ -98,7 +98,7 @@ public DesignerCategoryAttribute() { }
9898
public DesignerCategoryAttribute(string category) { }
9999
public string Category { get { throw null; } }
100100
public override object TypeId { get { throw null; } }
101-
public override bool Equals(object obj) { throw null; }
101+
public override bool Equals(object? obj) { throw null; }
102102
public override int GetHashCode() { throw null; }
103103
public override bool IsDefaultAttribute() { throw null; }
104104
}
@@ -117,7 +117,7 @@ public sealed partial class DesignerSerializationVisibilityAttribute : System.At
117117
public static readonly System.ComponentModel.DesignerSerializationVisibilityAttribute Visible;
118118
public DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility visibility) { }
119119
public System.ComponentModel.DesignerSerializationVisibility Visibility { get { throw null; } }
120-
public override bool Equals(object obj) { throw null; }
120+
public override bool Equals(object? obj) { throw null; }
121121
public override int GetHashCode() { throw null; }
122122
public override bool IsDefaultAttribute() { throw null; }
123123
}
@@ -129,7 +129,7 @@ public sealed partial class DesignOnlyAttribute : System.Attribute
129129
public static readonly System.ComponentModel.DesignOnlyAttribute Yes;
130130
public DesignOnlyAttribute(bool isDesignOnly) { }
131131
public bool IsDesignOnly { get { throw null; } }
132-
public override bool Equals(object obj) { throw null; }
132+
public override bool Equals(object? obj) { throw null; }
133133
public override int GetHashCode() { throw null; }
134134
public override bool IsDefaultAttribute() { throw null; }
135135
}
@@ -141,30 +141,30 @@ public DisplayNameAttribute() { }
141141
public DisplayNameAttribute(string displayName) { }
142142
public virtual string DisplayName { get { throw null; } }
143143
protected string DisplayNameValue { get { throw null; } set { } }
144-
public override bool Equals(object obj) { throw null; }
144+
public override bool Equals(object? obj) { throw null; }
145145
public override int GetHashCode() { throw null; }
146146
public override bool IsDefaultAttribute() { throw null; }
147147
}
148148
public sealed partial class EventHandlerList : System.IDisposable
149149
{
150150
public EventHandlerList() { }
151-
public System.Delegate this[object key] { get { throw null; } set { } }
152-
public void AddHandler(object key, System.Delegate value) { }
151+
public System.Delegate? this[object key] { get { throw null; } set { } }
152+
public void AddHandler(object key, System.Delegate? value) { }
153153
public void AddHandlers(System.ComponentModel.EventHandlerList listToAddFrom) { }
154154
public void Dispose() { }
155-
public void RemoveHandler(object key, System.Delegate value) { }
155+
public void RemoveHandler(object key, System.Delegate? value) { }
156156
}
157157
public partial interface IComponent : System.IDisposable
158158
{
159-
System.ComponentModel.ISite Site { get; set; }
160-
event System.EventHandler Disposed;
159+
System.ComponentModel.ISite? Site { get; set; }
160+
event System.EventHandler? Disposed;
161161
}
162162
public partial interface IContainer : System.IDisposable
163163
{
164164
System.ComponentModel.ComponentCollection Components { get; }
165-
void Add(System.ComponentModel.IComponent component);
166-
void Add(System.ComponentModel.IComponent component, string name);
167-
void Remove(System.ComponentModel.IComponent component);
165+
void Add(System.ComponentModel.IComponent? component);
166+
void Add(System.ComponentModel.IComponent? component, string? name);
167+
void Remove(System.ComponentModel.IComponent? component);
168168
}
169169
[System.AttributeUsageAttribute(System.AttributeTargets.All)]
170170
public sealed partial class ImmutableObjectAttribute : System.Attribute
@@ -174,7 +174,7 @@ public sealed partial class ImmutableObjectAttribute : System.Attribute
174174
public static readonly System.ComponentModel.ImmutableObjectAttribute Yes;
175175
public ImmutableObjectAttribute(bool immutable) { }
176176
public bool Immutable { get { throw null; } }
177-
public override bool Equals(object obj) { throw null; }
177+
public override bool Equals(object? obj) { throw null; }
178178
public override int GetHashCode() { throw null; }
179179
public override bool IsDefaultAttribute() { throw null; }
180180
}
@@ -188,23 +188,23 @@ public partial class InvalidAsynchronousStateException : System.ArgumentExceptio
188188
{
189189
public InvalidAsynchronousStateException() { }
190190
protected InvalidAsynchronousStateException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
191-
public InvalidAsynchronousStateException(string message) { }
192-
public InvalidAsynchronousStateException(string message, System.Exception innerException) { }
191+
public InvalidAsynchronousStateException(string? message) { }
192+
public InvalidAsynchronousStateException(string? message, System.Exception? innerException) { }
193193
}
194194
public partial class InvalidEnumArgumentException : System.ArgumentException
195195
{
196196
public InvalidEnumArgumentException() { }
197197
protected InvalidEnumArgumentException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
198-
public InvalidEnumArgumentException(string message) { }
199-
public InvalidEnumArgumentException(string message, System.Exception innerException) { }
200-
public InvalidEnumArgumentException(string argumentName, int invalidValue, System.Type enumClass) { }
198+
public InvalidEnumArgumentException(string? message) { }
199+
public InvalidEnumArgumentException(string? message, System.Exception? innerException) { }
200+
public InvalidEnumArgumentException(string? argumentName, int invalidValue, System.Type enumClass) { }
201201
}
202202
public partial interface ISite : System.IServiceProvider
203203
{
204204
System.ComponentModel.IComponent Component { get; }
205205
System.ComponentModel.IContainer Container { get; }
206206
bool DesignMode { get; }
207-
string Name { get; set; }
207+
string? Name { get; set; }
208208
}
209209
public partial interface ISupportInitialize
210210
{
@@ -214,9 +214,9 @@ public partial interface ISupportInitialize
214214
public partial interface ISynchronizeInvoke
215215
{
216216
bool InvokeRequired { get; }
217-
System.IAsyncResult BeginInvoke(System.Delegate method, object[] args);
218-
object EndInvoke(System.IAsyncResult result);
219-
object Invoke(System.Delegate method, object[] args);
217+
System.IAsyncResult BeginInvoke(System.Delegate method, object?[]? args);
218+
object? EndInvoke(System.IAsyncResult result);
219+
object? Invoke(System.Delegate method, object?[]? args);
220220
}
221221
[System.AttributeUsageAttribute(System.AttributeTargets.All)]
222222
public sealed partial class LocalizableAttribute : System.Attribute
@@ -226,7 +226,7 @@ public sealed partial class LocalizableAttribute : System.Attribute
226226
public static readonly System.ComponentModel.LocalizableAttribute Yes;
227227
public LocalizableAttribute(bool isLocalizable) { }
228228
public bool IsLocalizable { get { throw null; } }
229-
public override bool Equals(object obj) { throw null; }
229+
public override bool Equals(object? obj) { throw null; }
230230
public override int GetHashCode() { throw null; }
231231
public override bool IsDefaultAttribute() { throw null; }
232232
}
@@ -238,7 +238,7 @@ public sealed partial class MergablePropertyAttribute : System.Attribute
238238
public static readonly System.ComponentModel.MergablePropertyAttribute Yes;
239239
public MergablePropertyAttribute(bool allowMerge) { }
240240
public bool AllowMerge { get { throw null; } }
241-
public override bool Equals(object obj) { throw null; }
241+
public override bool Equals(object? obj) { throw null; }
242242
public override int GetHashCode() { throw null; }
243243
public override bool IsDefaultAttribute() { throw null; }
244244
}
@@ -250,7 +250,7 @@ public sealed partial class NotifyParentPropertyAttribute : System.Attribute
250250
public static readonly System.ComponentModel.NotifyParentPropertyAttribute Yes;
251251
public NotifyParentPropertyAttribute(bool notifyParent) { }
252252
public bool NotifyParent { get { throw null; } }
253-
public override bool Equals(object obj) { throw null; }
253+
public override bool Equals(object? obj) { throw null; }
254254
public override int GetHashCode() { throw null; }
255255
public override bool IsDefaultAttribute() { throw null; }
256256
}
@@ -261,7 +261,7 @@ public sealed partial class ParenthesizePropertyNameAttribute : System.Attribute
261261
public ParenthesizePropertyNameAttribute() { }
262262
public ParenthesizePropertyNameAttribute(bool needParenthesis) { }
263263
public bool NeedParenthesis { get { throw null; } }
264-
public override bool Equals(object o) { throw null; }
264+
public override bool Equals(object? o) { throw null; }
265265
public override int GetHashCode() { throw null; }
266266
public override bool IsDefaultAttribute() { throw null; }
267267
}
@@ -273,7 +273,7 @@ public sealed partial class ReadOnlyAttribute : System.Attribute
273273
public static readonly System.ComponentModel.ReadOnlyAttribute Yes;
274274
public ReadOnlyAttribute(bool isReadOnly) { }
275275
public bool IsReadOnly { get { throw null; } }
276-
public override bool Equals(object value) { throw null; }
276+
public override bool Equals(object? value) { throw null; }
277277
public override int GetHashCode() { throw null; }
278278
public override bool IsDefaultAttribute() { throw null; }
279279
}
@@ -291,7 +291,7 @@ public sealed partial class RefreshPropertiesAttribute : System.Attribute
291291
public static readonly System.ComponentModel.RefreshPropertiesAttribute Repaint;
292292
public RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties refresh) { }
293293
public System.ComponentModel.RefreshProperties RefreshProperties { get { throw null; } }
294-
public override bool Equals(object value) { throw null; }
294+
public override bool Equals(object? value) { throw null; }
295295
public override int GetHashCode() { throw null; }
296296
public override bool IsDefaultAttribute() { throw null; }
297297
}

src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Debug;uap-Release</Configurations>
4+
<Nullable>enable</Nullable>
45
</PropertyGroup>
56
<ItemGroup>
67
<Compile Include="System.ComponentModel.Primitives.cs" />

src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<RootNamespace>System.ComponentModel.Primitives</RootNamespace>
44
<AssemblyName>System.ComponentModel.Primitives</AssemblyName>
55
<Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations>
6+
<Nullable>enable</Nullable>
67
</PropertyGroup>
78
<ItemGroup>
89
<Compile Include="System\ComponentModel\ISynchronizeInvoke.cs" />

src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/BrowsableAttribute.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,8 @@ public BrowsableAttribute(bool browsable)
4343
/// </summary>
4444
public bool Browsable { get; }
4545

46-
public override bool Equals(object obj)
47-
{
48-
if (obj == this)
49-
{
50-
return true;
51-
}
52-
53-
BrowsableAttribute other = obj as BrowsableAttribute;
54-
return other?.Browsable == Browsable;
55-
}
46+
public override bool Equals(object? obj) =>
47+
obj is BrowsableAttribute other && other.Browsable == Browsable;
5648

5749
public override int GetHashCode() => Browsable.GetHashCode();
5850

src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ namespace System.ComponentModel
1111
[AttributeUsage(AttributeTargets.All)]
1212
public class CategoryAttribute : Attribute
1313
{
14-
private static volatile CategoryAttribute s_action;
15-
private static volatile CategoryAttribute s_appearance;
16-
private static volatile CategoryAttribute s_asynchronous;
17-
private static volatile CategoryAttribute s_behavior;
18-
private static volatile CategoryAttribute s_data;
19-
private static volatile CategoryAttribute s_design;
20-
private static volatile CategoryAttribute s_dragDrop;
21-
private static volatile CategoryAttribute s_defAttr;
22-
private static volatile CategoryAttribute s_focus;
23-
private static volatile CategoryAttribute s_format;
24-
private static volatile CategoryAttribute s_key;
25-
private static volatile CategoryAttribute s_layout;
26-
private static volatile CategoryAttribute s_mouse;
27-
private static volatile CategoryAttribute s_windowStyle;
14+
private static volatile CategoryAttribute? s_action;
15+
private static volatile CategoryAttribute? s_appearance;
16+
private static volatile CategoryAttribute? s_asynchronous;
17+
private static volatile CategoryAttribute? s_behavior;
18+
private static volatile CategoryAttribute? s_data;
19+
private static volatile CategoryAttribute? s_design;
20+
private static volatile CategoryAttribute? s_dragDrop;
21+
private static volatile CategoryAttribute? s_defAttr;
22+
private static volatile CategoryAttribute? s_focus;
23+
private static volatile CategoryAttribute? s_format;
24+
private static volatile CategoryAttribute? s_key;
25+
private static volatile CategoryAttribute? s_layout;
26+
private static volatile CategoryAttribute? s_mouse;
27+
private static volatile CategoryAttribute? s_windowStyle;
2828

2929
private bool _localized;
3030

@@ -176,7 +176,7 @@ public string Category
176176
{
177177
lock (_locker)
178178
{
179-
string localizedValue = GetLocalizedString(_categoryValue);
179+
string? localizedValue = GetLocalizedString(_categoryValue);
180180
if (localizedValue != null)
181181
{
182182
_categoryValue = localizedValue;
@@ -190,23 +190,15 @@ public string Category
190190
}
191191
}
192192

193-
public override bool Equals(object obj)
194-
{
195-
if (obj == this)
196-
{
197-
return true;
198-
}
199-
200-
CategoryAttribute other = obj as CategoryAttribute;
201-
return other != null && Category == other.Category;
202-
}
193+
public override bool Equals(object? obj) =>
194+
obj is CategoryAttribute other && other.Category == Category;
203195

204196
public override int GetHashCode() => Category?.GetHashCode() ?? 0;
205197

206198
/// <summary>
207199
/// Looks up the localized name of a given category.
208200
/// </summary>
209-
protected virtual string GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value, null);
201+
protected virtual string? GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value, null);
210202

211203
public override bool IsDefaultAttribute() => Category == Default.Category;
212204
}

0 commit comments

Comments
 (0)