Annotate System.ObjectModel for nullable (dotnet/corefx#41808)
authorbuyaa-n <bunamnan@microsoft.com>
Fri, 18 Oct 2019 16:40:35 +0000 (09:40 -0700)
committerGitHub <noreply@github.com>
Fri, 18 Oct 2019 16:40:35 +0000 (09:40 -0700)
Annotate System.ObjectModel for nullable

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

22 files changed:
src/libraries/System.ObjectModel/ref/System.ObjectModel.cs
src/libraries/System.ObjectModel/ref/System.ObjectModel.csproj
src/libraries/System.ObjectModel/src/System.ObjectModel.csproj
src/libraries/System.ObjectModel/src/System/Collections/Generic/DebugView.cs
src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/KeyedCollection.cs
src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs
src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs
src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/ReadOnlyObservableCollection.cs
src/libraries/System.ObjectModel/src/System/Collections/Specialized/INotifyCollectionChanged.cs
src/libraries/System.ObjectModel/src/System/Collections/Specialized/NotifyCollectionChangedEventArgs.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/DataErrorsChangedEventArgs.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/INotifyDataErrorInfo.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/INotifyPropertyChanged.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/INotifyPropertyChanging.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/PropertyChangedEventArgs.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/PropertyChangedEventHandler.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/PropertyChangingEventArgs.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/PropertyChangingEventHandler.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/TypeConverterAttribute.cs
src/libraries/System.ObjectModel/src/System/ComponentModel/TypeDescriptionProviderAttribute.cs
src/libraries/System.ObjectModel/src/System/Windows/Input/ICommand.cs
src/libraries/System.ObjectModel/src/System/Windows/Markup/ValueSerializerAttribute.cs

index c83c468..fb2e858 100644 (file)
@@ -7,13 +7,13 @@
 
 namespace System.Collections.ObjectModel
 {
-    public abstract partial class KeyedCollection<TKey, TItem> : System.Collections.ObjectModel.Collection<TItem>
+    public abstract partial class KeyedCollection<TKey, TItem> : System.Collections.ObjectModel.Collection<TItem> where TKey : notnull
     {
         protected KeyedCollection() { }
-        protected KeyedCollection(System.Collections.Generic.IEqualityComparer<TKey> comparer) { }
-        protected KeyedCollection(System.Collections.Generic.IEqualityComparer<TKey> comparer, int dictionaryCreationThreshold) { }
+        protected KeyedCollection(System.Collections.Generic.IEqualityComparer<TKey>? comparer) { }
+        protected KeyedCollection(System.Collections.Generic.IEqualityComparer<TKey>? comparer, int dictionaryCreationThreshold) { }
         public System.Collections.Generic.IEqualityComparer<TKey> Comparer { get { throw null; } }
-        protected System.Collections.Generic.IDictionary<TKey, TItem> Dictionary { get { throw null; } }
+        protected System.Collections.Generic.IDictionary<TKey, TItem>? Dictionary { get { throw null; } }
         public TItem this[TKey key] { get { throw null; } }
         protected void ChangeItemKey(TItem item, TKey newKey) { }
         protected override void ClearItems() { }
@@ -23,16 +23,16 @@ namespace System.Collections.ObjectModel
         public bool Remove(TKey key) { throw null; }
         protected override void RemoveItem(int index) { }
         protected override void SetItem(int index, TItem item) { }
-        public bool TryGetValue(TKey key, out TItem item) { throw null; }
+        public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TItem item) { throw null; }
     }
     public partial class ObservableCollection<T> : System.Collections.ObjectModel.Collection<T>, System.Collections.Specialized.INotifyCollectionChanged, System.ComponentModel.INotifyPropertyChanged
     {
         public ObservableCollection() { }
         public ObservableCollection(System.Collections.Generic.IEnumerable<T> collection) { }
         public ObservableCollection(System.Collections.Generic.List<T> list) { }
-        public virtual event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChanged { add { } remove { } }
-        protected virtual event System.ComponentModel.PropertyChangedEventHandler PropertyChanged { add { } remove { } }
-        event System.ComponentModel.PropertyChangedEventHandler System.ComponentModel.INotifyPropertyChanged.PropertyChanged { add { } remove { } }
+        public virtual event System.Collections.Specialized.NotifyCollectionChangedEventHandler? CollectionChanged { add { } remove { } }
+        protected virtual event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged { add { } remove { } }
+        event System.ComponentModel.PropertyChangedEventHandler? System.ComponentModel.INotifyPropertyChanged.PropertyChanged { add { } remove { } }
         protected System.IDisposable BlockReentrancy() { throw null; }
         protected void CheckReentrancy() { }
         protected override void ClearItems() { }
@@ -44,7 +44,7 @@ namespace System.Collections.ObjectModel
         protected override void RemoveItem(int index) { }
         protected override void SetItem(int index, T item) { }
     }
-    public partial class ReadOnlyDictionary<TKey, TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable
+    public partial class ReadOnlyDictionary<TKey, TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable where TKey : notnull
     {
         public ReadOnlyDictionary(System.Collections.Generic.IDictionary<TKey, TValue> dictionary) { }
         public int Count { get { throw null; } }
@@ -61,7 +61,7 @@ namespace System.Collections.ObjectModel
         object System.Collections.ICollection.SyncRoot { get { throw null; } }
         bool System.Collections.IDictionary.IsFixedSize { get { throw null; } }
         bool System.Collections.IDictionary.IsReadOnly { get { throw null; } }
-        object System.Collections.IDictionary.this[object key] { get { throw null; } set { } }
+        object? System.Collections.IDictionary.this[object key] { get { throw null; } set { } }
         System.Collections.ICollection System.Collections.IDictionary.Keys { get { throw null; } }
         System.Collections.ICollection System.Collections.IDictionary.Values { get { throw null; } }
         public System.Collections.ObjectModel.ReadOnlyDictionary<TKey, TValue>.ValueCollection Values { get { throw null; } }
@@ -75,13 +75,13 @@ namespace System.Collections.ObjectModel
         void System.Collections.Generic.IDictionary<TKey,TValue>.Add(TKey key, TValue value) { }
         bool System.Collections.Generic.IDictionary<TKey,TValue>.Remove(TKey key) { throw null; }
         void System.Collections.ICollection.CopyTo(System.Array array, int index) { }
-        void System.Collections.IDictionary.Add(object key, object value) { }
+        void System.Collections.IDictionary.Add(object key, object? value) { }
         void System.Collections.IDictionary.Clear() { }
         bool System.Collections.IDictionary.Contains(object key) { throw null; }
         System.Collections.IDictionaryEnumerator System.Collections.IDictionary.GetEnumerator() { throw null; }
         void System.Collections.IDictionary.Remove(object key) { }
         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
-        public bool TryGetValue(TKey key, out TValue value) { throw null; }
+        public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
         public sealed partial class KeyCollection : System.Collections.Generic.ICollection<TKey>, System.Collections.Generic.IEnumerable<TKey>, System.Collections.Generic.IReadOnlyCollection<TKey>, System.Collections.ICollection, System.Collections.IEnumerable
         {
             internal KeyCollection() { }
@@ -118,10 +118,10 @@ namespace System.Collections.ObjectModel
     public partial class ReadOnlyObservableCollection<T> : System.Collections.ObjectModel.ReadOnlyCollection<T>, System.Collections.Specialized.INotifyCollectionChanged, System.ComponentModel.INotifyPropertyChanged
     {
         public ReadOnlyObservableCollection(System.Collections.ObjectModel.ObservableCollection<T> list) : base (default(System.Collections.Generic.IList<T>)) { }
-        protected virtual event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChanged { add { } remove { } }
-        protected virtual event System.ComponentModel.PropertyChangedEventHandler PropertyChanged { add { } remove { } }
-        event System.Collections.Specialized.NotifyCollectionChangedEventHandler System.Collections.Specialized.INotifyCollectionChanged.CollectionChanged { add { } remove { } }
-        event System.ComponentModel.PropertyChangedEventHandler System.ComponentModel.INotifyPropertyChanged.PropertyChanged { add { } remove { } }
+        protected virtual event System.Collections.Specialized.NotifyCollectionChangedEventHandler? CollectionChanged { add { } remove { } }
+        protected virtual event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged { add { } remove { } }
+        event System.Collections.Specialized.NotifyCollectionChangedEventHandler? System.Collections.Specialized.INotifyCollectionChanged.CollectionChanged { add { } remove { } }
+        event System.ComponentModel.PropertyChangedEventHandler? System.ComponentModel.INotifyPropertyChanged.PropertyChanged { add { } remove { } }
         protected virtual void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) { }
         protected virtual void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args) { }
     }
@@ -130,7 +130,7 @@ namespace System.Collections.Specialized
 {
     public partial interface INotifyCollectionChanged
     {
-        event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChanged;
+        event System.Collections.Specialized.NotifyCollectionChangedEventHandler? CollectionChanged;
     }
     public enum NotifyCollectionChangedAction
     {
@@ -143,57 +143,57 @@ namespace System.Collections.Specialized
     public partial class NotifyCollectionChangedEventArgs : System.EventArgs
     {
         public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList changedItems) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList? changedItems) { }
         public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList newItems, System.Collections.IList oldItems) { }
         public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList newItems, System.Collections.IList oldItems, int startingIndex) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList changedItems, int startingIndex) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList changedItems, int index, int oldIndex) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object changedItem) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object changedItem, int index) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object changedItem, int index, int oldIndex) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object newItem, object oldItem) { }
