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() { }
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() { }
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; } }
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; } }
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() { }
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) { }
}
{
public partial interface INotifyCollectionChanged
{
- event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChanged;
+ event System.Collections.Specialized.NotifyCollectionChangedEventHandler? CollectionChanged;
}
public enum NotifyCollectionChangedAction
{
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
{
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)]
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
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
+ <Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.ObjectModel.cs" />
<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" />
}
}
- internal sealed class DictionaryDebugView<K, V>
+ internal sealed class DictionaryDebugView<K, V> where K: notnull
{
private readonly IDictionary<K, V> _dict;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
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)
{
}
- 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.
{
get
{
TItem item;
- if (TryGetValue(key, out item))
+ if (TryGetValue(key, out item!))
{
return item;
}
return false;
}
- public bool TryGetValue(TKey key, out TItem item)
+ public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TItem item)
{
if (key == null)
{
if (dict != null)
{
- return dict.TryGetValue(key, out item);
+ return dict.TryGetValue(key, out item!);
}
foreach (TItem itemInItems in Items)
}
}
- item = default(TItem);
+ item = default(TItem)!;
return false;
}
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);
}
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++)
return false;
}
- protected IDictionary<TKey, TItem> Dictionary => dict;
+ protected IDictionary<TKey, TItem>? Dictionary => dict;
protected void ChangeItemKey(TItem item, TKey newKey)
{
else if (keyCount == threshold)
{
CreateDictionary();
- dict.Add(key, item);
+ dict!.Add(key, item);
}
else
{
[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;
/// <summary>
/// PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
/// </summary>
- event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
+ event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged
{
add => PropertyChanged += value;
remove => PropertyChanged -= value;
/// see <seealso cref="INotifyCollectionChanged"/>
/// </remarks>
[field: NonSerialized]
- public virtual event NotifyCollectionChangedEventHandler CollectionChanged;
+ public virtual event NotifyCollectionChangedEventHandler? CollectionChanged;
/// <summary>
/// Called by base class Collection<T> when the list is being cleared;
/// 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.
/// </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.
/// <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));
}
/// <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));
}
/// <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));
}
/// </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]
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
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)
{
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;
return key is TKey;
}
- void IDictionary.Add(object key, object value)
+ void IDictionary.Add(object key, object? value)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
IDictionaryEnumerator IDictionary.GetEnumerator()
{
- IDictionary d = m_dictionary as IDictionary;
- if (d != null)
+ if (m_dictionary is IDictionary d)
{
return d.GetEnumerator();
}
ICollection IDictionary.Values => Values;
- object IDictionary.this[object key]
+ object? IDictionary.this[object key]
{
get
{
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)
{
}
else
{
- object[] objects = array as object[];
+ object[]? objects = array as object[];
if (objects == null)
{
throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array));
public object Key => _enumerator.Current.Key;
- public object Value => _enumerator.Current.Value;
+ public object? Value => _enumerator.Current.Value;
public object Current => Entry;
}
// 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);
}
{
// 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));
/// <summary>
/// CollectionChanged event (per <see cref="INotifyCollectionChanged" />).
/// </summary>
- event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
+ event NotifyCollectionChangedEventHandler? INotifyCollectionChanged.CollectionChanged
{
add => CollectionChanged += value;
remove => CollectionChanged -= value;
/// see <seealso cref="INotifyCollectionChanged"/>
/// </remarks>
[field: NonSerialized]
- protected virtual event NotifyCollectionChangedEventHandler CollectionChanged;
+ protected virtual event NotifyCollectionChangedEventHandler? CollectionChanged;
/// <summary>
/// raise CollectionChanged event to any listeners
/// <summary>
/// PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
/// </summary>
- event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
+ event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged
{
add => PropertyChanged += value;
remove => PropertyChanged -= value;
/// see <seealso cref="INotifyPropertyChanged"/>
/// </remarks>
[field: NonSerialized]
- protected virtual event PropertyChangedEventHandler PropertyChanged;
+ protected virtual event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// raise PropertyChanged event to any listeners
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);
}
/// <seealso cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs" />
/// containing data related to this event.
/// </remarks>
- event NotifyCollectionChangedEventHandler CollectionChanged;
+ event NotifyCollectionChangedEventHandler? CollectionChanged;
}
}
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;
/// </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))
}
else
{
- InitializeAddOrRemove(action, new object[] { changedItem }, -1);
+ InitializeAddOrRemove(action, new object?[] { changedItem }, -1);
}
}
/// <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))
}
else
{
- InitializeAddOrRemove(action, new object[] { changedItem }, index);
+ InitializeAddOrRemove(action, new object?[] { changedItem }, index);
}
}
/// </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))
/// <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))
/// <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>
/// <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>
/// <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)
{
throw new ArgumentException(SR.IndexCannotBeNegative, nameof(index));
}
- object[] changedItems = new object[] { changedItem };
+ object?[] changedItems = new object?[] { changedItem };
InitializeMoveOrReplace(action, changedItems, changedItems, index, oldIndex);
}
/// <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)
{
/// <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);
_oldStartingIndex = oldIndex;
}
- private void InitializeAddOrRemove(NotifyCollectionChangedAction action, IList changedItems, int startingIndex)
+ private void InitializeAddOrRemove(NotifyCollectionChangedAction action, IList? changedItems, int startingIndex)
{
if (action == NotifyCollectionChangedAction.Add)
{
}
}
- 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);
/// <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.
/// <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
{
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);
public object SyncRoot => _list.SyncRoot;
- public int Add(object value)
+ public int Add(object? value)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
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)
{
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);
}
/// Initializes a new instance of the <see cref='System.ComponentModel.DataErrorsChangedEventArgs'/>
/// class.
/// </summary>
- public DataErrorsChangedEventArgs(string propertyName)
+ public DataErrorsChangedEventArgs(string? propertyName)
{
PropertyName = propertyName;
}
/// <summary>
/// Indicates the name of the property whose errors changed.
/// </summary>
- public virtual string PropertyName { get; }
+ public virtual string? PropertyName { get; }
}
}
{
bool HasErrors { get; }
- IEnumerable GetErrors(string propertyName);
+ IEnumerable GetErrors(string? propertyName);
- event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
+ event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
}
}
{
public interface INotifyPropertyChanged
{
- event PropertyChangedEventHandler PropertyChanged;
+ event PropertyChangedEventHandler? PropertyChanged;
}
}
{
public interface INotifyPropertyChanging
{
- event PropertyChangingEventHandler PropertyChanging;
+ event PropertyChangingEventHandler? PropertyChanging;
}
}
/// Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangedEventArgs'/>
/// class.
/// </summary>
- public PropertyChangedEventArgs(string propertyName)
+ public PropertyChangedEventArgs(string? propertyName)
{
PropertyName = propertyName;
}
/// <summary>
/// Indicates the name of the property that changed.
/// </summary>
- public virtual string PropertyName { get; }
+ public virtual string? PropertyName { get; }
}
}
/// 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);
}
/// Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangingEventArgs'/>
/// class.
/// </summary>
- public PropertyChangingEventArgs(string propertyName)
+ public PropertyChangingEventArgs(string? propertyName)
{
PropertyName = propertyName;
}
/// <summary>
/// Indicates the name of the property that is changing.
/// </summary>
- public virtual string PropertyName { get; }
+ public virtual string? PropertyName { get; }
}
}
/// 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);
}
throw new ArgumentNullException(nameof(type));
}
- ConverterTypeName = type.AssemblyQualifiedName;
+ ConverterTypeName = type.AssemblyQualifiedName!;
}
/// <summary>
/// </summary>
public string ConverterTypeName { get; }
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return
obj is TypeConverterAttribute other &&
throw new ArgumentNullException(nameof(type));
}
- TypeName = type.AssemblyQualifiedName;
+ TypeName = type.AssemblyQualifiedName!;
}
/// <summary>
/// </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);
}
}
[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
_valueSerializerType = Type.GetType(_valueSerializerTypeName);
}
- return _valueSerializerType;
+ return _valueSerializerType!;
}
}
{
if (_valueSerializerType != null)
{
- return _valueSerializerType.AssemblyQualifiedName;
+ return _valueSerializerType.AssemblyQualifiedName!;
}
else
{
- return _valueSerializerTypeName;
+ return _valueSerializerTypeName!;
}
}
}