From 3b5fb7b2be66d881c4a92ce2827110ffdb16329c Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 13 Apr 2023 22:35:43 +0100 Subject: [PATCH 1/2] refactor: remove throw helpers in X10D.DSharpPlus (#80) --- .../src/DiscordChannelExtensions.cs | 9 ------ .../src/DiscordClientExtensions.cs | 8 ----- .../src/DiscordEmbedBuilderExtensions.cs | 31 ++----------------- X10D.DSharpPlus/src/DiscordGuildExtensions.cs | 13 -------- .../src/DiscordMemberExtensions.cs | 10 ------ .../src/DiscordMessageExtensions.cs | 13 -------- X10D.DSharpPlus/src/DiscordUserExtensions.cs | 19 ------------ 7 files changed, 2 insertions(+), 101 deletions(-) diff --git a/X10D.DSharpPlus/src/DiscordChannelExtensions.cs b/X10D.DSharpPlus/src/DiscordChannelExtensions.cs index 2734af9..820ced0 100644 --- a/X10D.DSharpPlus/src/DiscordChannelExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordChannelExtensions.cs @@ -19,14 +19,10 @@ public static class DiscordChannelExtensions /// is . public static DiscordChannel? GetCategory(this DiscordChannel channel) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(channel); -#else if (channel is null) { throw new ArgumentNullException(nameof(channel)); } -#endif while (true) { @@ -60,10 +56,6 @@ public static class DiscordChannelExtensions /// public static async Task NormalizeClientAsync(this DiscordChannel channel, DiscordClient client) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(channel); - ArgumentNullException.ThrowIfNull(client); -#else if (channel is null) { throw new ArgumentNullException(nameof(channel)); @@ -73,7 +65,6 @@ public static class DiscordChannelExtensions { throw new ArgumentNullException(nameof(client)); } -#endif return await client.GetChannelAsync(channel.Id).ConfigureAwait(false); } diff --git a/X10D.DSharpPlus/src/DiscordClientExtensions.cs b/X10D.DSharpPlus/src/DiscordClientExtensions.cs index f3d8964..5dfd415 100644 --- a/X10D.DSharpPlus/src/DiscordClientExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordClientExtensions.cs @@ -20,14 +20,10 @@ public static class DiscordClientExtensions /// is . public static void AutoJoinThreads(this DiscordClient client, bool rejoinIfRemoved = true) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(client); -#else if (client is null) { throw new ArgumentNullException(nameof(client)); } -#endif client.GuildAvailable += (_, args) => args.Guild.JoinAllThreadsAsync(); client.ThreadCreated += (_, args) => args.Thread.JoinThreadAsync(); @@ -53,14 +49,10 @@ public static class DiscordClientExtensions /// is . public static async Task GetUserOrNullAsync(this DiscordClient client, ulong userId) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(client); -#else if (client is null) { throw new ArgumentNullException(nameof(client)); } -#endif try { diff --git a/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs b/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs index 4a23a34..1c2c479 100644 --- a/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs @@ -23,14 +23,10 @@ public static class DiscordEmbedBuilderExtensions T? value, bool inline = false) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(builder); -#else if (builder is null) { throw new ArgumentNullException(nameof(builder)); } -#endif return builder.AddField(name, value?.ToString(), inline); } @@ -53,14 +49,10 @@ public static class DiscordEmbedBuilderExtensions T? value, bool inline = false) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(builder); -#else if (builder is null) { throw new ArgumentNullException(nameof(builder)); } -#endif if (condition) { @@ -92,10 +84,6 @@ public static class DiscordEmbedBuilderExtensions T? value, bool inline = false) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(predicate); -#else if (builder is null) { throw new ArgumentNullException(nameof(builder)); @@ -105,7 +93,6 @@ public static class DiscordEmbedBuilderExtensions { throw new ArgumentNullException(nameof(predicate)); } -#endif if (predicate.Invoke()) { @@ -139,11 +126,6 @@ public static class DiscordEmbedBuilderExtensions Func valueFactory, bool inline = false) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(predicate); - ArgumentNullException.ThrowIfNull(valueFactory); -#else if (builder is null) { throw new ArgumentNullException(nameof(builder)); @@ -158,7 +140,6 @@ public static class DiscordEmbedBuilderExtensions { throw new ArgumentNullException(nameof(valueFactory)); } -#endif if (predicate.Invoke()) { @@ -190,19 +171,15 @@ public static class DiscordEmbedBuilderExtensions Func valueFactory, bool inline = false) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(valueFactory); -#else if (builder is null) { throw new ArgumentNullException(nameof(builder)); } + if (valueFactory is null) { throw new ArgumentNullException(nameof(valueFactory)); } -#endif if (condition) { @@ -220,19 +197,15 @@ public static class DiscordEmbedBuilderExtensions /// The current instance of . public static DiscordEmbedBuilder WithAuthor(this DiscordEmbedBuilder builder, DiscordUser user) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(user); -#else if (builder is null) { throw new ArgumentNullException(nameof(builder)); } + if (user is null) { throw new ArgumentNullException(nameof(user)); } -#endif return builder.WithAuthor(user.GetUsernameWithDiscriminator(), iconUrl: user.AvatarUrl); } diff --git a/X10D.DSharpPlus/src/DiscordGuildExtensions.cs b/X10D.DSharpPlus/src/DiscordGuildExtensions.cs index c03016b..ff4636e 100644 --- a/X10D.DSharpPlus/src/DiscordGuildExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordGuildExtensions.cs @@ -16,14 +16,10 @@ public static class DiscordGuildExtensions /// is . public static async Task JoinAllThreadsAsync(this DiscordGuild guild) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(guild); -#else if (guild is null) { throw new ArgumentNullException(nameof(guild)); } -#endif await Task.WhenAll(guild.Threads.Values.Select(t => t.JoinThreadAsync())).ConfigureAwait(false); } @@ -37,14 +33,10 @@ public static class DiscordGuildExtensions /// is . public static async Task GetMemberOrNullAsync(this DiscordGuild guild, ulong userId) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(guild); -#else if (guild is null) { throw new ArgumentNullException(nameof(guild)); } -#endif try { @@ -77,10 +69,6 @@ public static class DiscordGuildExtensions /// public static async Task NormalizeClientAsync(this DiscordGuild guild, DiscordClient client) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(guild); - ArgumentNullException.ThrowIfNull(client); -#else if (guild is null) { throw new ArgumentNullException(nameof(guild)); @@ -90,7 +78,6 @@ public static class DiscordGuildExtensions { throw new ArgumentNullException(nameof(client)); } -#endif return await client.GetGuildAsync(guild.Id).ConfigureAwait(false); } diff --git a/X10D.DSharpPlus/src/DiscordMemberExtensions.cs b/X10D.DSharpPlus/src/DiscordMemberExtensions.cs index 3fd2020..7ec9925 100644 --- a/X10D.DSharpPlus/src/DiscordMemberExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordMemberExtensions.cs @@ -18,10 +18,6 @@ public static class DiscordMemberExtensions /// public static bool HasRole(this DiscordMember member, DiscordRole role) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(member); - ArgumentNullException.ThrowIfNull(role); -#else if (member is null) { throw new ArgumentNullException(nameof(member)); @@ -31,7 +27,6 @@ public static class DiscordMemberExtensions { throw new ArgumentNullException(nameof(role)); } -#endif return member.Roles.Contains(role); } @@ -52,10 +47,6 @@ public static class DiscordMemberExtensions /// public static async Task NormalizeClientAsync(this DiscordMember member, DiscordClient client) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(member); - ArgumentNullException.ThrowIfNull(client); -#else if (member is null) { throw new ArgumentNullException(nameof(member)); @@ -65,7 +56,6 @@ public static class DiscordMemberExtensions { throw new ArgumentNullException(nameof(client)); } -#endif DiscordGuild guild = await member.Guild.NormalizeClientAsync(client).ConfigureAwait(false); return await guild.GetMemberAsync(member.Id).ConfigureAwait(false); diff --git a/X10D.DSharpPlus/src/DiscordMessageExtensions.cs b/X10D.DSharpPlus/src/DiscordMessageExtensions.cs index f8317c7..f43116d 100644 --- a/X10D.DSharpPlus/src/DiscordMessageExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordMessageExtensions.cs @@ -17,14 +17,10 @@ public static class DiscordMessageExtensions /// is . public static async Task DeleteAfterAsync(this DiscordMessage message, TimeSpan delay, string? reason = null) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(message); -#else if (message is null) { throw new ArgumentNullException(nameof(message)); } -#endif await Task.Delay(delay).ConfigureAwait(false); await message.DeleteAsync(reason).ConfigureAwait(false); @@ -39,14 +35,10 @@ public static class DiscordMessageExtensions /// is . public static async Task DeleteAfterAsync(this Task task, TimeSpan delay, string? reason = null) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(task); -#else if (task is null) { throw new ArgumentNullException(nameof(task)); } -#endif DiscordMessage message = await task.ConfigureAwait(false); await message.DeleteAfterAsync(delay, reason).ConfigureAwait(false); @@ -68,10 +60,6 @@ public static class DiscordMessageExtensions /// public static async Task NormalizeClientAsync(this DiscordMessage message, DiscordClient client) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(message); - ArgumentNullException.ThrowIfNull(client); -#else if (message is null) { throw new ArgumentNullException(nameof(message)); @@ -81,7 +69,6 @@ public static class DiscordMessageExtensions { throw new ArgumentNullException(nameof(client)); } -#endif DiscordChannel channel = await message.Channel.NormalizeClientAsync(client).ConfigureAwait(false); return await channel.GetMessageAsync(message.Id).ConfigureAwait(false); diff --git a/X10D.DSharpPlus/src/DiscordUserExtensions.cs b/X10D.DSharpPlus/src/DiscordUserExtensions.cs index 6ab8314..adfd477 100644 --- a/X10D.DSharpPlus/src/DiscordUserExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordUserExtensions.cs @@ -25,10 +25,6 @@ public static class DiscordUserExtensions /// public static async Task GetAsMemberOfAsync(this DiscordUser user, DiscordGuild guild) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(user); - ArgumentNullException.ThrowIfNull(guild); -#else if (user is null) { throw new ArgumentNullException(nameof(user)); @@ -38,7 +34,6 @@ public static class DiscordUserExtensions { throw new ArgumentNullException(nameof(guild)); } -#endif if (user is DiscordMember member && member.Guild == guild) { @@ -68,14 +63,10 @@ public static class DiscordUserExtensions /// is . public static string GetUsernameWithDiscriminator(this DiscordUser user) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(user); -#else if (user is null) { throw new ArgumentNullException(nameof(user)); } -#endif return $"{user.Username}#{user.Discriminator}"; } @@ -91,10 +82,6 @@ public static class DiscordUserExtensions /// public static async Task IsInGuildAsync(this DiscordUser user, DiscordGuild guild) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(user); - ArgumentNullException.ThrowIfNull(guild); -#else if (user is null) { throw new ArgumentNullException(nameof(user)); @@ -104,7 +91,6 @@ public static class DiscordUserExtensions { throw new ArgumentNullException(nameof(guild)); } -#endif if (guild.Members.TryGetValue(user.Id, out _)) { @@ -138,10 +124,6 @@ public static class DiscordUserExtensions /// public static async Task NormalizeClientAsync(this DiscordUser user, DiscordClient client) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(user); - ArgumentNullException.ThrowIfNull(client); -#else if (user is null) { throw new ArgumentNullException(nameof(user)); @@ -151,7 +133,6 @@ public static class DiscordUserExtensions { throw new ArgumentNullException(nameof(client)); } -#endif return await client.GetUserAsync(user.Id).ConfigureAwait(false); } From bb3659c0472fa701c4499ef79c5c500d573ddcf6 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 13 Apr 2023 22:52:46 +0100 Subject: [PATCH 2/2] refactor: remove throw helpers (#80) --- X10D/src/Collections/ArrayExtensions.cs | 12 --- X10D/src/Collections/BoolListExtensions.cs | 16 ---- X10D/src/Collections/CollectionExtensions.cs | 8 -- X10D/src/Collections/DictionaryExtensions.cs | 64 -------------- X10D/src/Collections/EnumerableExtensions.cs | 56 ------------- X10D/src/Collections/ListExtensions.cs | 45 ---------- X10D/src/Core/RandomExtensions.cs | 66 --------------- X10D/src/Drawing/Polygon.cs | 16 ---- X10D/src/Drawing/PolygonF.cs | 24 ------ X10D/src/Drawing/Polyhedron.cs | 16 ---- X10D/src/Drawing/RandomExtensions.cs | 8 -- X10D/src/IO/DirectoryInfoExtensions.cs | 4 - X10D/src/IO/FileInfoExtensions.cs | 8 -- X10D/src/IO/ListOfByteExtensions.cs | 41 --------- X10D/src/IO/StreamExtensions.cs | 80 ------------------ X10D/src/IO/TextReaderExtensions.cs | 8 -- ...riterExtensions.WriteLineNoAlloc.Double.cs | 12 --- ...WriterExtensions.WriteLineNoAlloc.Int32.cs | 12 --- ...WriterExtensions.WriteLineNoAlloc.Int64.cs | 12 --- ...riterExtensions.WriteLineNoAlloc.Single.cs | 12 --- ...riterExtensions.WriteLineNoAlloc.UInt32.cs | 12 --- ...riterExtensions.WriteLineNoAlloc.UInt64.cs | 12 --- ...extWriterExtensions.WriteNoAlloc.Double.cs | 12 --- ...TextWriterExtensions.WriteNoAlloc.Int32.cs | 12 --- ...TextWriterExtensions.WriteNoAlloc.Int64.cs | 12 --- ...extWriterExtensions.WriteNoAlloc.Single.cs | 12 --- ...extWriterExtensions.WriteNoAlloc.UInt32.cs | 12 --- ...extWriterExtensions.WriteNoAlloc.UInt64.cs | 12 --- X10D/src/Linq/ByteExtensions.cs | 16 ---- X10D/src/Linq/DecimalExtensions.cs | 8 -- X10D/src/Linq/DoubleExtensions.cs | 8 -- X10D/src/Linq/EnumerableExtensions.cs | 36 -------- X10D/src/Linq/Int32Extensions.cs | 16 ---- X10D/src/Linq/Int64Extensions.cs | 16 ---- X10D/src/Linq/ReadOnlySpanExtensions.cs | 12 --- X10D/src/Linq/SingleExtensions.cs | 8 -- X10D/src/Linq/SpanExtensions.cs | 12 --- X10D/src/Math/ComparableExtensions.cs | 32 ------- X10D/src/Net/EndPointExtensions.cs | 8 -- X10D/src/Net/IPAddressExtensions.cs | 8 -- X10D/src/Numerics/RandomExtensions.cs | 16 ---- X10D/src/Reactive/ObservableDisposer.cs | 19 +---- X10D/src/Reactive/ProgressExtensions.cs | 8 -- X10D/src/Reactive/ProgressObservable.cs | 4 - X10D/src/Reflection/MemberInfoExtensions.cs | 20 +---- X10D/src/Reflection/TypeExtensions.cs | 18 ---- X10D/src/Text/EnumerableExtensions.cs | 10 --- X10D/src/Text/StringBuilderReader.cs | 4 - X10D/src/Text/StringExtensions.cs | 83 ------------------- X10D/src/Time/StringExtensions.cs | 4 - 50 files changed, 3 insertions(+), 979 deletions(-) diff --git a/X10D/src/Collections/ArrayExtensions.cs b/X10D/src/Collections/ArrayExtensions.cs index c6ed75b..7dd5863 100644 --- a/X10D/src/Collections/ArrayExtensions.cs +++ b/X10D/src/Collections/ArrayExtensions.cs @@ -17,14 +17,10 @@ public static class ArrayExtensions [Pure] public static IReadOnlyCollection AsReadOnly(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); } @@ -49,14 +45,10 @@ public static class ArrayExtensions /// is . public static void Clear(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); @@ -79,14 +71,10 @@ public static class ArrayExtensions /// public static void Clear(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) { diff --git a/X10D/src/Collections/BoolListExtensions.cs b/X10D/src/Collections/BoolListExtensions.cs index 347d19b..6258617 100644 --- a/X10D/src/Collections/BoolListExtensions.cs +++ b/X10D/src/Collections/BoolListExtensions.cs @@ -18,14 +18,10 @@ public static class BoolListExtensions [Pure] public static byte PackByte(this IReadOnlyList source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (source.Count > 8) { @@ -52,14 +48,10 @@ public static class BoolListExtensions [Pure] public static short PackInt16(this IReadOnlyList source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (source.Count > 16) { @@ -86,14 +78,10 @@ public static class BoolListExtensions [Pure] public static int PackInt32(this IReadOnlyList source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (source.Count > 32) { @@ -120,14 +108,10 @@ public static class BoolListExtensions [Pure] public static long PackInt64(this IReadOnlyList source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (source.Count > 64) { diff --git a/X10D/src/Collections/CollectionExtensions.cs b/X10D/src/Collections/CollectionExtensions.cs index 3554586..e9b2c6e 100644 --- a/X10D/src/Collections/CollectionExtensions.cs +++ b/X10D/src/Collections/CollectionExtensions.cs @@ -16,14 +16,10 @@ public static class CollectionExtensions /// public static void ClearAndDisposeAll(this ICollection 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) { @@ -55,14 +51,10 @@ public static class CollectionExtensions /// public static async Task ClearAndDisposeAllAsync(this ICollection 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) { diff --git a/X10D/src/Collections/DictionaryExtensions.cs b/X10D/src/Collections/DictionaryExtensions.cs index 66823b0..241efe9 100644 --- a/X10D/src/Collections/DictionaryExtensions.cs +++ b/X10D/src/Collections/DictionaryExtensions.cs @@ -37,10 +37,6 @@ public static class DictionaryExtensions Func 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)); @@ -50,7 +46,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif #if NET6_0_OR_GREATER ref var value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists); @@ -97,10 +92,6 @@ public static class DictionaryExtensions Func 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)); @@ -110,7 +101,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif if (dictionary.TryGetValue(key, out TValue? old)) { @@ -152,11 +142,6 @@ public static class DictionaryExtensions Func addValueFactory, Func 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)); @@ -171,7 +156,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif #if NET6_0_OR_GREATER ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists); @@ -222,11 +206,6 @@ public static class DictionaryExtensions Func addValueFactory, Func 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)); @@ -241,7 +220,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif if (dictionary.TryGetValue(key, out TValue? old)) { @@ -291,11 +269,6 @@ public static class DictionaryExtensions Func addValueFactory, Func 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)); @@ -310,7 +283,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif #if NET6_0_OR_GREATER ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists); @@ -367,11 +339,6 @@ public static class DictionaryExtensions Func addValueFactory, Func 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)); @@ -386,7 +353,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif if (dictionary.TryGetValue(key, out TValue? old)) { @@ -414,14 +380,10 @@ public static class DictionaryExtensions [Pure] public static string ToConnectionString(this IEnumerable> 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) { @@ -461,10 +423,6 @@ public static class DictionaryExtensions public static string ToConnectionString(this IEnumerable> source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(selector); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -474,7 +432,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(selector)); } -#endif static string SanitizeValue(string? value) { @@ -520,11 +477,6 @@ public static class DictionaryExtensions Func keySelector, Func 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)); @@ -539,7 +491,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(valueSelector)); } -#endif static string SanitizeValue(string? value) { @@ -571,14 +522,10 @@ public static class DictionaryExtensions public static string ToGetParameters(this IEnumerable> 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 pair) { @@ -610,10 +557,6 @@ public static class DictionaryExtensions Func 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)); @@ -623,7 +566,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(selector)); } -#endif // can't static here because of 'selector' parameter string GetQueryParameter(KeyValuePair pair) @@ -661,11 +603,6 @@ public static class DictionaryExtensions Func keySelector, Func 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)); @@ -680,7 +617,6 @@ public static class DictionaryExtensions { throw new ArgumentNullException(nameof(valueSelector)); } -#endif // can't static here because of selector parameters string GetQueryParameter(KeyValuePair pair) diff --git a/X10D/src/Collections/EnumerableExtensions.cs b/X10D/src/Collections/EnumerableExtensions.cs index c38e4df..a183c2b 100644 --- a/X10D/src/Collections/EnumerableExtensions.cs +++ b/X10D/src/Collections/EnumerableExtensions.cs @@ -24,10 +24,6 @@ public static class EnumerableExtensions [Pure] public static int CountWhereNot(this IEnumerable source, Func predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(predicate); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -37,7 +33,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.Count(item => !predicate(item)); } @@ -58,10 +53,6 @@ public static class EnumerableExtensions [Pure] public static TSource FirstWhereNot(this IEnumerable source, Func predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(predicate); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -71,7 +62,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.First(item => !predicate(item)); } @@ -91,10 +81,6 @@ public static class EnumerableExtensions [Pure] public static TSource? FirstWhereNotOrDefault(this IEnumerable source, Func predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(predicate); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -104,7 +90,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.FirstOrDefault(item => !predicate(item)); } @@ -127,10 +112,6 @@ public static class EnumerableExtensions /// public static void For(this IEnumerable source, Action action) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(action); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -140,7 +121,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(action)); } -#endif var index = 0; foreach (T item in source) @@ -166,10 +146,6 @@ public static class EnumerableExtensions /// public static void ForEach(this IEnumerable source, Action action) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(action); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -179,7 +155,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(action)); } -#endif foreach (T item in source) { @@ -196,14 +171,10 @@ public static class EnumerableExtensions /// public static void DisposeAll(this IEnumerable source) where T : IDisposable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif foreach (T item in source) { @@ -227,14 +198,10 @@ public static class EnumerableExtensions /// public static async Task DisposeAllAsync(this IEnumerable source) where T : IAsyncDisposable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif foreach (T item in source) { @@ -264,10 +231,6 @@ public static class EnumerableExtensions [Pure] public static TSource LastWhereNot(this IEnumerable source, Func predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(predicate); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -277,7 +240,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.Last(item => !predicate(item)); } @@ -297,10 +259,6 @@ public static class EnumerableExtensions [Pure] public static TSource? LastWhereNotOrDefault(this IEnumerable source, Func predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(predicate); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -310,7 +268,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.LastOrDefault(item => !predicate(item)); } @@ -326,14 +283,10 @@ public static class EnumerableExtensions [Pure] public static IReadOnlyCollection Shuffled(this IEnumerable source, Random? random = null) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif var list = new List(source); list.Shuffle(random); @@ -355,10 +308,6 @@ public static class EnumerableExtensions [Pure] public static IEnumerable WhereNot(this IEnumerable source, Func predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(predicate); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -368,7 +317,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.Where(item => !predicate(item)); } @@ -386,14 +334,10 @@ public static class EnumerableExtensions /// is . public static IEnumerable WhereNotNull(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Where(item => item is not null).Select(item => item!); } diff --git a/X10D/src/Collections/ListExtensions.cs b/X10D/src/Collections/ListExtensions.cs index 69292b4..be53ee8 100644 --- a/X10D/src/Collections/ListExtensions.cs +++ b/X10D/src/Collections/ListExtensions.cs @@ -19,14 +19,10 @@ public static class ListExtensions /// is . public static void Fill(this IList source, T value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif for (var i = 0; i < source.Count; i++) { @@ -53,14 +49,10 @@ public static class ListExtensions /// public static void Fill(this IList source, T value, int startIndex, int count) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (startIndex < 0) { @@ -105,14 +97,10 @@ public static class ListExtensions /// is . public static int IndexOf(this IReadOnlyList source, T? item) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.IndexOf(item, 0, source.Count); } @@ -138,14 +126,10 @@ public static class ListExtensions /// public static int IndexOf(this IReadOnlyList source, T? item, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.IndexOf(item, startIndex, source.Count - startIndex); } @@ -182,14 +166,10 @@ public static class ListExtensions /// public static int IndexOf(this IReadOnlyList source, T? item, int startIndex, int count) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (startIndex < 0 || startIndex > source.Count) { @@ -233,14 +213,10 @@ public static class ListExtensions [Pure] public static T Random(this IReadOnlyList source, Random? random = null) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif random ??= RandomExtensions.GetShared(); return random.NextFrom(source); @@ -260,14 +236,10 @@ public static class ListExtensions /// public static void RemoveRange(this IList source, Range range) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif int start = range.Start.IsFromEnd ? source.Count - range.Start.Value : range.Start.Value; int end = range.End.IsFromEnd ? source.Count - range.End.Value : range.End.Value; @@ -300,14 +272,10 @@ public static class ListExtensions /// is . public static void Shuffle(this IList source, Random? random = null) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif random ??= RandomExtensions.GetShared(); @@ -334,14 +302,10 @@ public static class ListExtensions /// public static IReadOnlyList Slice(this IReadOnlyList source, int start) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Slice(start, source.Count - start); } @@ -363,14 +327,10 @@ public static class ListExtensions /// public static IReadOnlyList Slice(this IReadOnlyList source, int start, int length) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (start < 0 || start > source.Count) { @@ -406,10 +366,6 @@ public static class ListExtensions /// public static void Swap(this IList source, IList other) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(other); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -419,7 +375,6 @@ public static class ListExtensions { throw new ArgumentNullException(nameof(other)); } -#endif int min = System.Math.Min(source.Count, other.Count); for (var index = 0; index < min; index++) diff --git a/X10D/src/Core/RandomExtensions.cs b/X10D/src/Core/RandomExtensions.cs index 32acc3b..49e8634 100644 --- a/X10D/src/Core/RandomExtensions.cs +++ b/X10D/src/Core/RandomExtensions.cs @@ -27,14 +27,10 @@ public static class RandomExtensions public static T Next(this Random random) where T : struct, Enum { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif var values = Enum.GetValues(typeof(T)); return (T)values.GetValue(random.Next(values.Length))!; @@ -54,14 +50,10 @@ public static class RandomExtensions /// is . public static bool NextBoolean(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return random.NextDouble() >= 0.5; } @@ -81,14 +73,10 @@ public static class RandomExtensions /// is less than 0. public static double NextDouble(this Random random, double maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif if (maxValue < 0) { @@ -117,14 +105,10 @@ public static class RandomExtensions /// public static double NextDouble(this Random random, double minValue, double maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif if (maxValue < minValue) { @@ -155,10 +139,6 @@ public static class RandomExtensions /// public static T NextFrom(this Random random, IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); - ArgumentNullException.ThrowIfNull(source); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); @@ -168,7 +148,6 @@ public static class RandomExtensions { throw new ArgumentNullException(nameof(source)); } -#endif if (source is T[] array) { @@ -206,14 +185,10 @@ public static class RandomExtensions /// public static T NextFrom(this Random random, Span source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return source[random.Next(source.Length)]; } @@ -242,14 +217,10 @@ public static class RandomExtensions /// public static T NextFrom(this Random random, ReadOnlySpan source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return source[random.Next(source.Length)]; } @@ -264,14 +235,10 @@ public static class RandomExtensions /// is . public static byte NextByte(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return random.NextByte(byte.MaxValue); } @@ -292,14 +259,10 @@ public static class RandomExtensions /// is . public static byte NextByte(this Random random, byte maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return random.NextByte(0, maxValue); } @@ -325,14 +288,10 @@ public static class RandomExtensions /// public static byte NextByte(this Random random, byte minValue, byte maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return (byte)random.Next(minValue, maxValue); } @@ -347,14 +306,10 @@ public static class RandomExtensions /// is . public static short NextInt16(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return random.NextInt16(short.MaxValue); } @@ -376,14 +331,10 @@ public static class RandomExtensions /// is less than 0. public static short NextInt16(this Random random, short maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif if (maxValue < 0) { @@ -414,14 +365,10 @@ public static class RandomExtensions /// is . public static short NextInt16(this Random random, short minValue, short maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif return (short)random.Next(minValue, maxValue); } @@ -459,14 +406,10 @@ public static class RandomExtensions /// is less than 0. public static float NextSingle(this Random random, float maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif if (maxValue < 0) { @@ -495,14 +438,10 @@ public static class RandomExtensions /// public static float NextSingle(this Random random, float minValue, float maxValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif if (maxValue < minValue) { @@ -530,10 +469,6 @@ public static class RandomExtensions /// is less than 0. public static string NextString(this Random random, IReadOnlyList source, int length) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); - ArgumentNullException.ThrowIfNull(source); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); @@ -543,7 +478,6 @@ public static class RandomExtensions { throw new ArgumentNullException(nameof(source)); } -#endif if (length < 0) { diff --git a/X10D/src/Drawing/Polygon.cs b/X10D/src/Drawing/Polygon.cs index 63abae8..9f03b58 100644 --- a/X10D/src/Drawing/Polygon.cs +++ b/X10D/src/Drawing/Polygon.cs @@ -22,14 +22,10 @@ public class Polygon : IEquatable /// public Polygon(Polygon polygon) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(polygon); -#else if (polygon is null) { throw new ArgumentNullException(nameof(polygon)); } -#endif _vertices = new List(); for (var index = 0; index < polygon._vertices.Count; index++) @@ -45,14 +41,10 @@ public class Polygon : IEquatable /// An enumerable collection of vertices from which the polygon should be constructed. public Polygon(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif _vertices = new List(vertices); } @@ -176,14 +168,10 @@ public class Polygon : IEquatable /// is . public static Polygon FromPolygonF(PolygonF polygon) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(polygon); -#else if (polygon is null) { throw new ArgumentNullException(nameof(polygon)); } -#endif var vertices = new List(); @@ -211,14 +199,10 @@ public class Polygon : IEquatable /// is . public void AddVertices(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif foreach (Point vertex in vertices) { diff --git a/X10D/src/Drawing/PolygonF.cs b/X10D/src/Drawing/PolygonF.cs index 51d9eeb..074edc3 100644 --- a/X10D/src/Drawing/PolygonF.cs +++ b/X10D/src/Drawing/PolygonF.cs @@ -25,14 +25,10 @@ public class PolygonF /// is . public PolygonF(PolygonF polygon) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(polygon); -#else if (polygon is null) { throw new ArgumentNullException(nameof(polygon)); } -#endif _vertices = new List(); for (var index = 0; index < polygon._vertices.Count; index++) { @@ -48,14 +44,10 @@ public class PolygonF /// is . public PolygonF(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif _vertices = new List(); foreach (Vector2 vertex in vertices) @@ -71,14 +63,10 @@ public class PolygonF /// is . public PolygonF(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif _vertices = new List(vertices); } @@ -202,14 +190,10 @@ public class PolygonF /// is . public static PolygonF FromPolygon(Polygon polygon) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(polygon); -#else if (polygon is null) { throw new ArgumentNullException(nameof(polygon)); } -#endif var vertices = new List(); @@ -246,14 +230,10 @@ public class PolygonF /// is . public void AddVertices(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif foreach (PointF vertex in vertices) { @@ -268,14 +248,10 @@ public class PolygonF /// is . public void AddVertices(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif foreach (Vector2 vertex in vertices) { diff --git a/X10D/src/Drawing/Polyhedron.cs b/X10D/src/Drawing/Polyhedron.cs index 2f46ca0..6be327e 100644 --- a/X10D/src/Drawing/Polyhedron.cs +++ b/X10D/src/Drawing/Polyhedron.cs @@ -34,14 +34,10 @@ public class Polyhedron : IEquatable /// is . public Polyhedron(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif _vertices = new List(vertices); } @@ -137,14 +133,10 @@ public class Polyhedron : IEquatable /// is . public static Polyhedron FromPolygon(Polygon polygon) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(polygon); -#else if (polygon is null) { throw new ArgumentNullException(nameof(polygon)); } -#endif var vertices = new List(); @@ -164,14 +156,10 @@ public class Polyhedron : IEquatable /// is . public static Polyhedron FromPolygonF(PolygonF polygon) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(polygon); -#else if (polygon is null) { throw new ArgumentNullException(nameof(polygon)); } -#endif var vertices = new List(); @@ -199,14 +187,10 @@ public class Polyhedron : IEquatable /// is . public void AddVertices(IEnumerable vertices) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(vertices); -#else if (vertices is null) { throw new ArgumentNullException(nameof(vertices)); } -#endif foreach (Vector3 vertex in vertices) { diff --git a/X10D/src/Drawing/RandomExtensions.cs b/X10D/src/Drawing/RandomExtensions.cs index 24c7419..880cd84 100644 --- a/X10D/src/Drawing/RandomExtensions.cs +++ b/X10D/src/Drawing/RandomExtensions.cs @@ -17,14 +17,10 @@ public static class RandomExtensions /// is . public static Color NextColorRgb(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif int rgb = random.Next(); return Color.FromArgb(0xFF, (byte)(rgb >> 16 & 0xFF), (byte)(rgb >> 8 & 0xFF), (byte)(rgb & 0xFF)); @@ -38,14 +34,10 @@ public static class RandomExtensions /// is . public static Color NextColorArgb(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif int argb = random.Next(); return Color.FromArgb(argb); diff --git a/X10D/src/IO/DirectoryInfoExtensions.cs b/X10D/src/IO/DirectoryInfoExtensions.cs index 5eb0a92..c6c7e81 100644 --- a/X10D/src/IO/DirectoryInfoExtensions.cs +++ b/X10D/src/IO/DirectoryInfoExtensions.cs @@ -33,14 +33,10 @@ public static class DirectoryInfoExtensions /// This directory or one of its children contain a read-only file. public static void Clear(this DirectoryInfo directory) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(directory); -#else if (directory is null) { throw new ArgumentNullException(nameof(directory)); } -#endif if (!directory.Exists) { diff --git a/X10D/src/IO/FileInfoExtensions.cs b/X10D/src/IO/FileInfoExtensions.cs index a0878bc..e1a4e69 100644 --- a/X10D/src/IO/FileInfoExtensions.cs +++ b/X10D/src/IO/FileInfoExtensions.cs @@ -29,14 +29,10 @@ public static class FileInfoExtensions public static byte[] GetHash(this FileInfo value) where T : HashAlgorithm { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif using FileStream stream = value.OpenRead(); return stream.GetHash(); @@ -69,14 +65,10 @@ public static class FileInfoExtensions public static bool TryWriteHash(this FileInfo value, Span destination, out int bytesWritten) where T : HashAlgorithm { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif using FileStream stream = value.OpenRead(); return stream.TryWriteHash(destination, out bytesWritten); diff --git a/X10D/src/IO/ListOfByteExtensions.cs b/X10D/src/IO/ListOfByteExtensions.cs index 3289fef..5d9122f 100644 --- a/X10D/src/IO/ListOfByteExtensions.cs +++ b/X10D/src/IO/ListOfByteExtensions.cs @@ -19,14 +19,10 @@ public static class ListOfByteExtensions /// is . public static string AsString(this IReadOnlyList source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToString(source.ToArray()); } @@ -54,14 +50,10 @@ public static class ListOfByteExtensions /// is . public static double ToDouble(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToDouble(source.ToArray(), startIndex); } @@ -86,14 +78,10 @@ public static class ListOfByteExtensions /// is . public static short ToInt16(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToInt16(source.ToArray(), startIndex); } @@ -118,14 +106,10 @@ public static class ListOfByteExtensions /// is . public static int ToInt32(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToInt32(source.ToArray(), startIndex); } @@ -150,14 +134,10 @@ public static class ListOfByteExtensions /// is . public static long ToInt64(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToInt64(source.ToArray(), startIndex); } @@ -183,14 +163,10 @@ public static class ListOfByteExtensions /// is . public static float ToSingle(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToSingle(source.ToArray(), startIndex); } @@ -208,10 +184,6 @@ public static class ListOfByteExtensions /// public static string ToString(this IReadOnlyList source, Encoding encoding) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(encoding); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -221,7 +193,6 @@ public static class ListOfByteExtensions { throw new ArgumentNullException(nameof(encoding)); } -#endif return encoding.GetString(source.ToArray()); } @@ -248,14 +219,10 @@ public static class ListOfByteExtensions [CLSCompliant(false)] public static ushort ToUInt16(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToUInt16(source.ToArray(), startIndex); } @@ -282,14 +249,10 @@ public static class ListOfByteExtensions [CLSCompliant(false)] public static uint ToUInt32(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToUInt32(source.ToArray(), startIndex); } @@ -316,14 +279,10 @@ public static class ListOfByteExtensions [CLSCompliant(false)] public static ulong ToUInt64(this IReadOnlyList source, int startIndex) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return BitConverter.ToUInt64(source.ToArray(), startIndex); } diff --git a/X10D/src/IO/StreamExtensions.cs b/X10D/src/IO/StreamExtensions.cs index c55b784..d1d44db 100644 --- a/X10D/src/IO/StreamExtensions.cs +++ b/X10D/src/IO/StreamExtensions.cs @@ -33,14 +33,10 @@ public static class StreamExtensions public static byte[] GetHash(this Stream stream) where T : HashAlgorithm { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif if (!stream.CanRead) { @@ -87,14 +83,10 @@ public static class StreamExtensions /// A decimal value read from the stream. public static decimal ReadDecimal(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -151,14 +143,10 @@ public static class StreamExtensions /// A double-precision floating point value read from the stream. public static double ReadDouble(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -211,14 +199,10 @@ public static class StreamExtensions /// An two-byte unsigned integer read from the stream. public static short ReadInt16(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -265,14 +249,10 @@ public static class StreamExtensions /// An four-byte unsigned integer read from the stream. public static int ReadInt32(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -319,14 +299,10 @@ public static class StreamExtensions /// An eight-byte unsigned integer read from the stream. public static long ReadInt64(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -373,14 +349,10 @@ public static class StreamExtensions /// A single-precision floating point value read from the stream. public static float ReadSingle(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -435,14 +407,10 @@ public static class StreamExtensions [CLSCompliant(false)] public static ushort ReadUInt16(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -491,14 +459,10 @@ public static class StreamExtensions [CLSCompliant(false)] public static uint ReadUInt32(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -547,14 +511,10 @@ public static class StreamExtensions [CLSCompliant(false)] public static ulong ReadUInt64(this Stream stream, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -607,14 +567,10 @@ public static class StreamExtensions public static bool TryWriteHash(this Stream stream, Span destination, out int bytesWritten) where T : HashAlgorithm { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif if (!stream.CanRead) { @@ -671,14 +627,10 @@ public static class StreamExtensions /// The number of bytes written to the stream. public static int Write(this Stream stream, short value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -735,14 +687,10 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, int value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -800,14 +748,10 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, long value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -867,14 +811,10 @@ public static class StreamExtensions [CLSCompliant(false)] public static int Write(this Stream stream, ushort value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -934,14 +874,10 @@ public static class StreamExtensions [CLSCompliant(false)] public static int Write(this Stream stream, uint value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -1001,14 +937,10 @@ public static class StreamExtensions [CLSCompliant(false)] public static int Write(this Stream stream, ulong value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -1052,14 +984,10 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, float value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -1135,14 +1063,10 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, double value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) @@ -1219,14 +1143,10 @@ public static class StreamExtensions [ExcludeFromCodeCoverage] public static int Write(this Stream stream, decimal value, Endianness endianness) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(stream); -#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } -#endif #if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) diff --git a/X10D/src/IO/TextReaderExtensions.cs b/X10D/src/IO/TextReaderExtensions.cs index 4ecb213..b8bef35 100644 --- a/X10D/src/IO/TextReaderExtensions.cs +++ b/X10D/src/IO/TextReaderExtensions.cs @@ -13,14 +13,10 @@ public static class TextReaderExtensions /// is . public static IEnumerable EnumerateLines(this TextReader reader) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(reader); -#else if (reader is null) { throw new ArgumentNullException(nameof(reader)); } -#endif while (reader.ReadLine() is { } line) { @@ -36,14 +32,10 @@ public static class TextReaderExtensions /// is . public static async IAsyncEnumerable EnumerateLinesAsync(this TextReader reader) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(reader); -#else if (reader is null) { throw new ArgumentNullException(nameof(reader)); } -#endif while (await reader.ReadLineAsync().ConfigureAwait(false) is { } line) { diff --git a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Double.cs b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Double.cs index 1a63f42..1317846 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Double.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Double.cs @@ -16,14 +16,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, double value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -41,14 +37,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, double value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteLineNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -68,14 +60,10 @@ public static partial class TextWriterExtensions public static void WriteLineNoAlloc(this TextWriter writer, double value, ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteNoAlloc(value, format, formatProvider); writer.WriteLine(); diff --git a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int32.cs b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int32.cs index 8836d63..9640a6a 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int32.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int32.cs @@ -16,14 +16,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, int value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -41,14 +37,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, int value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteLineNoAlloc(writer, (long)value, format, CultureInfo.CurrentCulture); } @@ -68,14 +60,10 @@ public static partial class TextWriterExtensions public static void WriteLineNoAlloc(this TextWriter writer, int value, ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteNoAlloc(value, format, formatProvider); writer.WriteLine(); diff --git a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int64.cs b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int64.cs index 83deadd..8ca5855 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int64.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int64.cs @@ -16,14 +16,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, long value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -41,14 +37,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, long value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture); } @@ -70,14 +62,10 @@ public static partial class TextWriterExtensions ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteNoAlloc(value, format, formatProvider); writer.WriteLine(); diff --git a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Single.cs b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Single.cs index bb6d2e0..9194c62 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Single.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Single.cs @@ -16,14 +16,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, float value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -41,14 +37,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteLineNoAlloc(this TextWriter writer, float value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteLineNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -68,14 +60,10 @@ public static partial class TextWriterExtensions public static void WriteLineNoAlloc(this TextWriter writer, float value, ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteNoAlloc(value, format, formatProvider); writer.WriteLine(); diff --git a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt32.cs b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt32.cs index 98e9d42..b812afb 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt32.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt32.cs @@ -17,14 +17,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteLineNoAlloc(this TextWriter writer, uint value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -43,14 +39,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteLineNoAlloc(this TextWriter writer, uint value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteLineNoAlloc(writer, (long)value, format, CultureInfo.CurrentCulture); } @@ -73,14 +65,10 @@ public static partial class TextWriterExtensions ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteNoAlloc(value, format, formatProvider); writer.WriteLine(); diff --git a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt64.cs b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt64.cs index 68f397f..7b55571 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt64.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt64.cs @@ -17,14 +17,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteLineNoAlloc(this TextWriter writer, ulong value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -43,14 +39,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteLineNoAlloc(this TextWriter writer, ulong value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture); } @@ -73,14 +65,10 @@ public static partial class TextWriterExtensions ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif writer.WriteNoAlloc(value, format, formatProvider); writer.WriteLine(); diff --git a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Double.cs b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Double.cs index 6b6de18..a8d5bbb 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Double.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Double.cs @@ -15,14 +15,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, double value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -39,14 +35,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, double value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -65,14 +57,10 @@ public static partial class TextWriterExtensions public static void WriteNoAlloc(this TextWriter writer, double value, ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif Span buffer = stackalloc char[100]; if (value.TryFormat(buffer, out int charsWritten, format, formatProvider)) diff --git a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int32.cs b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int32.cs index c2366bf..2018363 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int32.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int32.cs @@ -16,14 +16,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, int value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -40,14 +36,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, int value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -65,14 +57,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, int value, ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif int digitCount = value.CountDigits(); Span buffer = stackalloc char[System.Math.Max(value < 0 ? digitCount + 1 : digitCount, 100)]; diff --git a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int64.cs b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int64.cs index 049d891..c0cb32f 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int64.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int64.cs @@ -16,14 +16,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, long value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -40,14 +36,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, long value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -68,14 +60,10 @@ public static partial class TextWriterExtensions ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif int digitCount = value.CountDigits(); Span buffer = stackalloc char[System.Math.Max(value < 0 ? digitCount + 1 : digitCount, 100)]; diff --git a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Single.cs b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Single.cs index f595593..b48a415 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Single.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Single.cs @@ -15,14 +15,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, float value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -39,14 +35,10 @@ public static partial class TextWriterExtensions /// An I/O error occurs. public static void WriteNoAlloc(this TextWriter writer, float value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -65,14 +57,10 @@ public static partial class TextWriterExtensions public static void WriteNoAlloc(this TextWriter writer, float value, ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif Span buffer = stackalloc char[100]; if (value.TryFormat(buffer, out int charsWritten, format, formatProvider)) diff --git a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt32.cs b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt32.cs index f8d32a2..b38fa0a 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt32.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt32.cs @@ -17,14 +17,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteNoAlloc(this TextWriter writer, uint value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -42,14 +38,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteNoAlloc(this TextWriter writer, uint value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -71,14 +63,10 @@ public static partial class TextWriterExtensions ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif int digitCount = value.CountDigits(); Span buffer = stackalloc char[System.Math.Max(digitCount, 100)]; diff --git a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt64.cs b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt64.cs index 5e266e4..d9a48f4 100644 --- a/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt64.cs +++ b/X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt64.cs @@ -17,14 +17,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteNoAlloc(this TextWriter writer, ulong value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture); } @@ -42,14 +38,10 @@ public static partial class TextWriterExtensions [CLSCompliant(false)] public static void WriteNoAlloc(this TextWriter writer, ulong value, ReadOnlySpan format) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture); } @@ -71,14 +63,10 @@ public static partial class TextWriterExtensions ReadOnlySpan format, IFormatProvider? formatProvider) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(writer); -#else if (writer is null) { throw new ArgumentNullException(nameof(writer)); } -#endif int digitCount = value.CountDigits(); Span buffer = stackalloc char[System.Math.Max(digitCount, 100)]; diff --git a/X10D/src/Linq/ByteExtensions.cs b/X10D/src/Linq/ByteExtensions.cs index 3d7524d..64d1c01 100644 --- a/X10D/src/Linq/ByteExtensions.cs +++ b/X10D/src/Linq/ByteExtensions.cs @@ -15,14 +15,10 @@ public static class ByteExtensions /// is . public static byte Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate((byte)1, (current, value) => (byte)(current * value)); } @@ -36,14 +32,10 @@ public static class ByteExtensions [CLSCompliant(false)] public static sbyte Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate((sbyte)1, (current, value) => (sbyte)(current * value)); } @@ -59,14 +51,10 @@ public static class ByteExtensions /// is . public static byte Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } @@ -83,14 +71,10 @@ public static class ByteExtensions [CLSCompliant(false)] public static sbyte Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/DecimalExtensions.cs b/X10D/src/Linq/DecimalExtensions.cs index 01dde51..c5e1bc7 100644 --- a/X10D/src/Linq/DecimalExtensions.cs +++ b/X10D/src/Linq/DecimalExtensions.cs @@ -13,14 +13,10 @@ public static class DecimalExtensions /// is . public static decimal Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate(1m, (current, value) => (current * value)); } @@ -36,14 +32,10 @@ public static class DecimalExtensions /// is . public static decimal Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/DoubleExtensions.cs b/X10D/src/Linq/DoubleExtensions.cs index afb38ae..23628af 100644 --- a/X10D/src/Linq/DoubleExtensions.cs +++ b/X10D/src/Linq/DoubleExtensions.cs @@ -13,14 +13,10 @@ public static class DoubleExtensions /// is . public static double Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate(1.0, (current, value) => (current * value)); } @@ -36,14 +32,10 @@ public static class DoubleExtensions /// is . public static double Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/EnumerableExtensions.cs b/X10D/src/Linq/EnumerableExtensions.cs index 92592bf..05004c9 100644 --- a/X10D/src/Linq/EnumerableExtensions.cs +++ b/X10D/src/Linq/EnumerableExtensions.cs @@ -22,14 +22,10 @@ public static class EnumerableExtensions /// is . public static IEnumerable ConcatOne(this IEnumerable source, TSource value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif foreach (TSource item in source) { @@ -52,14 +48,10 @@ public static class EnumerableExtensions /// is . public static IEnumerable Except(this IEnumerable source, TSource item) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Where(i => !Equals(i, item)); } @@ -74,14 +66,10 @@ public static class EnumerableExtensions /// contains no elements. public static (T? Minimum, T? Maximum) MinMax(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return MinMax(source, Comparer.Default); } @@ -97,14 +85,10 @@ public static class EnumerableExtensions /// contains no elements. public static (T? Minimum, T? Maximum) MinMax(this IEnumerable source, IComparer? comparer) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif comparer ??= Comparer.Default; @@ -160,10 +144,6 @@ public static class EnumerableExtensions public static (TResult? Minimum, TResult? Maximum) MinMax(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(selector); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -173,7 +153,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(selector)); } -#endif return MinMax(source, selector, Comparer.Default); } @@ -194,10 +173,6 @@ public static class EnumerableExtensions Func selector, IComparer? comparer) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(selector); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -207,7 +182,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(selector)); } -#endif comparer ??= Comparer.Default; @@ -263,10 +237,6 @@ public static class EnumerableExtensions public static (TSource? Minimum, TSource? Maximum) MinMaxBy(this IEnumerable source, Func keySelector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(keySelector); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -276,7 +246,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(keySelector)); } -#endif return MinMaxBy(source, keySelector, Comparer.Default); } @@ -296,10 +265,6 @@ public static class EnumerableExtensions Func keySelector, IComparer? comparer) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(keySelector); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -309,7 +274,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(keySelector)); } -#endif comparer ??= Comparer.Default; TSource? minValue; diff --git a/X10D/src/Linq/Int32Extensions.cs b/X10D/src/Linq/Int32Extensions.cs index 871e422..876f373 100644 --- a/X10D/src/Linq/Int32Extensions.cs +++ b/X10D/src/Linq/Int32Extensions.cs @@ -15,14 +15,10 @@ public static class Int32Extensions /// is . public static int Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate(1, (current, value) => current * value); } @@ -36,14 +32,10 @@ public static class Int32Extensions [CLSCompliant(false)] public static uint Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate(1u, (current, value) => current * value); } @@ -59,14 +51,10 @@ public static class Int32Extensions /// is . public static int Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } @@ -83,14 +71,10 @@ public static class Int32Extensions [CLSCompliant(false)] public static uint Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/Int64Extensions.cs b/X10D/src/Linq/Int64Extensions.cs index 07b9802..00061d4 100644 --- a/X10D/src/Linq/Int64Extensions.cs +++ b/X10D/src/Linq/Int64Extensions.cs @@ -15,14 +15,10 @@ public static class Int64Extensions /// is . public static long Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate(1L, (current, value) => current * value); } @@ -36,14 +32,10 @@ public static class Int64Extensions [CLSCompliant(false)] public static ulong Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate(1UL, (current, value) => current * value); } @@ -59,14 +51,10 @@ public static class Int64Extensions /// is . public static long Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } @@ -83,14 +71,10 @@ public static class Int64Extensions [CLSCompliant(false)] public static ulong Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/ReadOnlySpanExtensions.cs b/X10D/src/Linq/ReadOnlySpanExtensions.cs index bf0d1d3..9d20ff8 100644 --- a/X10D/src/Linq/ReadOnlySpanExtensions.cs +++ b/X10D/src/Linq/ReadOnlySpanExtensions.cs @@ -21,14 +21,10 @@ public static class ReadOnlySpanExtensions [Pure] public static bool All(this ReadOnlySpan source, Predicate predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(predicate); -#else if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } -#endif if (source.IsEmpty) { @@ -60,14 +56,10 @@ public static class ReadOnlySpanExtensions [Pure] public static bool Any(this ReadOnlySpan source, Predicate predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(predicate); -#else if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } -#endif if (source.IsEmpty) { @@ -97,14 +89,10 @@ public static class ReadOnlySpanExtensions /// is . public static int Count(this ReadOnlySpan source, Predicate predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(predicate); -#else if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } -#endif if (source.IsEmpty) { diff --git a/X10D/src/Linq/SingleExtensions.cs b/X10D/src/Linq/SingleExtensions.cs index 9d48203..e80ed9b 100644 --- a/X10D/src/Linq/SingleExtensions.cs +++ b/X10D/src/Linq/SingleExtensions.cs @@ -13,14 +13,10 @@ public static class SingleExtensions /// is . public static float Product(this IEnumerable source) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Aggregate(1f, (current, value) => (current * value)); } @@ -36,14 +32,10 @@ public static class SingleExtensions /// is . public static float Product(this IEnumerable source, Func selector) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/SpanExtensions.cs b/X10D/src/Linq/SpanExtensions.cs index ce2e3f3..9b84308 100644 --- a/X10D/src/Linq/SpanExtensions.cs +++ b/X10D/src/Linq/SpanExtensions.cs @@ -21,14 +21,10 @@ public static class SpanExtensions [Pure] public static bool All(this Span source, Predicate predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(predicate); -#else if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } -#endif if (source.IsEmpty) { @@ -60,14 +56,10 @@ public static class SpanExtensions [Pure] public static bool Any(this Span source, Predicate predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(predicate); -#else if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } -#endif if (source.IsEmpty) { @@ -97,14 +89,10 @@ public static class SpanExtensions /// is . public static int Count(this Span source, Predicate predicate) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(predicate); -#else if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } -#endif if (source.IsEmpty) { diff --git a/X10D/src/Math/ComparableExtensions.cs b/X10D/src/Math/ComparableExtensions.cs index e1af91f..9aea7fc 100644 --- a/X10D/src/Math/ComparableExtensions.cs +++ b/X10D/src/Math/ComparableExtensions.cs @@ -56,14 +56,10 @@ public static class ComparableExtensions where T2 : IComparable where T3 : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif if (lower.GreaterThan(upper)) { @@ -114,14 +110,10 @@ public static class ComparableExtensions public static T Clamp(this T value, T lower, T upper) where T : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif if (lower.GreaterThan(upper)) { @@ -160,14 +152,10 @@ public static class ComparableExtensions public static bool GreaterThan(this T1 value, T2 other) where T1 : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.CompareTo(other) > 0; } @@ -199,14 +187,10 @@ public static class ComparableExtensions public static bool GreaterThanOrEqualTo(this T1 value, T2 other) where T1 : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.CompareTo(other) >= 0; } @@ -238,14 +222,10 @@ public static class ComparableExtensions public static bool LessThan(this T1 value, T2 other) where T1 : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.CompareTo(other) < 0; } @@ -277,14 +257,10 @@ public static class ComparableExtensions public static bool LessThanOrEqualTo(this T1 value, T2 other) where T1 : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.CompareTo(other) <= 0; } @@ -315,14 +291,10 @@ public static class ComparableExtensions public static T Max(this T value, T other) where T : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.GreaterThan(other) ? value : other; } @@ -353,14 +325,10 @@ public static class ComparableExtensions public static T Min(this T value, T other) where T : IComparable { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.LessThan(other) ? value : other; } diff --git a/X10D/src/Net/EndPointExtensions.cs b/X10D/src/Net/EndPointExtensions.cs index 4bbfacd..da4147f 100644 --- a/X10D/src/Net/EndPointExtensions.cs +++ b/X10D/src/Net/EndPointExtensions.cs @@ -26,14 +26,10 @@ public static class EndPointExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string GetHost(this EndPoint endPoint) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(endPoint); -#else if (endPoint is null) { throw new ArgumentNullException(nameof(endPoint)); } -#endif return endPoint switch { @@ -59,14 +55,10 @@ public static class EndPointExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static int GetPort(this EndPoint endPoint) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(endPoint); -#else if (endPoint is null) { throw new ArgumentNullException(nameof(endPoint)); } -#endif return endPoint switch { diff --git a/X10D/src/Net/IPAddressExtensions.cs b/X10D/src/Net/IPAddressExtensions.cs index bd79612..6c6dc43 100644 --- a/X10D/src/Net/IPAddressExtensions.cs +++ b/X10D/src/Net/IPAddressExtensions.cs @@ -23,14 +23,10 @@ public static class IPAddressExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsIPv4(this IPAddress address) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(address); -#else if (address is null) { throw new ArgumentNullException(nameof(address)); } -#endif return address.AddressFamily == AddressFamily.InterNetwork; } @@ -47,14 +43,10 @@ public static class IPAddressExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsIPv6(this IPAddress address) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(address); -#else if (address is null) { throw new ArgumentNullException(nameof(address)); } -#endif return address.AddressFamily == AddressFamily.InterNetworkV6; } diff --git a/X10D/src/Numerics/RandomExtensions.cs b/X10D/src/Numerics/RandomExtensions.cs index 5a89e94..ea2a19c 100644 --- a/X10D/src/Numerics/RandomExtensions.cs +++ b/X10D/src/Numerics/RandomExtensions.cs @@ -21,14 +21,10 @@ public static class RandomExtensions /// is . public static Quaternion NextRotation(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif int seed = random.Next(); var seededRandom = new Random(seed); @@ -48,14 +44,10 @@ public static class RandomExtensions /// is . public static Quaternion NextRotationUniform(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif int seed = random.Next(); var seededRandom = new Random(seed); @@ -84,14 +76,10 @@ public static class RandomExtensions /// public static Vector2 NextUnitVector2(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif // no need to construct a seeded random here, since we only call Next once @@ -112,14 +100,10 @@ public static class RandomExtensions /// public static Vector3 NextUnitVector3(this Random random) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(random); -#else if (random is null) { throw new ArgumentNullException(nameof(random)); } -#endif int seed = random.Next(); var seededRandom = new Random(seed); diff --git a/X10D/src/Reactive/ObservableDisposer.cs b/X10D/src/Reactive/ObservableDisposer.cs index 9073ff9..b935112 100644 --- a/X10D/src/Reactive/ObservableDisposer.cs +++ b/X10D/src/Reactive/ObservableDisposer.cs @@ -17,23 +17,8 @@ internal readonly struct ObservableDisposer : IDisposable /// The additional action to run on dispose. public ObservableDisposer(HashSet> observers, IObserver observer, Action? additionalAction) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(observers); - ArgumentNullException.ThrowIfNull(observer); -#else - if (observers is null) - { - throw new ArgumentNullException(nameof(observers)); - } - - if (observer is null) - { - throw new ArgumentNullException(nameof(observer)); - } -#endif - - _observers = observers; - _observer = observer; + _observers = observers ?? throw new ArgumentNullException(nameof(observers)); + _observer = observer ?? throw new ArgumentNullException(nameof(observer)); _additionalAction = additionalAction; } diff --git a/X10D/src/Reactive/ProgressExtensions.cs b/X10D/src/Reactive/ProgressExtensions.cs index 6128a72..2eecdd8 100644 --- a/X10D/src/Reactive/ProgressExtensions.cs +++ b/X10D/src/Reactive/ProgressExtensions.cs @@ -18,14 +18,10 @@ public static class ProgressExtensions /// is . public static IObservable OnProgressChanged(this Progress progress) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(progress); -#else if (progress is null) { throw new ArgumentNullException(nameof(progress)); } -#endif var progressObservable = new ProgressObservable(); @@ -59,14 +55,10 @@ public static class ProgressExtensions /// is . public static IObservable OnProgressChanged(this Progress progress, T completeValue) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(progress); -#else if (progress is null) { throw new ArgumentNullException(nameof(progress)); } -#endif var progressObservable = new ProgressObservable(); var comparer = EqualityComparer.Default; diff --git a/X10D/src/Reactive/ProgressObservable.cs b/X10D/src/Reactive/ProgressObservable.cs index 29a8243..32a0870 100644 --- a/X10D/src/Reactive/ProgressObservable.cs +++ b/X10D/src/Reactive/ProgressObservable.cs @@ -25,14 +25,10 @@ internal sealed class ProgressObservable : IObservable /// An object which can be disposed to unsubscribe from progress tracking. public IDisposable Subscribe(IObserver observer) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(observer); -#else if (observer is null) { throw new ArgumentNullException(nameof(observer)); } -#endif _observers.Add(observer); return new ObservableDisposer(_observers, observer, OnDispose); diff --git a/X10D/src/Reflection/MemberInfoExtensions.cs b/X10D/src/Reflection/MemberInfoExtensions.cs index afe4722..362fdd9 100644 --- a/X10D/src/Reflection/MemberInfoExtensions.cs +++ b/X10D/src/Reflection/MemberInfoExtensions.cs @@ -26,14 +26,11 @@ public static class MemberInfoExtensions public static bool HasCustomAttribute(this MemberInfo member) where T : Attribute { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(member); -#else if (member is null) { throw new ArgumentNullException(nameof(member)); } -#endif + return Attribute.IsDefined(member, typeof(T)); } @@ -51,10 +48,6 @@ public static class MemberInfoExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool HasCustomAttribute(this MemberInfo member, Type attribute) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(member); - ArgumentNullException.ThrowIfNull(attribute); -#else if (member is null) { throw new ArgumentNullException(nameof(member)); @@ -64,7 +57,6 @@ public static class MemberInfoExtensions { throw new ArgumentNullException(nameof(attribute)); } -#endif if (!attribute.Inherits()) { @@ -94,10 +86,6 @@ public static class MemberInfoExtensions Func selector) where TAttribute : Attribute { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(member); - ArgumentNullException.ThrowIfNull(selector); -#else if (member is null) { throw new ArgumentNullException(nameof(member)); @@ -107,7 +95,6 @@ public static class MemberInfoExtensions { throw new ArgumentNullException(nameof(selector)); } -#endif return member.SelectFromCustomAttribute(selector, default); } @@ -132,10 +119,6 @@ public static class MemberInfoExtensions Func selector, TReturn? defaultValue) where TAttribute : Attribute { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(member); - ArgumentNullException.ThrowIfNull(selector); -#else if (member is null) { throw new ArgumentNullException(nameof(member)); @@ -145,7 +128,6 @@ public static class MemberInfoExtensions { throw new ArgumentNullException(nameof(selector)); } -#endif return member.GetCustomAttribute() is { } attribute ? selector(attribute) diff --git a/X10D/src/Reflection/TypeExtensions.cs b/X10D/src/Reflection/TypeExtensions.cs index b336b06..32b4d75 100644 --- a/X10D/src/Reflection/TypeExtensions.cs +++ b/X10D/src/Reflection/TypeExtensions.cs @@ -21,14 +21,10 @@ public static class TypeExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool Implements(this Type value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.Implements(typeof(T)); } @@ -48,10 +44,6 @@ public static class TypeExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool Implements(this Type value, Type interfaceType) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); - ArgumentNullException.ThrowIfNull(interfaceType); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); @@ -61,7 +53,6 @@ public static class TypeExtensions { throw new ArgumentNullException(nameof(interfaceType)); } -#endif if (!interfaceType.IsInterface) { @@ -90,14 +81,10 @@ public static class TypeExtensions public static bool Inherits(this Type value) where T : class { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.Inherits(typeof(T)); } @@ -125,10 +112,6 @@ public static class TypeExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool Inherits(this Type value, Type type) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); - ArgumentNullException.ThrowIfNull(type); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); @@ -138,7 +121,6 @@ public static class TypeExtensions { throw new ArgumentNullException(nameof(type)); } -#endif if (!value.IsClass) { diff --git a/X10D/src/Text/EnumerableExtensions.cs b/X10D/src/Text/EnumerableExtensions.cs index c5552b3..e243ef0 100644 --- a/X10D/src/Text/EnumerableExtensions.cs +++ b/X10D/src/Text/EnumerableExtensions.cs @@ -18,10 +18,6 @@ public static class EnumerableExtensions /// public static IEnumerable Grep(this IEnumerable source, string pattern) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(pattern); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -31,7 +27,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(pattern)); } -#endif return Grep(source, pattern, false); } @@ -50,10 +45,6 @@ public static class EnumerableExtensions /// public static IEnumerable Grep(this IEnumerable source, string pattern, bool ignoreCase) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); - ArgumentNullException.ThrowIfNull(pattern); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); @@ -63,7 +54,6 @@ public static class EnumerableExtensions { throw new ArgumentNullException(nameof(pattern)); } -#endif #if NET6_0_OR_GREATER if (source.TryGetNonEnumeratedCount(out int count) && count == 0) diff --git a/X10D/src/Text/StringBuilderReader.cs b/X10D/src/Text/StringBuilderReader.cs index 337a22c..fe6e969 100644 --- a/X10D/src/Text/StringBuilderReader.cs +++ b/X10D/src/Text/StringBuilderReader.cs @@ -55,14 +55,10 @@ public class StringBuilderReader : TextReader /// public override int Read(char[] buffer, int index, int count) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(buffer); -#else if (buffer is null) { throw new ArgumentNullException(nameof(buffer)); } -#endif if (index < 0) { diff --git a/X10D/src/Text/StringExtensions.cs b/X10D/src/Text/StringExtensions.cs index 052b4c5..44db6bd 100644 --- a/X10D/src/Text/StringExtensions.cs +++ b/X10D/src/Text/StringExtensions.cs @@ -60,14 +60,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string Base64Decode(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return Convert.FromBase64String(value).ToString(Encoding.ASCII); } @@ -82,14 +78,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string Base64Encode(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return Convert.ToBase64String(value.GetBytes(Encoding.ASCII)); } @@ -115,11 +107,6 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string ChangeEncoding(this string value, Encoding sourceEncoding, Encoding destinationEncoding) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); - ArgumentNullException.ThrowIfNull(sourceEncoding); - ArgumentNullException.ThrowIfNull(destinationEncoding); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); @@ -134,7 +121,6 @@ public static class StringExtensions { throw new ArgumentNullException(nameof(destinationEncoding)); } -#endif return value.GetBytes(sourceEncoding).ToString(destinationEncoding); } @@ -179,14 +165,10 @@ public static class StringExtensions /// An integer representing the count of inside . public static int CountSubstring(this string haystack, char needle) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(haystack); -#else if (haystack is null) { throw new ArgumentNullException(nameof(haystack)); } -#endif return haystack.AsSpan().CountSubstring(needle); } @@ -211,14 +193,10 @@ public static class StringExtensions /// An integer representing the count of inside . public static int CountSubstring(this string haystack, string? needle, StringComparison comparison) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(haystack); -#else if (haystack is null) { throw new ArgumentNullException(nameof(haystack)); } -#endif if (string.IsNullOrWhiteSpace(needle)) { @@ -374,14 +352,10 @@ public static class StringExtensions public static T EnumParse(this string value, bool ignoreCase) where T : struct, Enum { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif value = value.Trim(); @@ -437,10 +411,6 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static byte[] GetBytes(this string value, Encoding encoding) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); - ArgumentNullException.ThrowIfNull(encoding); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); @@ -450,7 +420,6 @@ public static class StringExtensions { throw new ArgumentNullException(nameof(encoding)); } -#endif return encoding.GetBytes(value); } @@ -464,14 +433,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsEmoji(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return EmojiRegex.Value.IsMatch(value); } @@ -488,14 +453,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsEmpty(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif return value.Length == 0; } @@ -512,14 +473,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsLower(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif for (var index = 0; index < value.Length; index++) { @@ -599,14 +556,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsPalindrome(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif if (string.IsNullOrWhiteSpace(value)) { @@ -673,14 +626,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsUpper(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif for (var index = 0; index < value.Length; index++) { @@ -728,14 +677,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsWhiteSpace(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif if (value.Length == 0) { @@ -765,14 +710,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string Repeat(this string value, int count) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif switch (count) { @@ -810,14 +751,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string Randomize(this string source, int length, Random? random = null) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(source); -#else if (source is null) { throw new ArgumentNullException(nameof(source)); } -#endif if (length < 0) { @@ -852,14 +789,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string Reverse(this string value) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif if (value.Length < 2) { @@ -890,14 +823,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static string Shuffled(this string value, Random? random = null) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif random ??= RandomExtensions.GetShared(); @@ -920,14 +849,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static IEnumerable Split(this string value, int chunkSize) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(value); -#else if (value is null) { throw new ArgumentNullException(nameof(value)); } -#endif if (chunkSize == 0) { @@ -956,14 +881,10 @@ public static class StringExtensions /// public static bool StartsWithAny(this string? value, params string[] startValues) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(startValues); -#else if (startValues is null) { throw new ArgumentNullException(nameof(startValues)); } -#endif if (startValues.Length == 0 || string.IsNullOrWhiteSpace(value)) { @@ -989,14 +910,10 @@ public static class StringExtensions /// public static bool StartsWithAny(this string? value, StringComparison comparison, params string[] startValues) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(startValues); -#else if (startValues is null) { throw new ArgumentNullException(nameof(startValues)); } -#endif if (startValues.Length == 0 || string.IsNullOrWhiteSpace(value)) { diff --git a/X10D/src/Time/StringExtensions.cs b/X10D/src/Time/StringExtensions.cs index 4ebc4b0..668f26d 100644 --- a/X10D/src/Time/StringExtensions.cs +++ b/X10D/src/Time/StringExtensions.cs @@ -61,14 +61,10 @@ public static class StringExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static TimeSpan ToTimeSpan(this string input) { -#if NET6_0_OR_GREATER - ArgumentNullException.ThrowIfNull(input); -#else if (input is null) { throw new ArgumentNullException(nameof(input)); } -#endif return TimeSpanParser.TryParse(input, out TimeSpan result) ? result