-        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object newItem, object oldItem, int index) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList? changedItems, int startingIndex) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.IList? changedItems, int index, int oldIndex) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object? changedItem) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object? changedItem, int index) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object? changedItem, int index, int oldIndex) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object? newItem, object? oldItem) { }
+        public NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction action, object? newItem, object? oldItem, int index) { }
         public System.Collections.Specialized.NotifyCollectionChangedAction Action { get { throw null; } }
-        public System.Collections.IList NewItems { get { throw null; } }
+        public System.Collections.IList? NewItems { get { throw null; } }
         public int NewStartingIndex { get { throw null; } }
-        public System.Collections.IList OldItems { get { throw null; } }
+        public System.Collections.IList? OldItems { get { throw null; } }
         public int OldStartingIndex { get { throw null; } }
     }
-    public delegate void NotifyCollectionChangedEventHandler(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e);
+    public delegate void NotifyCollectionChangedEventHandler(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e);
 }
 namespace System.ComponentModel
 {
     public partial class DataErrorsChangedEventArgs : System.EventArgs
     {
-        public DataErrorsChangedEventArgs(string propertyName) { }
-        public virtual string PropertyName { get { throw null; } }
+        public DataErrorsChangedEventArgs(string? propertyName) { }
+        public virtual string? PropertyName { get { throw null; } }
     }
     public partial interface INotifyDataErrorInfo
     {
         bool HasErrors { get; }
-        event System.EventHandler<System.ComponentModel.DataErrorsChangedEventArgs> ErrorsChanged;
-        System.Collections.IEnumerable GetErrors(string propertyName);
+        event System.EventHandler<System.ComponentModel.DataErrorsChangedEventArgs>? ErrorsChanged;
+        System.Collections.IEnumerable GetErrors(string? propertyName);
     }
     public partial interface INotifyPropertyChanged
     {
-        event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
+        event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;
     }
     public partial interface INotifyPropertyChanging
     {
-        event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
+        event System.ComponentModel.PropertyChangingEventHandler? PropertyChanging;
     }
     public partial class PropertyChangedEventArgs : System.EventArgs
     {
-        public PropertyChangedEventArgs(string propertyName) { }
-        public virtual string PropertyName { get { throw null; } }
+        public PropertyChangedEventArgs(string? propertyName) { }
+        public virtual string? PropertyName { get { throw null; } }
     }
-    public delegate void PropertyChangedEventHandler(object sender, System.ComponentModel.PropertyChangedEventArgs e);
+    public delegate void PropertyChangedEventHandler(object? sender, System.ComponentModel.PropertyChangedEventArgs e);
     public partial class PropertyChangingEventArgs : System.EventArgs
     {
-        public PropertyChangingEventArgs(string propertyName) { }
-        public virtual string PropertyName { get { throw null; } }
+        public PropertyChangingEventArgs(string? propertyName) { }
+        public virtual string? PropertyName { get { throw null; } }
     }
-    public delegate void PropertyChangingEventHandler(object sender, System.ComponentModel.PropertyChangingEventArgs e);
+    public delegate void PropertyChangingEventHandler(object? sender, System.ComponentModel.PropertyChangingEventArgs e);
     [System.AttributeUsageAttribute(System.AttributeTargets.All)]
     public sealed partial class TypeConverterAttribute : System.Attribute
     {
@@ -202,7 +202,7 @@ namespace System.ComponentModel
         public TypeConverterAttribute(string typeName) { }
         public TypeConverterAttribute(System.Type type) { }
         public string ConverterTypeName { 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; }
     }
     [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=true)]
