From e083b2a4ab3045450005645dab8c009574a75d58 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 12 Jun 2019 15:09:49 -0400 Subject: [PATCH] Replace 'where T : object` with `where T : notnull` --- .../Collections/ObjectModel/ReadOnlyDictionary.cs | 2 +- .../Runtime/InteropServices/Marshal.CoreCLR.cs | 2 +- .../WindowsRuntime/ConstantSplittableMap.cs | 2 +- .../WindowsRuntime/DictionaryKeyCollection.cs | 4 ++-- .../WindowsRuntime/DictionaryToMapAdapter.cs | 14 +++++++------- .../WindowsRuntime/DictionaryValueCollection.cs | 4 ++-- .../Runtime/InteropServices/WindowsRuntime/IMap.cs | 2 +- .../IMapViewToIReadOnlyDictionaryAdapter.cs | 16 ++++++++-------- .../IReadOnlyDictionaryToIMapViewAdapter.cs | 8 ++++---- .../WindowsRuntime/MapToCollectionAdapter.cs | 14 +++++++------- .../WindowsRuntime/MapToDictionaryAdapter.cs | 20 ++++++++++---------- 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index 2a455a4..c1de2ae 100644 --- a/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -20,7 +20,7 @@ namespace System.Collections.ObjectModel { [DebuggerTypeProxy(typeof(IDictionaryDebugView<,>))] [DebuggerDisplay("Count = {Count}")] - internal class ReadOnlyDictionary : IDictionary, IDictionary, IReadOnlyDictionary where TKey : object + internal class ReadOnlyDictionary : IDictionary, IDictionary, IReadOnlyDictionary where TKey : notnull { private readonly IDictionary m_dictionary; private object? m_syncRoot; diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs index 6df19ae..a57d287 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs @@ -388,7 +388,7 @@ namespace System.Runtime.InteropServices [MethodImpl(MethodImplOptions.InternalCall)] public static extern IntPtr CreateAggregatedObject(IntPtr pOuter, object o); - public static IntPtr CreateAggregatedObject(IntPtr pOuter, T o) where T : object + public static IntPtr CreateAggregatedObject(IntPtr pOuter, T o) where T : notnull { return CreateAggregatedObject(pOuter, (object)o); } diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs index 9f5f99b..3d228ab 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs @@ -19,7 +19,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime /// Type of objects that act as keys. /// Type of objects that act as entries / values. [DebuggerDisplay("Count = {Count}")] - internal sealed class ConstantSplittableMap : IMapView where TKey : object + internal sealed class ConstantSplittableMap : IMapView where TKey : notnull { private class KeyValuePairComparator : IComparer> { diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs index 11f3ab2..f78bf0d 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs @@ -9,7 +9,7 @@ using System.Diagnostics; namespace System.Runtime.InteropServices.WindowsRuntime { [DebuggerDisplay("Count = {Count}")] - internal sealed class DictionaryKeyCollection : ICollection where TKey : object + internal sealed class DictionaryKeyCollection : ICollection where TKey : notnull { private readonly IDictionary dictionary; @@ -81,7 +81,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // public class DictionaryKeyCollection - internal sealed class DictionaryKeyEnumerator : IEnumerator where TKey : object + internal sealed class DictionaryKeyEnumerator : IEnumerator where TKey : notnull { private readonly IDictionary dictionary; private IEnumerator> enumeration; diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs index 57482f9..0feb7a1 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs @@ -25,7 +25,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // V Lookup(K key) - internal V Lookup(K key) where K : object + internal V Lookup(K key) where K : notnull { IDictionary _this = Unsafe.As>(this); V value; @@ -43,21 +43,21 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint Size { get } - internal uint Size() where K : object + internal uint Size() where K : notnull { IDictionary _this = Unsafe.As>(this); return (uint)_this.Count; } // bool HasKey(K key) - internal bool HasKey(K key) where K : object + internal bool HasKey(K key) where K : notnull { IDictionary _this = Unsafe.As>(this); return _this.ContainsKey(key); } // IMapView GetView() - internal IReadOnlyDictionary GetView() where K : object + internal IReadOnlyDictionary GetView() where K : notnull { IDictionary _this = Unsafe.As>(this); Debug.Assert(_this != null); @@ -72,7 +72,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Insert(K key, V value) - internal bool Insert(K key, V value) where K : object + internal bool Insert(K key, V value) where K : notnull { IDictionary _this = Unsafe.As>(this); bool replacing = _this.ContainsKey(key); @@ -81,7 +81,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Remove(K key) - internal void Remove(K key) where K : object + internal void Remove(K key) where K : notnull { IDictionary _this = Unsafe.As>(this); bool removed = _this.Remove(key); @@ -96,7 +96,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - internal void Clear() where K : object + internal void Clear() where K : notnull { IDictionary _this = Unsafe.As>(this); _this.Clear(); diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs index 9860efc..dd111ff 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs @@ -9,7 +9,7 @@ using System.Diagnostics; namespace System.Runtime.InteropServices.WindowsRuntime { [DebuggerDisplay("Count = {Count}")] - internal sealed class DictionaryValueCollection : ICollection where TKey : object + internal sealed class DictionaryValueCollection : ICollection where TKey : notnull { private readonly IDictionary dictionary; @@ -85,7 +85,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // public class DictionaryValueCollection - internal sealed class DictionaryValueEnumerator : IEnumerator where TKey : object + internal sealed class DictionaryValueEnumerator : IEnumerator where TKey : notnull { private readonly IDictionary dictionary; private IEnumerator> enumeration; diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs index 4dfdbbb..164350a 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs @@ -13,7 +13,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime [ComImport] [Guid("3c2925fe-8519-45c1-aa79-197b6718c1c1")] [WindowsRuntimeImport] - internal interface IMap : IIterable> where K : object + internal interface IMap : IIterable> where K : notnull { V Lookup(K key); uint Size { get; } diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs index 7a8b11b..d0b9aa4 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs @@ -37,7 +37,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // IEnumerable Keys { get } - internal IEnumerable Keys() where K : object + internal IEnumerable Keys() where K : notnull { IMapView _this = Unsafe.As>(this); IReadOnlyDictionary roDictionary = (IReadOnlyDictionary)_this; @@ -45,7 +45,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // IEnumerable Values { get } - internal IEnumerable Values() where K : object + internal IEnumerable Values() where K : notnull { IMapView _this = Unsafe.As>(this); IReadOnlyDictionary roDictionary = (IReadOnlyDictionary)_this; @@ -53,7 +53,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool ContainsKey(K key) - internal bool ContainsKey(K key) where K : object + internal bool ContainsKey(K key) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -63,7 +63,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool TryGetValue(TKey key, out TValue value) - internal bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) where K : object + internal bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -117,7 +117,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Note: One day we may make these return IReadOnlyCollection [DebuggerDisplay("Count = {Count}")] - internal sealed class ReadOnlyDictionaryKeyCollection : IEnumerable where TKey : object + internal sealed class ReadOnlyDictionaryKeyCollection : IEnumerable where TKey : notnull { private readonly IReadOnlyDictionary dictionary; @@ -170,7 +170,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // public class ReadOnlyDictionaryKeyCollection - internal sealed class ReadOnlyDictionaryKeyEnumerator : IEnumerator where TKey : object + internal sealed class ReadOnlyDictionaryKeyEnumerator : IEnumerator where TKey : notnull { private readonly IReadOnlyDictionary dictionary; private IEnumerator> enumeration; @@ -212,7 +212,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime [DebuggerDisplay("Count = {Count}")] - internal sealed class ReadOnlyDictionaryValueCollection : IEnumerable where TKey : object + internal sealed class ReadOnlyDictionaryValueCollection : IEnumerable where TKey : notnull { private readonly IReadOnlyDictionary dictionary; @@ -269,7 +269,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // public class ReadOnlyDictionaryValueCollection - internal sealed class ReadOnlyDictionaryValueEnumerator : IEnumerator where TKey : object + internal sealed class ReadOnlyDictionaryValueEnumerator : IEnumerator where TKey : notnull { private readonly IReadOnlyDictionary dictionary; private IEnumerator> enumeration; diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs index 2327e7c..ae4c80f 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs @@ -25,7 +25,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // V Lookup(K key) - internal V Lookup(K key) where K : object + internal V Lookup(K key) where K : notnull { IReadOnlyDictionary _this = Unsafe.As>(this); V value; @@ -43,21 +43,21 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint Size { get } - internal uint Size() where K : object + internal uint Size() where K : notnull { IReadOnlyDictionary _this = Unsafe.As>(this); return (uint)_this.Count; } // bool HasKey(K key) - internal bool HasKey(K key) where K : object + internal bool HasKey(K key) where K : notnull { IReadOnlyDictionary _this = Unsafe.As>(this); return _this.ContainsKey(key); } // void Split(out IMapView first, out IMapView second) - internal void Split(out IMapView? first, out IMapView? second) where K : object + internal void Split(out IMapView? first, out IMapView? second) where K : notnull { IReadOnlyDictionary _this = Unsafe.As>(this); diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs index 9dd1abe..7183c46 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs @@ -27,7 +27,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // int Count { get } - internal int Count() where K : object + internal int Count() where K : notnull { object _this = Unsafe.As(this); @@ -57,13 +57,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool IsReadOnly { get } - internal bool IsReadOnly() where K : object + internal bool IsReadOnly() where K : notnull { return false; } // void Add(T item) - internal void Add(KeyValuePair item) where K : object + internal void Add(KeyValuePair item) where K : notnull { object _this = Unsafe.As(this); @@ -79,7 +79,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - internal void Clear() where K : object + internal void Clear() where K : notnull { object _this = Unsafe.As(this); @@ -95,7 +95,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Contains(T item) - internal bool Contains(KeyValuePair item) where K : object + internal bool Contains(KeyValuePair item) where K : notnull { object _this = Unsafe.As(this); @@ -119,7 +119,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void CopyTo(T[] array, int arrayIndex) - internal void CopyTo(KeyValuePair[] array, int arrayIndex) where K : object + internal void CopyTo(KeyValuePair[] array, int arrayIndex) where K : notnull { if (array == null) throw new ArgumentNullException(nameof(array)); @@ -142,7 +142,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Remove(T item) - internal bool Remove(KeyValuePair item) where K : object + internal bool Remove(KeyValuePair item) where K : notnull { object _this = Unsafe.As(this); diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs index e0ad2d7..7ab9288 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs @@ -25,7 +25,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // V this[K key] { get } - internal V Indexer_Get(K key) where K : object + internal V Indexer_Get(K key) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -36,7 +36,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // V this[K key] { set } - internal void Indexer_Set(K key, V value) where K : object + internal void Indexer_Set(K key, V value) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -47,7 +47,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // ICollection Keys { get } - internal ICollection Keys() where K : object + internal ICollection Keys() where K : notnull { IMap _this = Unsafe.As>(this); IDictionary dictionary = (IDictionary)_this; @@ -55,7 +55,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // ICollection Values { get } - internal ICollection Values() where K : object + internal ICollection Values() where K : notnull { IMap _this = Unsafe.As>(this); IDictionary dictionary = (IDictionary)_this; @@ -63,7 +63,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool ContainsKey(K key) - internal bool ContainsKey(K key) where K : object + internal bool ContainsKey(K key) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -73,7 +73,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Add(K key, V value) - internal void Add(K key, V value) where K : object + internal void Add(K key, V value) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -87,7 +87,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Remove(TKey key) - internal bool Remove(K key) where K : object + internal bool Remove(K key) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -111,7 +111,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool TryGetValue(TKey key, out TValue value) - internal bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) where K : object + internal bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) where K : notnull { if (key == null) throw new ArgumentNullException(nameof(key)); @@ -137,7 +137,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Helpers: - private static V Lookup(IMap _this, K key) where K : object + private static V Lookup(IMap _this, K key) where K : notnull { Debug.Assert(null != key); @@ -153,7 +153,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - private static bool Insert(IMap _this, K key, V value) where K : object + private static bool Insert(IMap _this, K key, V value) where K : notnull { Debug.Assert(null != key); -- 2.7.4