Resolve CA1062

This commit is contained in:
JustArchi 2021-05-06 23:32:50 +02:00
parent 9a8a61e111
commit 559fdb34c6
5 changed files with 74 additions and 8 deletions

View file

@ -111,7 +111,6 @@ dotnet_diagnostic.ca1028.severity = silent
dotnet_diagnostic.ca1031.severity = silent
# TODO - one at a time
dotnet_diagnostic.ca1062.severity = silent
dotnet_diagnostic.ca1063.severity = silent
dotnet_diagnostic.ca1303.severity = silent
dotnet_diagnostic.ca1307.severity = silent

View file

@ -70,6 +70,10 @@ namespace ArchiSteamFarm.Collections {
public void CopyTo(T[] array, int arrayIndex) => BackingCollection.Keys.CopyTo(array, arrayIndex);
public void ExceptWith(IEnumerable<T> other) {
if (other == null) {
throw new ArgumentNullException(nameof(other));
}
foreach (T item in other) {
Remove(item);
}
@ -146,6 +150,10 @@ namespace ArchiSteamFarm.Collections {
}
public void UnionWith(IEnumerable<T> other) {
if (other == null) {
throw new ArgumentNullException(nameof(other));
}
foreach (T otherElement in other) {
Add(otherElement);
}

View file

@ -29,6 +29,14 @@ namespace ArchiSteamFarm.RuntimeCompatibility {
public static class Path {
public static string GetRelativePath(string relativeTo, string path) {
#if NETFRAMEWORK
if (relativeTo == null) {
throw new ArgumentNullException(nameof(relativeTo));
}
if (path == null) {
throw new ArgumentNullException(nameof(path));
}
if (!path.StartsWith(relativeTo, StringComparison.Ordinal)) {
throw new NotImplementedException();
}

View file

@ -60,15 +60,31 @@ namespace ArchiSteamFarm.RuntimeCompatibility {
}
#if NETFRAMEWORK
public static Task<byte[]> ComputeHashAsync(this HashAlgorithm hashAlgorithm, Stream inputStream) => Task.FromResult(hashAlgorithm.ComputeHash(inputStream));
public static Task<byte[]> ComputeHashAsync(this HashAlgorithm hashAlgorithm, Stream inputStream) {
if (hashAlgorithm == null) {
throw new ArgumentNullException(nameof(hashAlgorithm));
}
return Task.FromResult(hashAlgorithm.ComputeHash(inputStream));
}
public static IWebHostBuilder ConfigureWebHostDefaults(this IWebHostBuilder builder, Action<IWebHostBuilder> configure) {
if (configure == null) {
throw new ArgumentNullException(nameof(configure));
}
configure(builder);
return builder;
}
public static bool Contains(this string input, string value, StringComparison comparisonType) => input.IndexOf(value, comparisonType) >= 0;
public static bool Contains(this string input, string value, StringComparison comparisonType) {
if (input == null) {
throw new ArgumentNullException(nameof(input));
}
return input.IndexOf(value, comparisonType) >= 0;
}
// ReSharper disable once UseDeconstructionOnParameter - we actually implement deconstruction here
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> kv, out TKey key, out TValue value) {
@ -77,15 +93,38 @@ namespace ArchiSteamFarm.RuntimeCompatibility {
}
public static ValueTask DisposeAsync(this IDisposable disposable) {
if (disposable == null) {
throw new ArgumentNullException(nameof(disposable));
}
disposable.Dispose();
return default(ValueTask);
}
public static async Task<WebSocketReceiveResult> ReceiveAsync(this WebSocket webSocket, byte[] buffer, CancellationToken cancellationToken) => await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken).ConfigureAwait(false);
public static async Task SendAsync(this WebSocket webSocket, byte[] buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) => await webSocket.SendAsync(new ArraySegment<byte>(buffer), messageType, endOfMessage, cancellationToken).ConfigureAwait(false);
public static async Task<WebSocketReceiveResult> ReceiveAsync(this WebSocket webSocket, byte[] buffer, CancellationToken cancellationToken) {
if (webSocket == null) {
throw new ArgumentNullException(nameof(webSocket));
}
public static string[] Split(this string text, char separator, StringSplitOptions options = StringSplitOptions.None) => text.Split(new[] { separator }, options);
return await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken).ConfigureAwait(false);
}
public static async Task SendAsync(this WebSocket webSocket, byte[] buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) {
if (webSocket == null) {
throw new ArgumentNullException(nameof(webSocket));
}
await webSocket.SendAsync(new ArraySegment<byte>(buffer), messageType, endOfMessage, cancellationToken).ConfigureAwait(false);
}
public static string[] Split(this string text, char separator, StringSplitOptions options = StringSplitOptions.None) {
if (text == null) {
throw new ArgumentNullException(nameof(text));
}
return text.Split(new[] { separator }, options);
}
public static void TrimExcess<TKey, TValue>(this Dictionary<TKey, TValue> _) { } // no-op
#endif

View file

@ -235,13 +235,25 @@ namespace ArchiSteamFarm {
public static IEnumerable<IElement> SelectElementNodes(this IElement element, string xpath) => element.SelectNodes(xpath).OfType<IElement>();
[PublicAPI]
public static IEnumerable<IElement> SelectNodes(this IDocument document, string xpath) => document.Body.SelectNodes(xpath).OfType<IElement>();
public static IEnumerable<IElement> SelectNodes(this IDocument document, string xpath) {
if (document == null) {
throw new ArgumentNullException(nameof(document));
}
return document.Body.SelectNodes(xpath).OfType<IElement>();
}
[PublicAPI]
public static IElement? SelectSingleElementNode(this IElement element, string xpath) => (IElement?) element.SelectSingleNode(xpath);
[PublicAPI]
public static IElement? SelectSingleNode(this IDocument document, string xpath) => (IElement?) document.Body.SelectSingleNode(xpath);
public static IElement? SelectSingleNode(this IDocument document, string xpath) {
if (document == null) {
throw new ArgumentNullException(nameof(document));
}
return (IElement?) document.Body.SelectSingleNode(xpath);
}
[PublicAPI]
public static IEnumerable<T> ToEnumerable<T>(this T item) {