@@ -227,8 +227,8 @@ namespace System.Windows.Input
     public partial interface ICommand
     {
         event System.EventHandler CanExecuteChanged;
-        bool CanExecute(object parameter);
-        void Execute(object parameter);
+        bool CanExecute(object? parameter);
+        void Execute(object? parameter);
     }
 }
 namespace System.Windows.Markup
index cb2c4b1..bafa956 100644 (file)
@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System.ObjectModel.cs" />
index c879041..d04f9eb 100644 (file)
@@ -3,6 +3,7 @@
     <AssemblyName>System.ObjectModel</AssemblyName>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System\Collections\Generic\DebugView.cs" />
index 7e47757..0e7a977 100644 (file)
@@ -27,7 +27,7 @@ namespace System.Collections.Generic
         }
     }
 
-    internal sealed class DictionaryDebugView<K, V>
+    internal sealed class DictionaryDebugView<K, V> where K: notnull
     {
         private readonly IDictionary<K, V> _dict;
 
index 896bc8e..344acbb 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 
 namespace System.Collections.ObjectModel
 {
@@ -11,12 +12,12 @@ namespace System.Collections.ObjectModel
     [DebuggerTypeProxy(typeof(CollectionDebugView<>))]
     [DebuggerDisplay("Count = {Count}")]
     [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public abstract class KeyedCollection<TKey, TItem> : Collection<TItem>
+    public abstract class KeyedCollection<TKey, TItem> : Collection<TItem> where TKey: notnull
     {
         private const int DefaultThreshold = 0;
 
         private readonly IEqualityComparer<TKey> comparer; // Do not rename (binary serialization)
-        private Dictionary<TKey, TItem> dict; // Do not rename (binary serialization)
+        private Dictionary<TKey, TItem>? dict; // Do not rename (binary serialization)
         private int keyCount; // Do not rename (binary serialization)
         private readonly int threshold; // Do not rename (binary serialization)
 
@@ -24,11 +25,11 @@ namespace System.Collections.ObjectModel
         {
         }
 
-        protected KeyedCollection(IEqualityComparer<TKey> comparer) : this(comparer, DefaultThreshold)
+        protected KeyedCollection(IEqualityComparer<TKey>? comparer) : this(comparer, DefaultThreshold)
         {
         }
 
-        protected KeyedCollection(IEqualityComparer<TKey> comparer, int dictionaryCreationThreshold)
+        protected KeyedCollection(IEqualityComparer<TKey>? comparer, int dictionaryCreationThreshold)
             : base(new List<TItem>()) // Be explicit about the use of List<T> so we can foreach over
                                       // Items internally without enumerator allocations.
         {
@@ -60,7 +61,7 @@ namespace System.Collections.ObjectModel
             get
             {
                 TItem item;
-                if (TryGetValue(key, out item))
+                if (TryGetValue(key, out item!))
                 {
                     return item;
                 }
@@ -92,7 +93,7 @@ namespace System.Collections.ObjectModel
             return false;
         }
 
-        public bool TryGetValue(TKey key, out TItem item)
+        public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TItem item)
         {
             if (key == null)
             {
@@ -101,7 +102,7 @@ namespace System.Collections.ObjectModel
 
             if (dict != null)
             {
-                return dict.TryGetValue(key, out item);
+                return dict.TryGetValue(key, out item!);
             }
 
             foreach (TItem itemInItems in Items)
@@ -114,7 +115,7 @@ namespace System.Collections.ObjectModel
                 }
             }
 
-            item = default(TItem);
+            item = default(TItem)!;
             return false;
         }
 
@@ -126,7 +127,8 @@ namespace System.Collections.ObjectModel
                 return Items.Contains(item);
             }
 
-            if (dict.TryGetValue(key, out TItem itemInDict))
+            TItem itemInDict;
+            if (dict.TryGetValue(key, out itemInDict!))
             {
                 return EqualityComparer<TItem>.Default.Equals(itemInDict, item);
             }
@@ -143,7 +145,8 @@ namespace System.Collections.ObjectModel
 
             if (dict != null)
             {
-                return dict.TryGetValue(key, out TItem item) && Remove(item);
+                TItem item;
+                return dict.TryGetValue(key, out item!) && Remove(item);
             }
 
             for (int i = 0; i < Items.Count; i++)
@@ -158,7 +161,7 @@ namespace System.Collections.ObjectModel
             return false;
         }
 
-        protected IDictionary<TKey, TItem> Dictionary => dict;
+        protected IDictionary<TKey, TItem>? Dictionary => dict;
 
         protected void ChangeItemKey(TItem item, TKey newKey)
         {
@@ -249,7 +252,7 @@ namespace System.Collections.ObjectModel
             else if (keyCount == threshold)
             {
                 CreateDictionary();
-                dict.Add(key, item);
+                dict!.Add(key, item);
             }
             else
             {
index f74a2c8..5e837d7 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Collections.ObjectModel
     [System.Runtime.CompilerServices.TypeForwardedFrom("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
     public class ObservableCollection<T> : Collection<T>, INotifyCollectionChanged, INotifyPropertyChanged
     {
-        private SimpleMonitor _monitor; // Lazily allocated only when a subclass calls BlockReentrancy() or during serialization. Do not rename (binary serialization)
+        private SimpleMonitor? _monitor; // Lazily allocated only when a subclass calls BlockReentrancy() or during serialization. Do not rename (binary serialization)
 
         [NonSerialized]
         private int _blockReentrancyCount;
@@ -82,7 +82,7 @@ namespace System.Collections.ObjectModel
         /// <summary>
         /// PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
         /// </summary>
-        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
+        event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged
         {
             add => PropertyChanged += value;
             remove => PropertyChanged -= value;
@@ -95,7 +95,7 @@ namespace System.Collections.ObjectModel
         /// see <seealso cref="INotifyCollectionChanged"/>
         /// </remarks>
         [field: NonSerialized]
-        public virtual event NotifyCollectionChangedEventHandler CollectionChanged;
+        public virtual event NotifyCollectionChangedEventHandler? CollectionChanged;
 
         /// <summary>
         /// Called by base class Collection&lt;T&gt; when the list is being cleared;
@@ -183,7 +183,7 @@ namespace System.Collections.ObjectModel
         /// PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
         /// </summary>
         [field: NonSerialized]
-        protected virtual event PropertyChangedEventHandler PropertyChanged;
+        protected virtual event PropertyChangedEventHandler? PropertyChanged;
 
         /// <summary>
         /// Raise CollectionChanged event to any listeners.
@@ -196,7 +196,7 @@ namespace System.Collections.ObjectModel
         /// </remarks>
         protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
         {
-            NotifyCollectionChangedEventHandler handler = CollectionChanged;
+            NotifyCollectionChangedEventHandler? handler = CollectionChanged;
             if (handler != null)
             {
                 // Not calling BlockReentrancy() here to avoid the SimpleMonitor allocation.
@@ -260,7 +260,7 @@ namespace System.Collections.ObjectModel
         /// <summary>
         /// Helper to raise CollectionChanged event to any listeners
         /// </summary>
-        private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index)
+        private void OnCollectionChanged(NotifyCollectionChangedAction action, object? item, int index)
         {
             OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index));
         }
@@ -268,7 +268,7 @@ namespace System.Collections.ObjectModel
         /// <summary>
         /// Helper to raise CollectionChanged event to any listeners
         /// </summary>
-        private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index, int oldIndex)
+        private void OnCollectionChanged(NotifyCollectionChangedAction action, object? item, int index, int oldIndex)
         {
             OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index, oldIndex));
         }
@@ -276,7 +276,7 @@ namespace System.Collections.ObjectModel
         /// <summary>
         /// Helper to raise CollectionChanged event to any listeners
         /// </summary>
-        private void OnCollectionChanged(NotifyCollectionChangedAction action, object oldItem, object newItem, int index)
+        private void OnCollectionChanged(NotifyCollectionChangedAction action, object? oldItem, object? newItem, int index)
         {
             OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, newItem, oldItem, index));
         }
@@ -286,16 +286,13 @@ namespace System.Collections.ObjectModel
         /// </summary>
         private void OnCollectionReset() => OnCollectionChanged(EventArgsCache.ResetCollectionChanged);
 
-        private SimpleMonitor EnsureMonitorInitialized()
-        {
-            return _monitor ?? (_monitor = new SimpleMonitor(this));
-        }
+        private SimpleMonitor EnsureMonitorInitialized() => _monitor ??= new SimpleMonitor(this);
 
         [OnSerializing]
         private void OnSerializing(StreamingContext context)
         {
             EnsureMonitorInitialized();
-            _monitor._busyCount = _blockReentrancyCount;
+            _monitor!._busyCount = _blockReentrancyCount;
         }
 
         [OnDeserialized]
index a370d7c..efe1b67 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 
 namespace System.Collections.ObjectModel
 {
@@ -11,14 +12,14 @@ namespace System.Collections.ObjectModel
     [DebuggerTypeProxy(typeof(DictionaryDebugView<,>))]
     [DebuggerDisplay("Count = {Count}")]
     [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>
+    public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue> where TKey : notnull
     {
         private readonly IDictionary<TKey, TValue> m_dictionary; // Do not rename (binary serialization)
 
         [NonSerialized]
-        private KeyCollection _keys;
+        private KeyCollection? _keys;
         [NonSerialized]
-        private ValueCollection _values;
+        private ValueCollection? _values;
 
         public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
         {
@@ -41,9 +42,9 @@ namespace System.Collections.ObjectModel
 
         ICollection<TKey> IDictionary<TKey, TValue>.Keys => Keys;
 
-        public bool TryGetValue(TKey key, out TValue value)
+        public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
         {
-            return m_dictionary.TryGetValue(key, out value);
+            return m_dictionary.TryGetValue(key, out value!);
         }
 
         ICollection<TValue> IDictionary<TKey, TValue>.Values => Values;
@@ -115,7 +116,7 @@ namespace System.Collections.ObjectModel
             return key is TKey;
         }
 
-        void IDictionary.Add(object key, object value)
+        void IDictionary.Add(object key, object? value)
         {
             throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
         }
@@ -132,8 +133,7 @@ namespace System.Collections.ObjectModel
 
         IDictionaryEnumerator IDictionary.GetEnumerator()
         {
-            IDictionary d = m_dictionary as IDictionary;
-            if (d != null)
+            if (m_dictionary is IDictionary d)
             {
                 return d.GetEnumerator();
             }
@@ -153,7 +153,7 @@ namespace System.Collections.ObjectModel
 
         ICollection IDictionary.Values => Values;
 
-        object IDictionary.this[object key]
+        object? IDictionary.this[object key]
         {
             get
             {
@@ -190,15 +190,13 @@ namespace System.Collections.ObjectModel
                 throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
             }
 
-            KeyValuePair<TKey, TValue>[] pairs = array as KeyValuePair<TKey, TValue>[];
-            if (pairs != null)
+            if (array is KeyValuePair<TKey, TValue>[] pairs)
             {
                 m_dictionary.CopyTo(pairs, index);
             }
             else
             {
-                DictionaryEntry[] dictEntryArray = array as DictionaryEntry[];
-                if (dictEntryArray != null)
+                if (array is DictionaryEntry[] dictEntryArray)
                 {
                     foreach (var item in m_dictionary)
                     {
@@ -207,7 +205,7 @@ namespace System.Collections.ObjectModel
                 }
                 else
                 {
-                    object[] objects = array as object[];
+                    object[]? objects = array as object[];
                     if (objects == null)
                     {
                         throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array));
@@ -250,7 +248,7 @@ namespace System.Collections.ObjectModel
 
             public object Key => _enumerator.Current.Key;
 
-            public object Value => _enumerator.Current.Value;
+            public object? Value => _enumerator.Current.Value;
 
             public object Current => Entry;
 
@@ -396,15 +394,13 @@ namespace System.Collections.ObjectModel
             }
 
             // Easy out if the ICollection<T> implements the non-generic ICollection
-            ICollection nonGenericCollection = collection as ICollection;
-            if (nonGenericCollection != null)
+            if (collection is ICollection nonGenericCollection)
             {
                 nonGenericCollection.CopyTo(array, index);
                 return;
             }
 
-            T[] items = array as T[];
-            if (items != null)
+            if (array is T[] items)
             {
                 collection.CopyTo(items, index);
             }
@@ -412,7 +408,7 @@ namespace System.Collections.ObjectModel
             {
                 // We can't cast array of value type to object[], so we don't support
                 // widening of primitive types here.
-                object[] objects = array as object[];
+                object?[]? objects = array as object?[];
                 if (objects == null)
                 {
                     throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array));
index c736d74..794108a 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Collections.ObjectModel
         /// <summary>
         /// CollectionChanged event (per <see cref="INotifyCollectionChanged" />).
         /// </summary>
-        event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
+        event NotifyCollectionChangedEventHandler? INotifyCollectionChanged.CollectionChanged
         {
             add => CollectionChanged += value;
             remove => CollectionChanged -= value;
@@ -45,7 +45,7 @@ namespace System.Collections.ObjectModel
         /// see <seealso cref="INotifyCollectionChanged"/>
         /// </remarks>
         [field: NonSerialized]
-        protected virtual event NotifyCollectionChangedEventHandler CollectionChanged;
+        protected virtual event NotifyCollectionChangedEventHandler? CollectionChanged;
 
         /// <summary>
         /// raise CollectionChanged event to any listeners
@@ -58,7 +58,7 @@ namespace System.Collections.ObjectModel
         /// <summary>
         /// PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
         /// </summary>
-        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
+        event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged
         {
             add => PropertyChanged += value;
             remove => PropertyChanged -= value;
@@ -71,7 +71,7 @@ namespace System.Collections.ObjectModel
         /// see <seealso cref="INotifyPropertyChanged"/>
         /// </remarks>
         [field: NonSerialized]
-        protected virtual event PropertyChangedEventHandler PropertyChanged;
+        protected virtual event PropertyChangedEventHandler? PropertyChanged;
 
         /// <summary>
         /// raise PropertyChanged event to any listeners
@@ -81,12 +81,12 @@ namespace System.Collections.ObjectModel
             PropertyChanged?.Invoke(this, args);
         }
 
-        private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
+        private void HandleCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
         {
             OnCollectionChanged(e);
         }
 
-        private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
+        private void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e)
         {
             OnPropertyChanged(e);
         }
index 0195902..b0b9aa1 100644 (file)
@@ -18,6 +18,6 @@ namespace System.Collections.Specialized
         /// <seealso cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs" />
         /// containing data related to this event.
         /// </remarks>
-        event NotifyCollectionChangedEventHandler CollectionChanged;
+        event NotifyCollectionChangedEventHandler? CollectionChanged;
     }
 }
index e63d80f..82c23b6 100644 (file)
@@ -16,8 +16,8 @@ namespace System.Collections.Specialized
     public class NotifyCollectionChangedEventArgs : EventArgs
     {
         private NotifyCollectionChangedAction _action;
-        private IList _newItems;
-        private IList _oldItems;
+        private IList? _newItems;
+        private IList? _oldItems;
         private int _newStartingIndex = -1;
         private int _oldStartingIndex = -1;
 
@@ -40,7 +40,7 @@ namespace System.Collections.Specialized
         /// </summary>
         /// <param name="action">The action that caused the event; can only be Reset, Add or Remove action.</param>
         /// <param name="changedItem">The item affected by the change.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object changedItem)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object? changedItem)
         {
             if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
                     && (action != NotifyCollectionChangedAction.Reset))
@@ -59,7 +59,7 @@ namespace System.Collections.Specialized
             }
             else
             {
-                InitializeAddOrRemove(action, new object[] { changedItem }, -1);
+                InitializeAddOrRemove(action, new object?[] { changedItem }, -1);
             }
         }
 
@@ -69,7 +69,7 @@ namespace System.Collections.Specialized
         /// <param name="action">The action that caused the event.</param>
         /// <param name="changedItem">The item affected by the change.</param>
         /// <param name="index">The index where the change occurred.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object changedItem, int index)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object? changedItem, int index)
         {
             if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
                     && (action != NotifyCollectionChangedAction.Reset))
@@ -92,7 +92,7 @@ namespace System.Collections.Specialized
             }
             else
             {
-                InitializeAddOrRemove(action, new object[] { changedItem }, index);
+                InitializeAddOrRemove(action, new object?[] { changedItem }, index);
             }
         }
 
@@ -101,7 +101,7 @@ namespace System.Collections.Specialized
         /// </summary>
         /// <param name="action">The action that caused the event.</param>
         /// <param name="changedItems">The items affected by the change.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList changedItems)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList? changedItems)
         {
             if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
                     && (action != NotifyCollectionChangedAction.Reset))
@@ -135,7 +135,7 @@ namespace System.Collections.Specialized
         /// <param name="action">The action that caused the event.</param>
         /// <param name="changedItems">The items affected by the change.</param>
         /// <param name="startingIndex">The index where the change occurred.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList changedItems, int startingIndex)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList? changedItems, int startingIndex)
         {
             if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
                     && (action != NotifyCollectionChangedAction.Reset))
@@ -177,14 +177,14 @@ namespace System.Collections.Specialized
         /// <param name="action">Can only be a Replace action.</param>
         /// <param name="newItem">The new item replacing the original item.</param>
         /// <param name="oldItem">The original item that is replaced.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object newItem, object oldItem)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object? newItem, object? oldItem)
         {
             if (action != NotifyCollectionChangedAction.Replace)
             {
                 throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Replace), nameof(action));
             }
 
-            InitializeMoveOrReplace(action, new object[] { newItem }, new object[] { oldItem }, -1, -1);
+            InitializeMoveOrReplace(action, new object?[] { newItem }, new object?[] { oldItem }, -1, -1);
         }
 
         /// <summary>
