1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:18:47 +00:00

style: cluster throw helpers together to reduce branch repetition

This commit is contained in:
Oliver Booth 2023-04-01 14:37:37 +01:00
parent 431e72a4c1
commit 39c8c7defb
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
6 changed files with 55 additions and 109 deletions

View File

@ -1,4 +1,4 @@
using System.Diagnostics.Contracts;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Web;
@ -37,15 +37,13 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
@ -108,15 +106,13 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
@ -167,23 +163,19 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(addValueFactory);
#else
if (addValueFactory is null)
{
throw new ArgumentNullException(nameof(addValueFactory));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
@ -250,23 +242,19 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(addValueFactory);
#else
if (addValueFactory is null)
{
throw new ArgumentNullException(nameof(addValueFactory));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
@ -325,23 +313,19 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(addValueFactory);
#else
if (addValueFactory is null)
{
throw new ArgumentNullException(nameof(addValueFactory));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
@ -414,23 +398,19 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary);
ArgumentNullException.ThrowIfNull(addValueFactory);
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(addValueFactory);
#else
if (addValueFactory is null)
{
throw new ArgumentNullException(nameof(addValueFactory));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
@ -514,15 +494,13 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(selector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
@ -575,23 +553,19 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(keySelector);
ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(keySelector);
#else
if (keySelector is null)
{
throw new ArgumentNullException(nameof(keySelector));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (valueSelector is null)
{
throw new ArgumentNullException(nameof(valueSelector));
@ -669,15 +643,13 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(selector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
@ -722,23 +694,19 @@ public static class DictionaryExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(keySelector);
ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(keySelector);
#else
if (keySelector is null)
{
throw new ArgumentNullException(nameof(keySelector));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (valueSelector is null)
{
throw new ArgumentNullException(nameof(valueSelector));

View File

@ -157,15 +157,13 @@ public static class RandomExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random);
ArgumentNullException.ThrowIfNull(source);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
@ -534,15 +532,13 @@ public static class RandomExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random);
ArgumentNullException.ThrowIfNull(source);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));

View File

@ -210,15 +210,13 @@ public static class ListOfByteExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(encoding);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(encoding);
#else
if (encoding is null)
{
throw new ArgumentNullException(nameof(encoding));

View File

@ -60,15 +60,13 @@ public static class MemberInfoExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(member);
ArgumentNullException.ThrowIfNull(attribute);
#else
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(attribute);
#else
if (attribute is null)
{
throw new ArgumentNullException(nameof(attribute));
@ -105,15 +103,13 @@ public static class MemberInfoExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(member);
ArgumentNullException.ThrowIfNull(selector);
#else
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
@ -145,15 +141,13 @@ public static class MemberInfoExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(member);
ArgumentNullException.ThrowIfNull(selector);
#else
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));

View File

@ -57,15 +57,13 @@ public static class TypeExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(interfaceType);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(interfaceType);
#else
if (interfaceType is null)
{
throw new ArgumentNullException(nameof(interfaceType));
@ -144,15 +142,13 @@ public static class TypeExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(type);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(type);
#else
if (type is null)
{
throw new ArgumentNullException(nameof(type));

View File

@ -136,23 +136,19 @@ public static class StringExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(sourceEncoding);
ArgumentNullException.ThrowIfNull(destinationEncoding);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(sourceEncoding);
#else
if (sourceEncoding is null)
{
throw new ArgumentNullException(nameof(sourceEncoding));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(destinationEncoding);
#else
if (destinationEncoding is null)
{
throw new ArgumentNullException(nameof(destinationEncoding));
@ -478,15 +474,13 @@ public static class StringExtensions
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(encoding);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(encoding);
#else
if (encoding is null)
{
throw new ArgumentNullException(nameof(encoding));