Annotate System.ComponentModel.Primitives for nullable (dotnet/corefx#41185)
authorbuyaa-n <bunamnan@microsoft.com>
Tue, 24 Sep 2019 17:05:58 +0000 (10:05 -0700)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2019 17:05:58 +0000 (10:05 -0700)
* Annotate System.ComponentModel.Primitives for nullable

Commit migrated from https://github.com/dotnet/corefx/commit/da147ece700c2502b91e57d99213feadcfb9c1f0

27 files changed:
src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs
src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.csproj
src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/BrowsableAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/Component.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ComponentCollection.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DescriptionAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignOnlyAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerCategoryAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerSerializationVisibilityAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DisplayNameAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EventHandlerList.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IComponent.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IContainer.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISite.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISynchronizeInvoke.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ImmutableObjectAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidAsynchronousStateException.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/LocalizableAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/MergablePropertyAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/NotifyParentPropertyAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ParenthesizePropertyNameAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ReadOnlyAttribute.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/RefreshPropertiesAttribute.cs
src/libraries/System.ComponentModel/ref/System.ComponentModel.cs

index 3b7d893..a43aac8 100644 (file)
@@ -15,7 +15,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.BrowsableAttribute Yes;
         public BrowsableAttribute(bool browsable) { }
         public bool Browsable { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -39,9 +39,9 @@ namespace System.ComponentModel
         public static System.ComponentModel.CategoryAttribute Layout { get { throw null; } }
         public static System.ComponentModel.CategoryAttribute Mouse { get { throw null; } }
         public static System.ComponentModel.CategoryAttribute WindowStyle { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
-        protected virtual string GetLocalizedString(string value) { throw null; }
+        protected virtual string? GetLocalizedString(string value) { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
     [System.ComponentModel.DesignerCategoryAttribute("Component")]
@@ -51,28 +51,28 @@ namespace System.ComponentModel
         protected virtual bool CanRaiseEvents { get { throw null; } }
         [System.ComponentModel.BrowsableAttribute(false)]
         [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
-        public System.ComponentModel.IContainer Container { get { throw null; } }
+        public System.ComponentModel.IContainer? Container { get { throw null; } }
         [System.ComponentModel.BrowsableAttribute(false)]
         [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
         protected bool DesignMode { get { throw null; } }
         protected System.ComponentModel.EventHandlerList Events { get { throw null; } }
         [System.ComponentModel.BrowsableAttribute(false)]
         [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
-        public virtual System.ComponentModel.ISite Site { get { throw null; } set { } }
+        public virtual System.ComponentModel.ISite? Site { get { throw null; } set { } }
         [System.ComponentModel.BrowsableAttribute(false)]
         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
-        public event System.EventHandler Disposed { add { } remove { } }
+        public event System.EventHandler? Disposed { add { } remove { } }
         public void Dispose() { }
         protected virtual void Dispose(bool disposing) { }
         ~Component() { }
-        protected virtual object GetService(System.Type service) { throw null; }
+        protected virtual object? GetService(System.Type service) { throw null; }
         public override string ToString() { throw null; }
     }
     public partial class ComponentCollection : System.Collections.ReadOnlyCollectionBase
     {
         public ComponentCollection(System.ComponentModel.IComponent[] components) { }
-        public virtual System.ComponentModel.IComponent this[int index] { get { throw null; } }
-        public virtual System.ComponentModel.IComponent this[string name] { get { throw null; } }
+        public virtual System.ComponentModel.IComponent? this[int index] { get { throw null; } }
+        public virtual System.ComponentModel.IComponent? this[string? name] { get { throw null; } }
         public void CopyTo(System.ComponentModel.IComponent[] array, int index) { }
     }
     [System.AttributeUsageAttribute(System.AttributeTargets.All)]
@@ -83,7 +83,7 @@ namespace System.ComponentModel
         public DescriptionAttribute(string description) { }
         public virtual string Description { get { throw null; } }
         protected string DescriptionValue { get { throw null; } set { } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -98,7 +98,7 @@ namespace System.ComponentModel
         public DesignerCategoryAttribute(string category) { }
         public string Category { get { throw null; } }
         public override object TypeId { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -117,7 +117,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.DesignerSerializationVisibilityAttribute Visible;
         public DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility visibility) { }
         public System.ComponentModel.DesignerSerializationVisibility Visibility { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -129,7 +129,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.DesignOnlyAttribute Yes;
         public DesignOnlyAttribute(bool isDesignOnly) { }
         public bool IsDesignOnly { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -141,30 +141,30 @@ namespace System.ComponentModel
         public DisplayNameAttribute(string displayName) { }
         public virtual string DisplayName { get { throw null; } }
         protected string DisplayNameValue { get { throw null; } set { } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
     public sealed partial class EventHandlerList : System.IDisposable
     {
         public EventHandlerList() { }
-        public System.Delegate this[object key] { get { throw null; } set { } }
-        public void AddHandler(object key, System.Delegate value) { }
+        public System.Delegate? this[object key] { get { throw null; } set { } }
+        public void AddHandler(object key, System.Delegate? value) { }
         public void AddHandlers(System.ComponentModel.EventHandlerList listToAddFrom) { }
         public void Dispose() { }
-        public void RemoveHandler(object key, System.Delegate value) { }
+        public void RemoveHandler(object key, System.Delegate? value) { }
     }
     public partial interface IComponent : System.IDisposable
     {
-        System.ComponentModel.ISite Site { get; set; }
-        event System.EventHandler Disposed;
+        System.ComponentModel.ISite? Site { get; set; }
+        event System.EventHandler? Disposed;
     }
     public partial interface IContainer : System.IDisposable
     {
         System.ComponentModel.ComponentCollection Components { get; }
-        void Add(System.ComponentModel.IComponent component);
-        void Add(System.ComponentModel.IComponent component, string name);
-        void Remove(System.ComponentModel.IComponent component);
+        void Add(System.ComponentModel.IComponent? component);
+        void Add(System.ComponentModel.IComponent? component, string? name);
+        void Remove(System.ComponentModel.IComponent? component);
     }
     [System.AttributeUsageAttribute(System.AttributeTargets.All)]
     public sealed partial class ImmutableObjectAttribute : System.Attribute
@@ -174,7 +174,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.ImmutableObjectAttribute Yes;
         public ImmutableObjectAttribute(bool immutable) { }
         public bool Immutable { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -188,23 +188,23 @@ namespace System.ComponentModel
     {
         public InvalidAsynchronousStateException() { }
         protected InvalidAsynchronousStateException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
-        public InvalidAsynchronousStateException(string message) { }
-        public InvalidAsynchronousStateException(string message, System.Exception innerException) { }
+        public InvalidAsynchronousStateException(string? message) { }
+        public InvalidAsynchronousStateException(string? message, System.Exception? innerException) { }
     }
     public partial class InvalidEnumArgumentException : System.ArgumentException
     {
         public InvalidEnumArgumentException() { }
         protected InvalidEnumArgumentException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
-        public InvalidEnumArgumentException(string message) { }
-        public InvalidEnumArgumentException(string message, System.Exception innerException) { }
-        public InvalidEnumArgumentException(string argumentName, int invalidValue, System.Type enumClass) { }
+        public InvalidEnumArgumentException(string? message) { }
+        public InvalidEnumArgumentException(string? message, System.Exception? innerException) { }
+        public InvalidEnumArgumentException(string? argumentName, int invalidValue, System.Type enumClass) { }
     }
     public partial interface ISite : System.IServiceProvider
     {
         System.ComponentModel.IComponent Component { get; }
         System.ComponentModel.IContainer Container { get; }
         bool DesignMode { get; }
-        string Name { get; set; }
+        string? Name { get; set; }
     }
     public partial interface ISupportInitialize
     {
@@ -214,9 +214,9 @@ namespace System.ComponentModel
     public partial interface ISynchronizeInvoke
     {
         bool InvokeRequired { get; }
-        System.IAsyncResult BeginInvoke(System.Delegate method, object[] args);
-        object EndInvoke(System.IAsyncResult result);
-        object Invoke(System.Delegate method, object[] args);
+        System.IAsyncResult BeginInvoke(System.Delegate method, object?[]? args);
+        object? EndInvoke(System.IAsyncResult result);
+        object? Invoke(System.Delegate method, object?[]? args);
     }
     [System.AttributeUsageAttribute(System.AttributeTargets.All)]
     public sealed partial class LocalizableAttribute : System.Attribute
@@ -226,7 +226,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.LocalizableAttribute Yes;
         public LocalizableAttribute(bool isLocalizable) { }
         public bool IsLocalizable { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -238,7 +238,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.MergablePropertyAttribute Yes;
         public MergablePropertyAttribute(bool allowMerge) { }
         public bool AllowMerge { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -250,7 +250,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.NotifyParentPropertyAttribute Yes;
         public NotifyParentPropertyAttribute(bool notifyParent) { }
         public bool NotifyParent { get { throw null; } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -261,7 +261,7 @@ namespace System.ComponentModel
         public ParenthesizePropertyNameAttribute() { }
         public ParenthesizePropertyNameAttribute(bool needParenthesis) { }
         public bool NeedParenthesis { get { throw null; } }
-        public override bool Equals(object o) { throw null; }
+        public override bool Equals(object? o) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -273,7 +273,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.ReadOnlyAttribute Yes;
         public ReadOnlyAttribute(bool isReadOnly) { }
         public bool IsReadOnly { get { throw null; } }
-        public override bool Equals(object value) { throw null; }
+        public override bool Equals(object? value) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
@@ -291,7 +291,7 @@ namespace System.ComponentModel
         public static readonly System.ComponentModel.RefreshPropertiesAttribute Repaint;
         public RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties refresh) { }
         public System.ComponentModel.RefreshProperties RefreshProperties { get { throw null; } }
-        public override bool Equals(object value) { throw null; }
+        public override bool Equals(object? value) { throw null; }
         public override int GetHashCode() { throw null; }
         public override bool IsDefaultAttribute() { throw null; }
     }
index 5a694eb..df7ed1d 100644 (file)
@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Debug;uap-Release</Configurations>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System.ComponentModel.Primitives.cs" />
index eebf768..70db1a4 100644 (file)
@@ -3,6 +3,7 @@
     <RootNamespace>System.ComponentModel.Primitives</RootNamespace>
     <AssemblyName>System.ComponentModel.Primitives</AssemblyName>
     <Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System\ComponentModel\ISynchronizeInvoke.cs" />
index 9c0086b..07f1f43 100644 (file)
@@ -43,16 +43,8 @@ namespace System.ComponentModel
         /// </summary>
         public bool Browsable { get; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            BrowsableAttribute other = obj as BrowsableAttribute;
-            return other?.Browsable == Browsable;
-        }
+        public override bool Equals(object? obj) =>
+            obj is BrowsableAttribute other && other.Browsable == Browsable;
 
         public override int GetHashCode() => Browsable.GetHashCode();
 
index 9572587..5cd50e9 100644 (file)
@@ -11,20 +11,20 @@ namespace System.ComponentModel
     [AttributeUsage(AttributeTargets.All)]
     public class CategoryAttribute : Attribute
     {
-        private static volatile CategoryAttribute s_action;
-        private static volatile CategoryAttribute s_appearance;
-        private static volatile CategoryAttribute s_asynchronous;
-        private static volatile CategoryAttribute s_behavior;
-        private static volatile CategoryAttribute s_data;
-        private static volatile CategoryAttribute s_design;
-        private static volatile CategoryAttribute s_dragDrop;
-        private static volatile CategoryAttribute s_defAttr;
-        private static volatile CategoryAttribute s_focus;
-        private static volatile CategoryAttribute s_format;
-        private static volatile CategoryAttribute s_key;
-        private static volatile CategoryAttribute s_layout;
-        private static volatile CategoryAttribute s_mouse;
-        private static volatile CategoryAttribute s_windowStyle;
+        private static volatile CategoryAttribute? s_action;
+        private static volatile CategoryAttribute? s_appearance;
+        private static volatile CategoryAttribute? s_asynchronous;
+        private static volatile CategoryAttribute? s_behavior;
+        private static volatile CategoryAttribute? s_data;
+        private static volatile CategoryAttribute? s_design;
+        private static volatile CategoryAttribute? s_dragDrop;
+        private static volatile CategoryAttribute? s_defAttr;
+        private static volatile CategoryAttribute? s_focus;
+        private static volatile CategoryAttribute? s_format;
+        private static volatile CategoryAttribute? s_key;
+        private static volatile CategoryAttribute? s_layout;
+        private static volatile CategoryAttribute? s_mouse;
+        private static volatile CategoryAttribute? s_windowStyle;
 
         private bool _localized;
 
@@ -176,7 +176,7 @@ namespace System.ComponentModel
                 {
                     lock (_locker)
                     {
-                        string localizedValue = GetLocalizedString(_categoryValue);
+                        string? localizedValue = GetLocalizedString(_categoryValue);
                         if (localizedValue != null)
                         {
                             _categoryValue = localizedValue;
@@ -190,23 +190,15 @@ namespace System.ComponentModel
             }
         }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            CategoryAttribute other = obj as CategoryAttribute;
-            return other != null && Category == other.Category;
-        }
+        public override bool Equals(object? obj) =>
+            obj is CategoryAttribute other && other.Category == Category;
 
         public override int GetHashCode() => Category?.GetHashCode() ?? 0;
 
         /// <summary>
         /// Looks up the localized name of a given category.
         /// </summary>
-        protected virtual string GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value, null);
+        protected virtual string? GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value, null);
 
         public override bool IsDefaultAttribute() => Category == Default.Category;
     }
index 28f0fbc..4de5064 100644 (file)
@@ -16,8 +16,8 @@ namespace System.ComponentModel
         /// </summary>
         private static readonly object s_eventDisposed = new object();
 
-        private ISite _site;
-        private EventHandlerList _events;
+        private ISite? _site;
+        private EventHandlerList? _events;
 
         ~Component() => Dispose(false);
 
@@ -44,7 +44,7 @@ namespace System.ComponentModel
         /// </summary>
         [Browsable(false)]
         [EditorBrowsable(EditorBrowsableState.Advanced)]
-        public event EventHandler Disposed
+        public event EventHandler? Disposed
         {
             add => Events.AddHandler(s_eventDisposed, value);
             remove => Events.RemoveHandler(s_eventDisposed, value);
@@ -60,7 +60,7 @@ namespace System.ComponentModel
         /// </summary>
         [Browsable(false)]
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
-        public virtual ISite Site
+        public virtual ISite? Site
         {
             get => _site;
             set => _site = value;
@@ -87,7 +87,7 @@ namespace System.ComponentModel
                     _site?.Container?.Remove(this);
                     if (_events != null)
                     {
-                        ((EventHandler)_events[s_eventDisposed])?.Invoke(this, EventArgs.Empty);
+                        ((EventHandler?)_events[s_eventDisposed])?.Invoke(this, EventArgs.Empty);
                     }
                 }
             }
@@ -99,13 +99,13 @@ namespace System.ComponentModel
         /// </summary>
         [Browsable(false)]
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
-        public IContainer Container => _site?.Container;
+        public IContainer? Container => _site?.Container;
 
         /// <summary>
         /// Returns an object representing a service provided by
         /// the <see cref='System.ComponentModel.Component'/>.
         /// </summary>
-        protected virtual object GetService(Type service) => _site?.GetService(service);
+        protected virtual object? GetService(Type service) => _site?.GetService(service);
 
         /// <summary>
         /// Gets a value indicating whether the <see cref='System.ComponentModel.Component'/>
@@ -122,10 +122,10 @@ namespace System.ComponentModel
         /// </summary>
         public override string ToString()
         {
-            ISite s = _site;
+            ISite? s = _site;
             if (s == null)
             {
-                return GetType().FullName;
+                return GetType().FullName!;
             }
 
             return s.Name + " [" + GetType().FullName + "]";
index 8edfbd8..011c325 100644 (file)
@@ -14,14 +14,14 @@ namespace System.ComponentModel
         /// Gets a specific <see cref='System.ComponentModel.Component'/> in the
         /// <see cref='System.ComponentModel.IContainer'/>.
         /// </summary>
-        public virtual IComponent this[string name]
+        public virtual IComponent? this[string? name]
         {
             get
             {
                 if (name != null)
                 {
                     IList list = InnerList;
-                    foreach (IComponent comp in list)
+                    foreach (IComponent? comp in list)
                     {
                         if (comp != null && comp.Site != null && comp.Site.Name != null && string.Equals(comp.Site.Name, name, StringComparison.OrdinalIgnoreCase))
                         {
@@ -37,7 +37,7 @@ namespace System.ComponentModel
         /// Gets a specific <see cref='System.ComponentModel.Component'/> in the
         /// <see cref='System.ComponentModel.IContainer'/>.
         /// </summary>
-        public virtual IComponent this[int index] => (IComponent)InnerList[index];
+        public virtual IComponent? this[int index] => (IComponent?)InnerList[index];
 
         public void CopyTo(IComponent[] array, int index) => InnerList.CopyTo(array, index);
     }
index 759e6e8..31e29ee 100644 (file)
@@ -40,16 +40,8 @@ namespace System.ComponentModel
         /// </summary>
         protected string DescriptionValue { get; set; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            DescriptionAttribute other = obj as DescriptionAttribute;
-            return other != null && other.Description == Description;
-        }
+        public override bool Equals(object? obj) =>
+            obj is DescriptionAttribute other && other.Description == Description;
 
         public override int GetHashCode() => Description?.GetHashCode() ?? 0;
 
index 8d680f6..31c3b3c 100644 (file)
@@ -42,16 +42,8 @@ namespace System.ComponentModel
         /// </summary>
         public bool IsDesignOnly { get; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            DesignOnlyAttribute other = obj as DesignOnlyAttribute;
-            return other?.IsDesignOnly == IsDesignOnly;
-        }
+        public override bool Equals(object? obj) =>
+            obj is DesignOnlyAttribute other && other.IsDesignOnly == IsDesignOnly;
 
         public override int GetHashCode() => IsDesignOnly.GetHashCode();
 
index 83cca46..5e99500 100644 (file)
@@ -56,16 +56,8 @@ namespace System.ComponentModel
         /// </summary>
         public string Category { get; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            DesignerCategoryAttribute other = obj as DesignerCategoryAttribute;
-            return other != null && other.Category == Category;
-        }
+        public override bool Equals(object? obj) =>
+            obj is DesignerCategoryAttribute other && other.Category == Category;
 
         public override int GetHashCode() => Category?.GetHashCode() ?? 0;
 
index 55433d7..8a0cb3a 100644 (file)
@@ -52,16 +52,8 @@ namespace System.ComponentModel
         /// </summary>
         public DesignerSerializationVisibility Visibility { get; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            DesignerSerializationVisibilityAttribute other = obj as DesignerSerializationVisibilityAttribute;
-            return other?.Visibility == Visibility;
-        }
+        public override bool Equals(object? obj) =>
+            obj is DesignerSerializationVisibilityAttribute other && other.Visibility == Visibility;
 
         public override int GetHashCode() => base.GetHashCode();
 
index f51f464..d9e58ea 100644 (file)
@@ -39,16 +39,8 @@ namespace System.ComponentModel
         /// </summary>
         protected string DisplayNameValue { get; set; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            DisplayNameAttribute other = obj as DisplayNameAttribute;
-            return other != null && other.DisplayName == DisplayName;
-        }
+        public override bool Equals(object? obj) =>
+            obj is DisplayNameAttribute other && other.DisplayName == DisplayName;
 
         public override int GetHashCode() => DisplayName?.GetHashCode() ?? 0;
 
index 97079e1..c35517a 100644 (file)
@@ -9,8 +9,8 @@ namespace System.ComponentModel
     /// </summary>
     public sealed class EventHandlerList : IDisposable
     {
-        private ListEntry _head;
-        private readonly Component _parent;
+        private ListEntry? _head;
+        private readonly Component? _parent;
 
         /// <summary>
         /// Creates a new event handler list. The parent component is used to check the
@@ -31,11 +31,11 @@ namespace System.ComponentModel
         /// <summary>
         /// Gets or sets the delegate for the specified key.
         /// </summary>
-        public Delegate this[object key]
+        public Delegate? this[object key]
         {
             get
             {
-                ListEntry e = null;
+                ListEntry? e = null;
                 if (_parent == null || _parent.CanRaiseEventsInternal)
                 {
                     e = Find(key);
@@ -45,7 +45,7 @@ namespace System.ComponentModel
             }
             set
             {
-                ListEntry e = Find(key);
+                ListEntry? e = Find(key);
                 if (e != null)
                 {
                     e._handler = value;
@@ -57,9 +57,9 @@ namespace System.ComponentModel
             }
         }
 
-        public void AddHandler(object key, Delegate value)
+        public void AddHandler(object key, Delegate? value)
         {
-            ListEntry e = Find(key);
+            ListEntry? e = Find(key);
             if (e != null)
             {
                 e._handler = Delegate.Combine(e._handler, value);
@@ -77,7 +77,7 @@ namespace System.ComponentModel
                 throw new ArgumentNullException(nameof(listToAddFrom));
             }
 
-            ListEntry currentListEntry = listToAddFrom._head;
+            ListEntry? currentListEntry = listToAddFrom._head;
             while (currentListEntry != null)
             {
                 AddHandler(currentListEntry._key, currentListEntry._handler);
@@ -87,9 +87,9 @@ namespace System.ComponentModel
 
         public void Dispose() => _head = null;
 
-        private ListEntry Find(object key)
+        private ListEntry? Find(object key)
         {
-            ListEntry found = _head;
+            ListEntry? found = _head;
             while (found != null)
             {
                 if (found._key == key)
@@ -101,9 +101,9 @@ namespace System.ComponentModel
             return found;
         }
 
-        public void RemoveHandler(object key, Delegate value)
+        public void RemoveHandler(object key, Delegate? value)
         {
-            ListEntry e = Find(key);
+            ListEntry? e = Find(key);
             if (e != null)
             {
                 e._handler = Delegate.Remove(e._handler, value);
@@ -112,11 +112,11 @@ namespace System.ComponentModel
 
         private sealed class ListEntry
         {
-            internal readonly ListEntry _next;
+            internal readonly ListEntry? _next;
             internal readonly object _key;
-            internal Delegate _handler;
+            internal Delegate? _handler;
 
-            public ListEntry(object key, Delegate handler, ListEntry next)
+            public ListEntry(object key, Delegate? handler, ListEntry? next)
             {
                 _next = next;
                 _key = key;
index fab87be..bbe9a34 100644 (file)
@@ -26,11 +26,11 @@ namespace System.ComponentModel
         /// When implemented by a class, gets or sets the <see cref='System.ComponentModel.ISite'/>
         /// associated with the <see cref='System.ComponentModel.IComponent'/>.
         /// </summary>
-        ISite Site { get; set; }
+        ISite? Site { get; set; }
 
         /// <summary>
         /// Adds an event handler to listen to the Disposed event on the component.
         /// </summary>
-        event EventHandler Disposed;
+        event EventHandler? Disposed;
     }
 }
index 49e8ca7..000558c 100644 (file)
@@ -20,7 +20,7 @@ namespace System.ComponentModel
         /// Adds the specified <see cref='System.ComponentModel.IComponent'/> to the
         /// <see cref='System.ComponentModel.IContainer'/> at the end of the list.
         /// </summary>
-        void Add(IComponent component);
+        void Add(IComponent? component);
 
         //  Adds a component to the container.
         /// <summary>
@@ -28,7 +28,7 @@ namespace System.ComponentModel
         /// <see cref='System.ComponentModel.IContainer'/> at the end of the list,
         /// and assigns a name to the component.
         /// </summary>
-        void Add(IComponent component, string name);
+        void Add(IComponent? component, string? name);
 
         /// <summary>
         /// Gets all the components in the <see cref='System.ComponentModel.IContainer'/>.
@@ -38,6 +38,6 @@ namespace System.ComponentModel
         /// <summary>
         /// Removes a component from the <see cref='System.ComponentModel.IContainer'/>.
         /// </summary>
-        void Remove(IComponent component);
+        void Remove(IComponent? component);
     }
 }
index 46c51a1..a7730b5 100644 (file)
@@ -38,6 +38,6 @@ namespace System.ComponentModel
         /// When implemented by a class, gets or sets the name of the component
         /// associated with the <see cref='System.ComponentModel.ISite'/>.
         /// </summary>
-        string Name { get; set; }
+        string? Name { get; set; }
     }
 }
index c3156f4..d6845b3 100644 (file)
@@ -18,17 +18,17 @@ namespace System.ComponentModel
         /// <summary>
         /// Executes the given delegate on the main thread that this object executes on.
         /// </summary>
-        IAsyncResult BeginInvoke(Delegate method, object[] args);
+        IAsyncResult BeginInvoke(Delegate method, object?[]? args);
 
         /// <summary>
         /// Waits until the process you started by calling <see cref='System.ComponentModel.ISynchronizeInvoke.BeginInvoke'/>
         /// completes, and then returns the value generated by the process.
         /// </summary>
-        object EndInvoke(IAsyncResult result);
+        object? EndInvoke(IAsyncResult result);
 
         /// <summary>
         /// Executes the given delegate on the main thread that this object executes on.
         /// </summary>
-        object Invoke(Delegate method, object[] args);
+        object? Invoke(Delegate method, object?[]? args);
     }
 }
index b6272de..a0eea4b 100644 (file)
@@ -42,16 +42,8 @@ namespace System.ComponentModel
 
         public bool Immutable { get; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            ImmutableObjectAttribute other = obj as ImmutableObjectAttribute;
-            return other?.Immutable == Immutable;
-        }
+        public override bool Equals(object? obj) =>
+            obj is ImmutableObjectAttribute other && other.Immutable == Immutable;
 
         public override int GetHashCode() => base.GetHashCode();
 
index d4f6b8a..e9729df 100644 (file)
@@ -27,7 +27,7 @@ namespace System.ComponentModel
         /// Initializes a new instance of the <see cref='System.ComponentModel.InvalidAsynchronousStateException'/>
         /// class with the specified message.
         /// </summary>
-        public InvalidAsynchronousStateException(string message) : base(message)
+        public InvalidAsynchronousStateException(string? message) : base(message)
         {
         }
 
@@ -35,7 +35,7 @@ namespace System.ComponentModel
         /// Initializes a new instance of the Exception class with a specified error message
         /// and a reference to the inner exception that is the cause of this exception.
         /// </summary>
-        public InvalidAsynchronousStateException(string message, Exception innerException) : base(message, innerException)
+        public InvalidAsynchronousStateException(string? message, Exception? innerException) : base(message, innerException)
         {
         }
 
index fe63ee1..39ec123 100644 (file)
@@ -26,7 +26,7 @@ namespace System.ComponentModel
         /// Initializes a new instance of the <see cref='InvalidEnumArgumentException'/>
         /// class with the specified message.
         /// </summary>
-        public InvalidEnumArgumentException(string message) : base(message)
+        public InvalidEnumArgumentException(string? message) : base(message)
         {
         }
 
@@ -34,7 +34,7 @@ namespace System.ComponentModel
         /// Initializes a new instance of the Exception class with a specified error message
         /// and a reference to the inner exception that is the cause of this exception.
         /// </summary>
-        public InvalidEnumArgumentException(string message, Exception innerException)
+        public InvalidEnumArgumentException(string? message, Exception? innerException)
             : base(message, innerException)
         {
         }
@@ -44,7 +44,7 @@ namespace System.ComponentModel
         /// class with a message generated from the argument, invalid value, and
         /// enumeration class.
         /// </summary>
-        public InvalidEnumArgumentException(string argumentName, int invalidValue, Type enumClass)
+        public InvalidEnumArgumentException(string? argumentName, int invalidValue, Type enumClass)
             : base(SR.Format(SR.InvalidEnumArgument,
                                 argumentName,
                                 invalidValue,
index 0eaf049..a83e0e2 100644 (file)
@@ -42,16 +42,8 @@ namespace System.ComponentModel
         /// </summary>
         public static readonly LocalizableAttribute Default = No;
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            LocalizableAttribute other = obj as LocalizableAttribute;
-            return other?.IsLocalizable == IsLocalizable;
-        }
+        public override bool Equals(object? obj) =>
+            obj is LocalizableAttribute other && other.IsLocalizable == IsLocalizable;
 
         public override int GetHashCode() => base.GetHashCode();
 
index 8424ac8..8779416 100644 (file)
@@ -48,16 +48,8 @@ namespace System.ComponentModel
         /// </summary>
         public bool AllowMerge { get; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            MergablePropertyAttribute other = obj as MergablePropertyAttribute;
-            return other?.AllowMerge == AllowMerge;
-        }
+        public override bool Equals(object? obj) =>
+            obj is MergablePropertyAttribute other && other.AllowMerge == AllowMerge;
 
         public override int GetHashCode() => base.GetHashCode();
 
index f3064db..3149c87 100644 (file)
@@ -50,16 +50,8 @@ namespace System.ComponentModel
         /// <summary>
         /// Tests whether the specified object is the same as the current object.
         /// </summary>
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            NotifyParentPropertyAttribute other = obj as NotifyParentPropertyAttribute;
-            return other?.NotifyParent == NotifyParent;
-        }
+        public override bool Equals(object? obj) =>
+            obj is NotifyParentPropertyAttribute other && other.NotifyParent == NotifyParent;
 
         public override int GetHashCode() => base.GetHashCode();
 
index e1829b3..a1f1a84 100644 (file)
@@ -40,16 +40,8 @@ namespace System.ComponentModel
         /// <summary>
         /// Compares the specified object to this object and tests for equality.
         /// </summary>
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            ParenthesizePropertyNameAttribute other = obj as ParenthesizePropertyNameAttribute;
-            return other?.NeedParenthesis == NeedParenthesis;
-        }
+        public override bool Equals(object? obj) =>
+            obj is ParenthesizePropertyNameAttribute other && other.NeedParenthesis == NeedParenthesis;
 
         public override int GetHashCode() => base.GetHashCode();
 
index 67fed53..341360c 100644 (file)
@@ -43,16 +43,8 @@ namespace System.ComponentModel
         /// </summary>
         public bool IsReadOnly { get; }
 
-        public override bool Equals(object value)
-        {
-            if (this == value)
-            {
-                return true;
-            }
-
-            ReadOnlyAttribute other = value as ReadOnlyAttribute;
-            return other?.IsReadOnly == IsReadOnly;
-        }
+        public override bool Equals(object? value) =>
+            value is ReadOnlyAttribute other && other.IsReadOnly == IsReadOnly;
 
         public override int GetHashCode() => base.GetHashCode();
 
index 6f648e8..19f27e1 100644 (file)
@@ -38,16 +38,8 @@ namespace System.ComponentModel
         /// </summary>
         public RefreshProperties RefreshProperties { get; }
 
-        public override bool Equals(object obj)
-        {
-            if (obj == this)
-            {
-                return true;
-            }
-
-            RefreshPropertiesAttribute other = obj as RefreshPropertiesAttribute;
-            return other?.RefreshProperties == RefreshProperties;
-        }
+        public override bool Equals(object? obj) =>
+            obj is RefreshPropertiesAttribute other && other.RefreshProperties == RefreshProperties;
 
         public override int GetHashCode() => base.GetHashCode();
 
index ba8d5b5..7fd5d5f 100644 (file)
@@ -9,7 +9,7 @@ namespace System
 {
     public partial interface IServiceProvider
     {
-        object? GetService(System.Type? serviceType);
+        object? GetService(System.Type serviceType);
     }
 }
 namespace System.ComponentModel