@@ -194,14 +194,14 @@ namespace System.Collections.Specialized
         /// <param name="newItem">The new item replacing the original item.</param>
         /// <param name="oldItem">The original item that is replaced.</param>
         /// <param name="index">The index of the item being replaced.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object newItem, object oldItem, int index)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object? newItem, object? oldItem, int index)
         {
             if (action != NotifyCollectionChangedAction.Replace)
             {
                 throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Replace), nameof(action));
             }
 
-            InitializeMoveOrReplace(action, new object[] { newItem }, new object[] { oldItem }, index, index);
+            InitializeMoveOrReplace(action, new object?[] { newItem }, new object?[] { oldItem }, index, index);
         }
 
         /// <summary>
@@ -260,7 +260,7 @@ namespace System.Collections.Specialized
         /// <param name="changedItem">The item affected by the change.</param>
         /// <param name="index">The new index for the changed item.</param>
         /// <param name="oldIndex">The old index for the changed item.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object changedItem, int index, int oldIndex)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object? changedItem, int index, int oldIndex)
         {
             if (action != NotifyCollectionChangedAction.Move)
             {
@@ -271,7 +271,7 @@ namespace System.Collections.Specialized
                 throw new ArgumentException(SR.IndexCannotBeNegative, nameof(index));
             }
 
-            object[] changedItems = new object[] { changedItem };
+            object?[] changedItems = new object?[] { changedItem };
             InitializeMoveOrReplace(action, changedItems, changedItems, index, oldIndex);
         }
 
