Skip to content

Commit

Permalink
refactor: remove throw helpers (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Apr 13, 2023
1 parent 3b5fb7b commit bb3659c
Show file tree
Hide file tree
Showing 50 changed files with 3 additions and 979 deletions.
12 changes: 0 additions & 12 deletions X10D/src/Collections/ArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ public static class ArrayExtensions
[Pure]
public static IReadOnlyCollection<T> AsReadOnly<T>(this T[] array)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(array);
#else
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
#endif

return Array.AsReadOnly(array);
}
Expand All @@ -49,14 +45,10 @@ public static void Clear<T>(this T?[] array)
/// <exception cref="ArgumentNullException"><paramref name="array" /> is <see langword="null" />.</exception>
public static void Clear<T>(this T?[] array, Range range)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(array);
#else
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
#endif

(int offset, int length) = range.GetOffsetAndLength(array.Length);
array.Clear(offset, length);
Expand All @@ -79,14 +71,10 @@ public static void Clear<T>(this T?[] array, Range range)
/// </exception>
public static void Clear<T>(this T?[] array, int index, int length)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(array);
#else
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
#endif

if (length == 0 || array.Length == 0)
{
Expand Down
16 changes: 0 additions & 16 deletions X10D/src/Collections/BoolListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ public static class BoolListExtensions
[Pure]
public static byte PackByte(this IReadOnlyList<bool> source)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

if (source.Count > 8)
{
Expand All @@ -52,14 +48,10 @@ public static byte PackByte(this IReadOnlyList<bool> source)
[Pure]
public static short PackInt16(this IReadOnlyList<bool> source)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

if (source.Count > 16)
{
Expand All @@ -86,14 +78,10 @@ public static short PackInt16(this IReadOnlyList<bool> source)
[Pure]
public static int PackInt32(this IReadOnlyList<bool> source)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

if (source.Count > 32)
{
Expand All @@ -120,14 +108,10 @@ public static int PackInt32(this IReadOnlyList<bool> source)
[Pure]
public static long PackInt64(this IReadOnlyList<bool> source)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

if (source.Count > 64)
{
Expand Down
8 changes: 0 additions & 8 deletions X10D/src/Collections/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ public static class CollectionExtensions
/// <seealso cref="EnumerableExtensions.DisposeAll{T}" />
public static void ClearAndDisposeAll<T>(this ICollection<T> source) where T : IDisposable
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

if (source.IsReadOnly)
{
Expand Down Expand Up @@ -55,14 +51,10 @@ public static void ClearAndDisposeAll<T>(this ICollection<T> source) where T : I
/// <seealso cref="EnumerableExtensions.DisposeAllAsync{T}" />
public static async Task ClearAndDisposeAllAsync<T>(this ICollection<T> source) where T : IAsyncDisposable
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

if (source.IsReadOnly)
{
Expand Down
64 changes: 0 additions & 64 deletions X10D/src/Collections/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dic
Func<TKey, TValue, TValue> updateValueFactory)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
Expand All @@ -50,7 +46,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dic
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif

#if NET6_0_OR_GREATER
ref var value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
Expand Down Expand Up @@ -97,10 +92,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> di
Func<TKey, TValue, TValue> updateValueFactory)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
Expand All @@ -110,7 +101,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> di
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif

if (dictionary.TryGetValue(key, out TValue? old))
{
Expand Down Expand Up @@ -152,11 +142,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dic
Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
Expand All @@ -171,7 +156,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dic
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif

#if NET6_0_OR_GREATER
ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
Expand Down Expand Up @@ -222,11 +206,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> di
Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
Expand All @@ -241,7 +220,6 @@ public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> di
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif

if (dictionary.TryGetValue(key, out TValue? old))
{
Expand Down Expand Up @@ -291,11 +269,6 @@ public static TValue AddOrUpdate<TKey, TValue, TArg>(this Dictionary<TKey, TValu
Func<TKey, TArg, TValue> addValueFactory, Func<TKey, TValue, TArg, TValue> updateValueFactory, TArg factoryArgument)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
Expand All @@ -310,7 +283,6 @@ public static TValue AddOrUpdate<TKey, TValue, TArg>(this Dictionary<TKey, TValu
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif

#if NET6_0_OR_GREATER
ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
Expand Down Expand Up @@ -367,11 +339,6 @@ public static TValue AddOrUpdate<TKey, TValue, TArg>(this IDictionary<TKey, TVal
Func<TKey, TArg, TValue> addValueFactory, Func<TKey, TValue, TArg, TValue> updateValueFactory, TArg factoryArgument)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
Expand All @@ -386,7 +353,6 @@ public static TValue AddOrUpdate<TKey, TValue, TArg>(this IDictionary<TKey, TVal
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif

if (dictionary.TryGetValue(key, out TValue? old))
{
Expand Down Expand Up @@ -414,14 +380,10 @@ public static TValue AddOrUpdate<TKey, TValue, TArg>(this IDictionary<TKey, TVal
[Pure]
public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

static string SanitizeValue(string? value)
{
Expand Down Expand Up @@ -461,10 +423,6 @@ static string GetQueryParameter(KeyValuePair<TKey, TValue> pair)
public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source,
Func<TValue, string?> selector)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(selector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -474,7 +432,6 @@ public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValueP
{
throw new ArgumentNullException(nameof(selector));
}
#endif

static string SanitizeValue(string? value)
{
Expand Down Expand Up @@ -520,11 +477,6 @@ public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValueP
Func<TKey, string> keySelector, Func<TValue, string?> valueSelector)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(keySelector);
ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -539,7 +491,6 @@ public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValueP
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

static string SanitizeValue(string? value)
{
Expand Down Expand Up @@ -571,14 +522,10 @@ string GetQueryParameter(KeyValuePair<TKey, TValue> pair)
public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif

static string GetQueryParameter(KeyValuePair<TKey, TValue> pair)
{
Expand Down Expand Up @@ -610,10 +557,6 @@ public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair
Func<TValue, string?> selector)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(selector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -623,7 +566,6 @@ public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair
{
throw new ArgumentNullException(nameof(selector));
}
#endif

// can't static here because of 'selector' parameter
string GetQueryParameter(KeyValuePair<TKey, TValue> pair)
Expand Down Expand Up @@ -661,11 +603,6 @@ public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair
Func<TKey, string> keySelector, Func<TValue, string?> valueSelector)
where TKey : notnull
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(keySelector);
ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
Expand All @@ -680,7 +617,6 @@ public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif

// can't static here because of selector parameters
string GetQueryParameter(KeyValuePair<TKey, TValue> pair)
Expand Down
Loading

0 comments on commit bb3659c

Please sign in to comment.