Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Annotate System.Collections.NonGeneric for nullable (#41036)
Browse files Browse the repository at this point in the history
* Annotate System.Collections.NonGeneric for nullable

* Removing unnessecarry constant

* Marked CaseInsensitiveHashCodeProvider as Obsolete

* Removing NullableAttributes defintion as it was already added

* Applying feedback

* Revert "Applying feedback"

* Applying feedback
  • Loading branch information
buyaa-n authored and stephentoub committed Sep 13, 2019
1 parent 2602450 commit 001420e
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public CaseInsensitiveComparer() { }
public CaseInsensitiveComparer(System.Globalization.CultureInfo culture) { }
public static System.Collections.CaseInsensitiveComparer Default { get { throw null; } }
public static System.Collections.CaseInsensitiveComparer DefaultInvariant { get { throw null; } }
public int Compare(object a, object b) { throw null; }
public int Compare(object? a, object? b) { throw null; }
}
[System.ObsoleteAttribute("Please use StringComparer instead.")]
public partial class CaseInsensitiveHashCodeProvider : System.Collections.IHashCodeProvider
Expand All @@ -36,25 +36,25 @@ protected CollectionBase(int capacity) { }
object System.Collections.ICollection.SyncRoot { get { throw null; } }
bool System.Collections.IList.IsFixedSize { get { throw null; } }
bool System.Collections.IList.IsReadOnly { get { throw null; } }
object System.Collections.IList.this[int index] { get { throw null; } set { } }
object? System.Collections.IList.this[int index] { get { throw null; } set { } }
public void Clear() { }
public System.Collections.IEnumerator GetEnumerator() { throw null; }
protected virtual void OnClear() { }
protected virtual void OnClearComplete() { }
protected virtual void OnInsert(int index, object value) { }
protected virtual void OnInsertComplete(int index, object value) { }
protected virtual void OnRemove(int index, object value) { }
protected virtual void OnRemoveComplete(int index, object value) { }
protected virtual void OnSet(int index, object oldValue, object newValue) { }
protected virtual void OnSetComplete(int index, object oldValue, object newValue) { }
protected virtual void OnInsert(int index, object? value) { }
protected virtual void OnInsertComplete(int index, object? value) { }
protected virtual void OnRemove(int index, object? value) { }
protected virtual void OnRemoveComplete(int index, object? value) { }
protected virtual void OnSet(int index, object? oldValue, object? newValue) { }
protected virtual void OnSetComplete(int index, object? oldValue, object? newValue) { }
protected virtual void OnValidate(object value) { }
public void RemoveAt(int index) { }
void System.Collections.ICollection.CopyTo(System.Array array, int index) { }
int System.Collections.IList.Add(object value) { throw null; }
bool System.Collections.IList.Contains(object value) { throw null; }
int System.Collections.IList.IndexOf(object value) { throw null; }
void System.Collections.IList.Insert(int index, object value) { }
void System.Collections.IList.Remove(object value) { }
int System.Collections.IList.Add(object? value) { throw null; }
bool System.Collections.IList.Contains(object? value) { throw null; }
int System.Collections.IList.IndexOf(object? value) { throw null; }
void System.Collections.IList.Insert(int index, object? value) { }
void System.Collections.IList.Remove(object? value) { }
}
public abstract partial class DictionaryBase : System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable
{
Expand All @@ -66,23 +66,23 @@ protected DictionaryBase() { }
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 void Clear() { }
public void CopyTo(System.Array array, int index) { }
public System.Collections.IDictionaryEnumerator GetEnumerator() { throw null; }
protected virtual void OnClear() { }
protected virtual void OnClearComplete() { }
protected virtual object OnGet(object key, object currentValue) { throw null; }
protected virtual void OnInsert(object key, object value) { }
protected virtual void OnInsertComplete(object key, object value) { }
protected virtual void OnRemove(object key, object value) { }
protected virtual void OnRemoveComplete(object key, object value) { }
protected virtual void OnSet(object key, object oldValue, object newValue) { }
protected virtual void OnSetComplete(object key, object oldValue, object newValue) { }
protected virtual void OnValidate(object key, object value) { }
void System.Collections.IDictionary.Add(object key, object value) { }
protected virtual object? OnGet(object key, object? currentValue) { throw null; }
protected virtual void OnInsert(object key, object? value) { }
protected virtual void OnInsertComplete(object key, object? value) { }
protected virtual void OnRemove(object key, object? value) { }
protected virtual void OnRemoveComplete(object key, object? value) { }
protected virtual void OnSet(object key, object? oldValue, object? newValue) { }
protected virtual void OnSetComplete(object key, object? oldValue, object? newValue) { }
protected virtual void OnValidate(object key, object? value) { }
void System.Collections.IDictionary.Add(object key, object? value) { }
bool System.Collections.IDictionary.Contains(object key) { throw null; }
void System.Collections.IDictionary.Remove(object key) { }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
Expand All @@ -98,14 +98,14 @@ public Queue(int capacity, float growFactor) { }
public virtual object SyncRoot { get { throw null; } }
public virtual void Clear() { }
public virtual object Clone() { throw null; }
public virtual bool Contains(object obj) { throw null; }
public virtual bool Contains(object? obj) { throw null; }
public virtual void CopyTo(System.Array array, int index) { }
public virtual object Dequeue() { throw null; }
public virtual void Enqueue(object obj) { }
public virtual object? Dequeue() { throw null; }
public virtual void Enqueue(object? obj) { }
public virtual System.Collections.IEnumerator GetEnumerator() { throw null; }
public virtual object Peek() { throw null; }
public virtual object? Peek() { throw null; }
public static System.Collections.Queue Synchronized(System.Collections.Queue queue) { throw null; }
public virtual object[] ToArray() { throw null; }
public virtual object?[] ToArray() { throw null; }
public virtual void TrimToSize() { }
}
public abstract partial class ReadOnlyCollectionBase : System.Collections.ICollection, System.Collections.IEnumerable
Expand All @@ -121,37 +121,37 @@ void System.Collections.ICollection.CopyTo(System.Array array, int index) { }
public partial class SortedList : System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable, System.ICloneable
{
public SortedList() { }
public SortedList(System.Collections.IComparer comparer) { }
public SortedList(System.Collections.IComparer comparer, int capacity) { }
public SortedList(System.Collections.IComparer? comparer) { }
public SortedList(System.Collections.IComparer? comparer, int capacity) { }
public SortedList(System.Collections.IDictionary d) { }
public SortedList(System.Collections.IDictionary d, System.Collections.IComparer comparer) { }
public SortedList(System.Collections.IDictionary d, System.Collections.IComparer? comparer) { }
public SortedList(int initialCapacity) { }
public virtual int Capacity { get { throw null; } set { } }
public virtual int Count { get { throw null; } }
public virtual bool IsFixedSize { get { throw null; } }
public virtual bool IsReadOnly { get { throw null; } }
public virtual bool IsSynchronized { get { throw null; } }
public virtual object this[object key] { get { throw null; } set { } }
public virtual object? this[object key] { get { throw null; } set { } }
public virtual System.Collections.ICollection Keys { get { throw null; } }
public virtual object SyncRoot { get { throw null; } }
public virtual System.Collections.ICollection Values { get { throw null; } }
public virtual void Add(object key, object value) { }
public virtual void Add(object key, object? value) { }
public virtual void Clear() { }
public virtual object Clone() { throw null; }
public virtual bool Contains(object key) { throw null; }
public virtual bool ContainsKey(object key) { throw null; }
public virtual bool ContainsValue(object value) { throw null; }
public virtual bool ContainsValue(object? value) { throw null; }
public virtual void CopyTo(System.Array array, int arrayIndex) { }
public virtual object GetByIndex(int index) { throw null; }
public virtual object? GetByIndex(int index) { throw null; }
public virtual System.Collections.IDictionaryEnumerator GetEnumerator() { throw null; }
public virtual object GetKey(int index) { throw null; }
public virtual System.Collections.IList GetKeyList() { throw null; }
public virtual System.Collections.IList GetValueList() { throw null; }
public virtual int IndexOfKey(object key) { throw null; }
public virtual int IndexOfValue(object value) { throw null; }
public virtual int IndexOfValue(object? value) { throw null; }
public virtual void Remove(object key) { }
public virtual void RemoveAt(int index) { }
public virtual void SetByIndex(int index, object value) { }
public virtual void SetByIndex(int index, object? value) { }
public static System.Collections.SortedList Synchronized(System.Collections.SortedList list) { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
public virtual void TrimToSize() { }
Expand All @@ -166,14 +166,14 @@ public Stack(int initialCapacity) { }
public virtual object SyncRoot { get { throw null; } }
public virtual void Clear() { }
public virtual object Clone() { throw null; }
public virtual bool Contains(object obj) { throw null; }
public virtual bool Contains(object? obj) { throw null; }
public virtual void CopyTo(System.Array array, int index) { }
public virtual System.Collections.IEnumerator GetEnumerator() { throw null; }
public virtual object Peek() { throw null; }
public virtual object Pop() { throw null; }
public virtual void Push(object obj) { }
public virtual object? Peek() { throw null; }
public virtual object? Pop() { throw null; }
public virtual void Push(object? obj) { }
public static System.Collections.Stack Synchronized(System.Collections.Stack stack) { throw null; }
public virtual object[] ToArray() { throw null; }
public virtual object?[] ToArray() { throw null; }
}
}
namespace System.Collections.Specialized
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Debug;uap-Release</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Collections.NonGeneric.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>System.Collections.NonGeneric</RootNamespace>
<AssemblyName>System.Collections.NonGeneric</AssemblyName>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Collections\CaseInsensitiveComparer.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace System.Collections
public class CaseInsensitiveComparer : IComparer
{
private readonly CompareInfo _compareInfo;
private static volatile CaseInsensitiveComparer s_InvariantCaseInsensitiveComparer;
private static volatile CaseInsensitiveComparer? s_InvariantCaseInsensitiveComparer;

public CaseInsensitiveComparer()
{
Expand Down Expand Up @@ -61,10 +61,10 @@ public static CaseInsensitiveComparer DefaultInvariant
// If a doesn't implement IComparable and b does, -(b.CompareTo(a)) is returned.
// Otherwise an exception is thrown.
//
public int Compare(object a, object b)
public int Compare(object? a, object? b)
{
string sa = a as string;
string sb = b as string;
string? sa = a as string;
string? sb = b as string;
if (sa != null && sb != null)
return _compareInfo.Compare(sa, sb, CompareOptions.IgnoreCase);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace System.Collections
[Obsolete("Please use StringComparer instead.")]
public class CaseInsensitiveHashCodeProvider : IHashCodeProvider
{
private static volatile CaseInsensitiveHashCodeProvider s_invariantCaseInsensitiveHashCodeProvider = null;
private static volatile CaseInsensitiveHashCodeProvider? s_invariantCaseInsensitiveHashCodeProvider = null;
private readonly CompareInfo _compareInfo;

public CaseInsensitiveHashCodeProvider()
Expand Down Expand Up @@ -42,7 +42,7 @@ public int GetHashCode(object obj)
throw new ArgumentNullException(nameof(obj));
}

string s = obj as string;
string? s = obj as string;
return s != null ?
_compareInfo.GetHashCode(s, CompareOptions.IgnoreCase) :
obj.GetHashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void RemoveAt(int index)
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
object temp = InnerList[index];
OnValidate(temp);
object? temp = InnerList[index];
OnValidate(temp!);
OnRemove(index, temp);
InnerList.RemoveAt(index);
try
Expand Down Expand Up @@ -113,7 +113,7 @@ void ICollection.CopyTo(Array array, int index)
InnerList.CopyTo(array, index);
}

object IList.this[int index]
object? IList.this[int index]
{
get
{
Expand All @@ -125,8 +125,8 @@ object IList.this[int index]
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
OnValidate(value);
object temp = InnerList[index];
OnValidate(value!);
object? temp = InnerList[index];
OnSet(index, temp, value);
InnerList[index] = value;
try
Expand All @@ -141,14 +141,14 @@ object IList.this[int index]
}
}

bool IList.Contains(object value)
bool IList.Contains(object? value)
{
return InnerList.Contains(value);
}

int IList.Add(object value)
int IList.Add(object? value)
{
OnValidate(value);
OnValidate(value!);
OnInsert(InnerList.Count, value);
int index = InnerList.Add(value);
try
Expand All @@ -164,9 +164,9 @@ int IList.Add(object value)
}


void IList.Remove(object value)
void IList.Remove(object? value)
{
OnValidate(value);
OnValidate(value!);
int index = InnerList.IndexOf(value);
if (index < 0) throw new ArgumentException(SR.Arg_RemoveArgNotFound);
OnRemove(index, value);
Expand All @@ -182,16 +182,16 @@ void IList.Remove(object value)
}
}

int IList.IndexOf(object value)
int IList.IndexOf(object? value)
{
return InnerList.IndexOf(value);
}

void IList.Insert(int index, object value)
void IList.Insert(int index, object? value)
{
if (index < 0 || index > Count)
throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
OnValidate(value);
OnValidate(value!);
OnInsert(index, value);
InnerList.Insert(index, value);
try
Expand All @@ -210,19 +210,19 @@ public IEnumerator GetEnumerator()
return InnerList.GetEnumerator();
}

protected virtual void OnSet(int index, object oldValue, object newValue)
protected virtual void OnSet(int index, object? oldValue, object? newValue)
{
}

protected virtual void OnInsert(int index, object value)
protected virtual void OnInsert(int index, object? value)
{
}

protected virtual void OnClear()
{
}

protected virtual void OnRemove(int index, object value)
protected virtual void OnRemove(int index, object? value)
{
}

Expand All @@ -231,19 +231,19 @@ protected virtual void OnValidate(object value)
if (value == null) throw new ArgumentNullException(nameof(value));
}

protected virtual void OnSetComplete(int index, object oldValue, object newValue)
protected virtual void OnSetComplete(int index, object? oldValue, object? newValue)
{
}

protected virtual void OnInsertComplete(int index, object value)
protected virtual void OnInsertComplete(int index, object? value)
{
}

protected virtual void OnClearComplete()
{
}

protected virtual void OnRemoveComplete(int index, object value)
protected virtual void OnRemoveComplete(int index, object? value)
{
}
}
Expand Down
Loading

0 comments on commit 001420e

Please sign in to comment.