@@ -282,7 +282,7 @@ namespace System.Collections.Specialized
         /// <param name="changedItems">The items affected by the change.</param>
         /// <param name="index">The new index for the changed items.</param>
         /// <param name="oldIndex">The old index for the changed items.</param>
-        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList changedItems, int index, int oldIndex)
+        public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList? changedItems, int index, int oldIndex)
         {
             if (action != NotifyCollectionChangedAction.Move)
             {
@@ -299,7 +299,7 @@ namespace System.Collections.Specialized
         /// <summary>
         /// Construct a NotifyCollectionChangedEventArgs with given fields (no validation). Used by WinRT marshaling.
         /// </summary>
-        internal NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList newItems, IList oldItems, int newIndex, int oldIndex)
+        internal NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList? newItems, IList? oldItems, int newIndex, int oldIndex)
         {
             _action = action;
             _newItems = (newItems == null) ? null : new ReadOnlyList(newItems);
@@ -308,7 +308,7 @@ namespace System.Collections.Specialized
             _oldStartingIndex = oldIndex;
         }
 
-        private void InitializeAddOrRemove(NotifyCollectionChangedAction action, IList changedItems, int startingIndex)
+        private void InitializeAddOrRemove(NotifyCollectionChangedAction action, IList? changedItems, int startingIndex)
         {
             if (action == NotifyCollectionChangedAction.Add)
             {
@@ -321,21 +321,21 @@ namespace System.Collections.Specialized
             }
         }
 
