From: buyaa-n Date: Tue, 24 Sep 2019 17:05:58 +0000 (-0700) Subject: Annotate System.ComponentModel.Primitives for nullable (dotnet/corefx#41185) X-Git-Tag: submit/tizen/20210909.063632~11031^2~416 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2491c6d06ed96eba2a1441398fc78cf58ff3679f;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Annotate System.ComponentModel.Primitives for nullable (dotnet/corefx#41185) * Annotate System.ComponentModel.Primitives for nullable Commit migrated from https://github.com/dotnet/corefx/commit/da147ece700c2502b91e57d99213feadcfb9c1f0 --- diff --git a/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs b/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs index 3b7d893..a43aac8 100644 --- a/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs +++ b/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs @@ -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; } } diff --git a/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.csproj b/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.csproj index 5a694eb..df7ed1d 100644 --- a/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.csproj +++ b/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.csproj @@ -1,6 +1,7 @@ netcoreapp-Debug;netcoreapp-Release;uap-Debug;uap-Release + enable diff --git a/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj b/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj index eebf768..70db1a4 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj +++ b/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj @@ -3,6 +3,7 @@ System.ComponentModel.Primitives System.ComponentModel.Primitives netcoreapp-Debug;netcoreapp-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release + enable diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/BrowsableAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/BrowsableAttribute.cs index 9c0086b..07f1f43 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/BrowsableAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/BrowsableAttribute.cs @@ -43,16 +43,8 @@ namespace System.ComponentModel /// 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs index 9572587..5cd50e9 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs @@ -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; /// /// Looks up the localized name of a given category. /// - 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; } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/Component.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/Component.cs index 28f0fbc..4de5064 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/Component.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/Component.cs @@ -16,8 +16,8 @@ namespace System.ComponentModel /// 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 /// [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 /// [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 /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public IContainer Container => _site?.Container; + public IContainer? Container => _site?.Container; /// /// Returns an object representing a service provided by /// the . /// - protected virtual object GetService(Type service) => _site?.GetService(service); + protected virtual object? GetService(Type service) => _site?.GetService(service); /// /// Gets a value indicating whether the @@ -122,10 +122,10 @@ namespace System.ComponentModel /// public override string ToString() { - ISite s = _site; + ISite? s = _site; if (s == null) { - return GetType().FullName; + return GetType().FullName!; } return s.Name + " [" + GetType().FullName + "]"; diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ComponentCollection.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ComponentCollection.cs index 8edfbd8..011c325 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ComponentCollection.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ComponentCollection.cs @@ -14,14 +14,14 @@ namespace System.ComponentModel /// Gets a specific in the /// . /// - 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 in the /// . /// - 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); } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DescriptionAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DescriptionAttribute.cs index 759e6e8..31e29ee 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DescriptionAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DescriptionAttribute.cs @@ -40,16 +40,8 @@ namespace System.ComponentModel /// 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; diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignOnlyAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignOnlyAttribute.cs index 8d680f6..31c3b3c 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignOnlyAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignOnlyAttribute.cs @@ -42,16 +42,8 @@ namespace System.ComponentModel /// 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerCategoryAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerCategoryAttribute.cs index 83cca46b..5e99500 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerCategoryAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerCategoryAttribute.cs @@ -56,16 +56,8 @@ namespace System.ComponentModel /// 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; diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerSerializationVisibilityAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerSerializationVisibilityAttribute.cs index 55433d7..8a0cb3a 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerSerializationVisibilityAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerSerializationVisibilityAttribute.cs @@ -52,16 +52,8 @@ namespace System.ComponentModel /// 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DisplayNameAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DisplayNameAttribute.cs index f51f464..d9e58ea 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DisplayNameAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DisplayNameAttribute.cs @@ -39,16 +39,8 @@ namespace System.ComponentModel /// 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; diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EventHandlerList.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EventHandlerList.cs index 97079e1..c35517a 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EventHandlerList.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EventHandlerList.cs @@ -9,8 +9,8 @@ namespace System.ComponentModel /// public sealed class EventHandlerList : IDisposable { - private ListEntry _head; - private readonly Component _parent; + private ListEntry? _head; + private readonly Component? _parent; /// /// Creates a new event handler list. The parent component is used to check the @@ -31,11 +31,11 @@ namespace System.ComponentModel /// /// Gets or sets the delegate for the specified key. /// - 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; diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IComponent.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IComponent.cs index fab87be..bbe9a34 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IComponent.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IComponent.cs @@ -26,11 +26,11 @@ namespace System.ComponentModel /// When implemented by a class, gets or sets the /// associated with the . /// - ISite Site { get; set; } + ISite? Site { get; set; } /// /// Adds an event handler to listen to the Disposed event on the component. /// - event EventHandler Disposed; + event EventHandler? Disposed; } } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IContainer.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IContainer.cs index 49e8ca7..000558c 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IContainer.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/IContainer.cs @@ -20,7 +20,7 @@ namespace System.ComponentModel /// Adds the specified to the /// at the end of the list. /// - void Add(IComponent component); + void Add(IComponent? component); // Adds a component to the container. /// @@ -28,7 +28,7 @@ namespace System.ComponentModel /// at the end of the list, /// and assigns a name to the component. /// - void Add(IComponent component, string name); + void Add(IComponent? component, string? name); /// /// Gets all the components in the . @@ -38,6 +38,6 @@ namespace System.ComponentModel /// /// Removes a component from the . /// - void Remove(IComponent component); + void Remove(IComponent? component); } } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISite.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISite.cs index 46c51a1..a7730b5 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISite.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISite.cs @@ -38,6 +38,6 @@ namespace System.ComponentModel /// When implemented by a class, gets or sets the name of the component /// associated with the . /// - string Name { get; set; } + string? Name { get; set; } } } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISynchronizeInvoke.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISynchronizeInvoke.cs index c3156f4..d6845b3 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISynchronizeInvoke.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ISynchronizeInvoke.cs @@ -18,17 +18,17 @@ namespace System.ComponentModel /// /// Executes the given delegate on the main thread that this object executes on. /// - IAsyncResult BeginInvoke(Delegate method, object[] args); + IAsyncResult BeginInvoke(Delegate method, object?[]? args); /// /// Waits until the process you started by calling /// completes, and then returns the value generated by the process. /// - object EndInvoke(IAsyncResult result); + object? EndInvoke(IAsyncResult result); /// /// Executes the given delegate on the main thread that this object executes on. /// - object Invoke(Delegate method, object[] args); + object? Invoke(Delegate method, object?[]? args); } } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ImmutableObjectAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ImmutableObjectAttribute.cs index b6272de..a0eea4b 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ImmutableObjectAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ImmutableObjectAttribute.cs @@ -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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidAsynchronousStateException.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidAsynchronousStateException.cs index d4f6b8a..e9729df 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidAsynchronousStateException.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidAsynchronousStateException.cs @@ -27,7 +27,7 @@ namespace System.ComponentModel /// Initializes a new instance of the /// class with the specified message. /// - 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. /// - public InvalidAsynchronousStateException(string message, Exception innerException) : base(message, innerException) + public InvalidAsynchronousStateException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.cs index fe63ee1..39ec123 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.cs @@ -26,7 +26,7 @@ namespace System.ComponentModel /// Initializes a new instance of the /// class with the specified message. /// - 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. /// - 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. /// - public InvalidEnumArgumentException(string argumentName, int invalidValue, Type enumClass) + public InvalidEnumArgumentException(string? argumentName, int invalidValue, Type enumClass) : base(SR.Format(SR.InvalidEnumArgument, argumentName, invalidValue, diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/LocalizableAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/LocalizableAttribute.cs index 0eaf049..a83e0e2 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/LocalizableAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/LocalizableAttribute.cs @@ -42,16 +42,8 @@ namespace System.ComponentModel /// 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/MergablePropertyAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/MergablePropertyAttribute.cs index 8424ac8..8779416 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/MergablePropertyAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/MergablePropertyAttribute.cs @@ -48,16 +48,8 @@ namespace System.ComponentModel /// 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/NotifyParentPropertyAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/NotifyParentPropertyAttribute.cs index f3064db..3149c87 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/NotifyParentPropertyAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/NotifyParentPropertyAttribute.cs @@ -50,16 +50,8 @@ namespace System.ComponentModel /// /// Tests whether the specified object is the same as the current object. /// - 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ParenthesizePropertyNameAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ParenthesizePropertyNameAttribute.cs index e1829b3..a1f1a84 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ParenthesizePropertyNameAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ParenthesizePropertyNameAttribute.cs @@ -40,16 +40,8 @@ namespace System.ComponentModel /// /// Compares the specified object to this object and tests for equality. /// - 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ReadOnlyAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ReadOnlyAttribute.cs index 67fed53..341360c 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ReadOnlyAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/ReadOnlyAttribute.cs @@ -43,16 +43,8 @@ namespace System.ComponentModel /// 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(); diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/RefreshPropertiesAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/RefreshPropertiesAttribute.cs index 6f648e8..19f27e1 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/RefreshPropertiesAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/RefreshPropertiesAttribute.cs @@ -38,16 +38,8 @@ namespace System.ComponentModel /// 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(); diff --git a/src/libraries/System.ComponentModel/ref/System.ComponentModel.cs b/src/libraries/System.ComponentModel/ref/System.ComponentModel.cs index ba8d5b5..7fd5d5f 100644 --- a/src/libraries/System.ComponentModel/ref/System.ComponentModel.cs +++ b/src/libraries/System.ComponentModel/ref/System.ComponentModel.cs @@ -9,7 +9,7 @@ namespace System { public partial interface IServiceProvider { - object? GetService(System.Type? serviceType); + object? GetService(System.Type serviceType); } } namespace System.ComponentModel