* Start working on nullable checks

help me

* Update GlobalConfig.cs

* Finish initial fixup round

* nullability code review
This commit is contained in:
Łukasz Domeradzki
2020-08-22 21:41:01 +02:00
committed by GitHub
parent e5f64ec9dd
commit 9fc1ea65a5
91 changed files with 1996 additions and 2808 deletions

View File

@@ -23,12 +23,11 @@ using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Collections {
public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ISet<T> {
public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ISet<T> where T : notnull {
public int Count => BackingCollection.Count;
public bool IsReadOnly => false;
@@ -36,7 +35,7 @@ namespace ArchiSteamFarm.Collections {
public ConcurrentHashSet() => BackingCollection = new ConcurrentDictionary<T, bool>();
public ConcurrentHashSet([JetBrains.Annotations.NotNull] IEqualityComparer<T> comparer) {
public ConcurrentHashSet(IEqualityComparer<T> comparer) {
if (comparer == null) {
throw new ArgumentNullException(nameof(comparer));
}
@@ -47,7 +46,6 @@ namespace ArchiSteamFarm.Collections {
public bool Add(T item) => BackingCollection.TryAdd(item, true);
public void Clear() => BackingCollection.Clear();
[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
public bool Contains(T item) => BackingCollection.ContainsKey(item);
public void CopyTo(T[] array, int arrayIndex) => BackingCollection.Keys.CopyTo(array, arrayIndex);
@@ -98,7 +96,6 @@ namespace ArchiSteamFarm.Collections {
return otherSet.Any(Contains);
}
[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
public bool Remove(T item) => BackingCollection.TryRemove(item, out _);
public bool SetEquals(IEnumerable<T> other) {
@@ -127,22 +124,20 @@ namespace ArchiSteamFarm.Collections {
}
}
[SuppressMessage("ReSharper", "AnnotationConflictInHierarchy")]
[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
void ICollection<T>.Add([JetBrains.Annotations.NotNull] T item) => Add(item);
void ICollection<T>.Add(T item) => Add(item);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
// We use Count() and not Any() because we must ensure full loop pass
[PublicAPI]
public bool AddRange([JetBrains.Annotations.NotNull] IEnumerable<T> items) => items.Count(Add) > 0;
public bool AddRange(IEnumerable<T> items) => items.Count(Add) > 0;
// We use Count() and not Any() because we must ensure full loop pass
[PublicAPI]
public bool RemoveRange([JetBrains.Annotations.NotNull] IEnumerable<T> items) => items.Count(Remove) > 0;
public bool RemoveRange(IEnumerable<T> items) => items.Count(Remove) > 0;
[PublicAPI]
public bool ReplaceIfNeededWith([JetBrains.Annotations.NotNull] IReadOnlyCollection<T> other) {
public bool ReplaceIfNeededWith(IReadOnlyCollection<T> other) {
if (SetEquals(other)) {
return false;
}
@@ -153,7 +148,7 @@ namespace ArchiSteamFarm.Collections {
}
[PublicAPI]
public void ReplaceWith([JetBrains.Annotations.NotNull] IEnumerable<T> other) {
public void ReplaceWith(IEnumerable<T> other) {
BackingCollection.Clear();
foreach (T item in other) {