-        private void InitializeAdd(NotifyCollectionChangedAction action, IList newItems, int newStartingIndex)
+        private void InitializeAdd(NotifyCollectionChangedAction action, IList? newItems, int newStartingIndex)
         {
             _action = action;
             _newItems = (newItems == null) ? null : new ReadOnlyList(newItems);
             _newStartingIndex = newStartingIndex;
         }
 
-        private void InitializeRemove(NotifyCollectionChangedAction action, IList oldItems, int oldStartingIndex)
+        private void InitializeRemove(NotifyCollectionChangedAction action, IList? oldItems, int oldStartingIndex)
         {
             _action = action;
             _oldItems = (oldItems == null) ? null : new ReadOnlyList(oldItems);
             _oldStartingIndex = oldStartingIndex;
         }
 
-        private void InitializeMoveOrReplace(NotifyCollectionChangedAction action, IList newItems, IList oldItems, int startingIndex, int oldStartingIndex)
+        private void InitializeMoveOrReplace(NotifyCollectionChangedAction action, IList? newItems, IList? oldItems, int startingIndex, int oldStartingIndex)
         {
             InitializeAdd(action, newItems, startingIndex);
             InitializeRemove(action, oldItems, oldStartingIndex);
@@ -349,12 +349,12 @@ namespace System.Collections.Specialized
         /// <summary>
         /// The items affected by the change.
         /// </summary>
-        public IList NewItems => _newItems;
+        public IList? NewItems => _newItems;
 
         /// <summary>
         /// The old items affected by the change (for Replace events).
         /// </summary>
-        public IList OldItems => _oldItems;
+        public IList? OldItems => _oldItems;
 
         /// <summary>
         /// The index where the change occurred.
@@ -370,7 +370,7 @@ namespace System.Collections.Specialized
     /// <summary>
     /// The delegate to use for handlers that receive the CollectionChanged event.
     /// </summary>
-    public delegate void NotifyCollectionChangedEventHandler(object sender, NotifyCollectionChangedEventArgs e);
+    public delegate void NotifyCollectionChangedEventHandler(object? sender, NotifyCollectionChangedEventArgs e);
 
     internal sealed class ReadOnlyList : IList
     {
@@ -390,7 +390,7 @@ namespace System.Collections.Specialized
 
         public bool IsSynchronized => _list.IsSynchronized;
 
-        public object this[int index]
+        public object? this[int index]
         {
             get => _list[index];
             set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
@@ -398,7 +398,7 @@ namespace System.Collections.Specialized
 
         public object SyncRoot => _list.SyncRoot;
 
-        public int Add(object value)
+        public int Add(object? value)
         {
             throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
         }
@@ -408,7 +408,7 @@ namespace System.Collections.Specialized
             throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
         }
 
-        public bool Contains(object value) => _list.Contains(value);
+        public bool Contains(object? value) => _list.Contains(value);
 
         public void CopyTo(Array array, int index)
         {
@@ -417,14 +417,14 @@ namespace System.Collections.Specialized
 
         public IEnumerator GetEnumerator() => _list.GetEnumerator();
 
-        public int IndexOf(object value) => _list.IndexOf(value);
+        public int IndexOf(object? value) => _list.IndexOf(value);
 
-        public void Insert(int index, object value)
+        public void Insert(int index, object? value)
         {
             throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
         }
 
-        public void Remove(object value)
+        public void Remove(object? value)
         {
             throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
         }
index 2ff2da8..af22646 100644 (file)
@@ -13,7 +13,7 @@ namespace System.ComponentModel
         /// Initializes a new instance of the <see cref='System.ComponentModel.DataErrorsChangedEventArgs'/>
         /// class.
         /// </summary>
-        public DataErrorsChangedEventArgs(string propertyName)
+        public DataErrorsChangedEventArgs(string? propertyName)
         {
             PropertyName = propertyName;
         }
@@ -21,6 +21,6 @@ namespace System.ComponentModel
         /// <summary>
         /// Indicates the name of the property whose errors changed.
         /// </summary>
-        public virtual string PropertyName { get; }
+        public virtual string? PropertyName { get; }
     }
 }
index fb0d5a4..6ee621e 100644 (file)
@@ -10,8 +10,8 @@ namespace System.ComponentModel
     {
         bool HasErrors { get; }
 
-        IEnumerable GetErrors(string propertyName);
+        IEnumerable GetErrors(string? propertyName);
 
-        event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
+        event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
     }
 }
index 30e9857..d2cf6a9 100644 (file)
@@ -6,6 +6,6 @@ namespace System.ComponentModel
 {
     public interface INotifyPropertyChanged
     {
-        event PropertyChangedEventHandler PropertyChanged;
+        event PropertyChangedEventHandler? PropertyChanged;
     }
 }
index 06b9607..9f79bc6 100644 (file)
@@ -6,6 +6,6 @@ namespace System.ComponentModel
 {
     public interface INotifyPropertyChanging
     {
-        event PropertyChangingEventHandler PropertyChanging;
+        event PropertyChangingEventHandler? PropertyChanging;
     }
 }
index 0aaaa7b..497995c 100644 (file)
@@ -13,7 +13,7 @@ namespace System.ComponentModel
         /// Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangedEventArgs'/>
         /// class.
         /// </summary>
-        public PropertyChangedEventArgs(string propertyName)
+        public PropertyChangedEventArgs(string? propertyName)
         {
             PropertyName = propertyName;
         }
@@ -21,6 +21,6 @@ namespace System.ComponentModel
         /// <summary>
         /// Indicates the name of the property that changed.
         /// </summary>
-        public virtual string PropertyName { get; }
+        public virtual string? PropertyName { get; }
     }
 }
index 950b6cd..e013dc7 100644 (file)
@@ -8,5 +8,5 @@ namespace System.ComponentModel
     /// Represents the method that will handle the <see langword='PropertyChanged'/>
     /// event raised when a property is changed on a component.
     /// </summary>
-    public delegate void PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e);
+    public delegate void PropertyChangedEventHandler(object? sender, PropertyChangedEventArgs e);
 }
index 17a33ca..6f796b2 100644 (file)
@@ -13,7 +13,7 @@ namespace System.ComponentModel
         /// Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangingEventArgs'/>
         /// class.
         /// </summary>
-        public PropertyChangingEventArgs(string propertyName)
+        public PropertyChangingEventArgs(string? propertyName)
         {
             PropertyName = propertyName;
         }
@@ -21,6 +21,6 @@ namespace System.ComponentModel
         /// <summary>
         /// Indicates the name of the property that is changing.
         /// </summary>
-        public virtual string PropertyName { get; }
+        public virtual string? PropertyName { get; }
     }
 }
index 3e97919..0daf9fd 100644 (file)
@@ -8,5 +8,5 @@ namespace System.ComponentModel
     /// Represents the method that will handle the <see langword='PropertyChanging'/>
     /// event raised when a property is changing on a component.
     /// </summary>
-    public delegate void PropertyChangingEventHandler(object sender, PropertyChangingEventArgs e);
+    public delegate void PropertyChangingEventHandler(object? sender, PropertyChangingEventArgs e);
 }
index cc08c4e..c4cc885 100644 (file)
@@ -38,7 +38,7 @@ namespace System.ComponentModel
                 throw new ArgumentNullException(nameof(type));
             }
 
-            ConverterTypeName = type.AssemblyQualifiedName;
+            ConverterTypeName = type.AssemblyQualifiedName!;
         }
 
         /// <summary>
@@ -62,7 +62,7 @@ namespace System.ComponentModel
         /// </summary>
         public string ConverterTypeName { get; }
 
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             return
                 obj is TypeConverterAttribute other &&
index afe42ab..c5c4cbf 100644 (file)
@@ -30,7 +30,7 @@ namespace System.ComponentModel
                 throw new ArgumentNullException(nameof(type));
             }
 
-            TypeName = type.AssemblyQualifiedName;
+            TypeName = type.AssemblyQualifiedName!;
         }
 
         /// <summary>
index b626119..3b4f9fb 100644 (file)
@@ -26,12 +26,12 @@ namespace System.Windows.Input
         /// </summary>
         /// <param name="parameter">A parameter that may be used in executing the command. This parameter may be ignored by some implementations.</param>
         /// <returns>true if the command can be executed with the given parameter and current state. false otherwise.</returns>
-        bool CanExecute(object parameter);
+        bool CanExecute(object? parameter);
 
         /// <summary>
         /// Defines the method that should be executed when the command is executed.
         /// </summary>
         /// <param name="parameter">A parameter that may be used in executing the command. This parameter may be ignored by some implementations.</param>
-        void Execute(object parameter);
+        void Execute(object? parameter);
     }
 }
index 46bca95..687e8e9 100644 (file)
@@ -16,8 +16,8 @@ namespace System.Windows.Markup
     [TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
     public sealed class ValueSerializerAttribute : Attribute
     {
-        private Type _valueSerializerType;
-        private readonly string _valueSerializerTypeName;
+        private Type? _valueSerializerType;
+        private readonly string? _valueSerializerTypeName;
 
         /// <summary>
         /// Constructor for the ValueSerializerAttribute
@@ -49,7 +49,7 @@ namespace System.Windows.Markup
                     _valueSerializerType = Type.GetType(_valueSerializerTypeName);
                 }
 
-                return _valueSerializerType;
+                return _valueSerializerType!;
             }
         }
 
@@ -62,11 +62,11 @@ namespace System.Windows.Markup
             {
                 if (_valueSerializerType != null)
                 {
-                    return _valueSerializerType.AssemblyQualifiedName;
+                    return _valueSerializerType.AssemblyQualifiedName!;
                 }
                 else
                 {
-                    return _valueSerializerTypeName;
+                    return _valueSerializerTypeName!;
                 }
             }
         }