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 2734af986..820ced0ee 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 async Task NormalizeClientAsync(this DiscordChanne { 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 f3d8964d4..5dfd41573 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 void AutoJoinThreads(this DiscordClient client, bool rejoinIfRemov /// 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 4a23a34ff..1c2c479c9 100644 --- a/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs +++ b/X10D.DSharpPlus/src/DiscordEmbedBuilderExtensions.cs @@ -23,14 +23,10 @@ public static DiscordEmbedBuilder AddField( 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 DiscordEmbedBuilder AddFieldIf( 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 DiscordEmbedBuilder AddFieldIf( 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 DiscordEmbedBuilder AddFieldIf( { throw new ArgumentNullException(nameof(predicate)); } -#endif if (predicate.Invoke()) { @@ -139,11 +126,6 @@ public static DiscordEmbedBuilder AddFieldIf( 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 DiscordEmbedBuilder AddFieldIf( { throw new ArgumentNullException(nameof(valueFactory)); } -#endif if (predicate.Invoke()) { @@ -190,19 +171,15 @@ public static DiscordEmbedBuilder AddFieldIf( 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 DiscordEmbedBuilder AddFieldIf( /// 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 c03016bc3..ff4636e33 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 async Task JoinAllThreadsAsync(this DiscordGuild guild) /// 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 async Task JoinAllThreadsAsync(this DiscordGuild guild) /// 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 async Task NormalizeClientAsync(this DiscordGuild gu { 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 3fd202048..7ec99256b 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 bool HasRole(this DiscordMember member, DiscordRole role) { throw new ArgumentNullException(nameof(role)); } -#endif return member.Roles.Contains(role); } @@ -52,10 +47,6 @@ public static bool HasRole(this DiscordMember member, DiscordRole role) /// 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 async Task NormalizeClientAsync(this DiscordMember { 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 f8317c71f..f43116d4c 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 async Task DeleteAfterAsync(this DiscordMessage message, TimeSpan /// 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 async Task DeleteAfterAsync(this Task task, TimeSp /// 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 async Task NormalizeClientAsync(this DiscordMessag { 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 6ab831458..adfd477d3 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 string GetUsernameWithDiscriminator(this DiscordUser user) /// 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 async Task IsInGuildAsync(this DiscordUser user, DiscordGuil { throw new ArgumentNullException(nameof(guild)); } -#endif if (guild.Members.TryGetValue(user.Id, out _)) { @@ -138,10 +124,6 @@ public static async Task IsInGuildAsync(this DiscordUser user, DiscordGuil /// 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 async Task NormalizeClientAsync(this DiscordUser user { 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 c6ed75bbe..7dd5863e4 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 void Clear(this T?[] array) /// 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 void Clear(this T?[] array, Range range) /// 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 347d19bb8..6258617fd 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 byte PackByte(this IReadOnlyList source) [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 short PackInt16(this IReadOnlyList source) [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 int PackInt32(this IReadOnlyList source) [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 355458666..e9b2c6ed1 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 void ClearAndDisposeAll(this ICollection source) where T : I /// 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 66823b011..241efe920 100644 --- a/X10D/src/Collections/DictionaryExtensions.cs +++ b/X10D/src/Collections/DictionaryExtensions.cs @@ -37,10 +37,6 @@ public static TValue AddOrUpdate(this Dictionary dic 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 TValue AddOrUpdate(this Dictionary dic { 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 TValue AddOrUpdate(this IDictionary di 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 TValue AddOrUpdate(this IDictionary di { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif if (dictionary.TryGetValue(key, out TValue? old)) { @@ -152,11 +142,6 @@ public static TValue AddOrUpdate(this Dictionary dic 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 TValue AddOrUpdate(this Dictionary dic { 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 TValue AddOrUpdate(this IDictionary di 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 TValue AddOrUpdate(this IDictionary di { throw new ArgumentNullException(nameof(updateValueFactory)); } -#endif if (dictionary.TryGetValue(key, out TValue? old)) { @@ -291,11 +269,6 @@ public static TValue AddOrUpdate(this Dictionary 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 TValue AddOrUpdate(this Dictionary(this IDictionary 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 TValue AddOrUpdate(this IDictionary(this IDictionary(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 @@ static string GetQueryParameter(KeyValuePair pair) 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 string ToConnectionString(this IEnumerable(this IEnumerable 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 string ToConnectionString(this IEnumerable pair) 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 string ToGetParameters(this IEnumerable 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 string ToGetParameters(this IEnumerable pair) @@ -661,11 +603,6 @@ public static string ToGetParameters(this IEnumerable 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 string ToGetParameters(this IEnumerable pair) diff --git a/X10D/src/Collections/EnumerableExtensions.cs b/X10D/src/Collections/EnumerableExtensions.cs index c38e4dff2..a183c2b89 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 int CountWhereNot(this IEnumerable source, Func< { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.Count(item => !predicate(item)); } @@ -58,10 +53,6 @@ public static int CountWhereNot(this IEnumerable source, Func< [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 TSource FirstWhereNot(this IEnumerable source, F { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.First(item => !predicate(item)); } @@ -91,10 +81,6 @@ public static TSource FirstWhereNot(this IEnumerable source, F [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 TSource FirstWhereNot(this IEnumerable source, F { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.FirstOrDefault(item => !predicate(item)); } @@ -127,10 +112,6 @@ public static TSource FirstWhereNot(this IEnumerable source, F /// 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 void For(this IEnumerable source, Action action) { throw new ArgumentNullException(nameof(action)); } -#endif var index = 0; foreach (T item in source) @@ -166,10 +146,6 @@ public static void For(this IEnumerable source, Action action) /// 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 void ForEach(this IEnumerable source, Action action) { throw new ArgumentNullException(nameof(action)); } -#endif foreach (T item in source) { @@ -196,14 +171,10 @@ public static void ForEach(this IEnumerable source, Action action) /// 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 void DisposeAll(this IEnumerable source) where T : IDisposab /// 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 async Task DisposeAllAsync(this IEnumerable source) where T [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 TSource LastWhereNot(this IEnumerable source, Fu { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.Last(item => !predicate(item)); } @@ -297,10 +259,6 @@ public static TSource LastWhereNot(this IEnumerable source, Fu [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 TSource LastWhereNot(this IEnumerable source, Fu { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.LastOrDefault(item => !predicate(item)); } @@ -326,14 +283,10 @@ public static TSource LastWhereNot(this IEnumerable source, Fu [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 IReadOnlyCollection Shuffled(this IEnumerable source, Ran [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 IEnumerable WhereNot(this IEnumerable s { throw new ArgumentNullException(nameof(predicate)); } -#endif return source.Where(item => !predicate(item)); } @@ -386,14 +334,10 @@ public static IEnumerable WhereNot(this IEnumerable s /// 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 69292b4fb..be53ee814 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 void Fill(this IList source, T value) /// 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 void Fill(this IList source, T value, int startIndex, int co /// 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 int IndexOf(this IReadOnlyList source, T? item) /// 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 int IndexOf(this IReadOnlyList source, T? item, int startIn /// 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 int IndexOf(this IReadOnlyList source, T? item, int startIn [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 T Random(this IReadOnlyList source, Random? random = null) /// 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 void RemoveRange(this IList source, Range range) /// 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 void Shuffle(this IList source, Random? random = null) /// 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 IReadOnlyList Slice(this IReadOnlyList source, int start) /// 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 IReadOnlyList Slice(this IReadOnlyList source, int start, /// 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 void Swap(this IList source, IList other) { 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 32acc3b2e..49e8634af 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 T Next(this Random random) /// 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 bool NextBoolean(this Random random) /// 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 double NextDouble(this Random random, double maxValue) /// 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 double NextDouble(this Random random, double minValue, double maxV /// 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 T NextFrom(this Random random, IEnumerable source) { throw new ArgumentNullException(nameof(source)); } -#endif if (source is T[] array) { @@ -206,14 +185,10 @@ public static T NextFrom(this Random random, IEnumerable source) /// 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 T NextFrom(this Random random, Span source) /// 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 T NextFrom(this Random random, ReadOnlySpan source) /// 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 byte NextByte(this Random random) /// 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 byte NextByte(this Random random, byte maxValue) /// 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 byte NextByte(this Random random, byte minValue, byte maxValue) /// 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 short NextInt16(this Random random) /// 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 short NextInt16(this Random random, short maxValue) /// 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 float NextSingle(this Random random) /// 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 float NextSingle(this Random random, float maxValue) /// 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 float NextSingle(this Random random, float minValue, float maxValu /// 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 string NextString(this Random random, IReadOnlyList source, { throw new ArgumentNullException(nameof(source)); } -#endif if (length < 0) { diff --git a/X10D/src/Drawing/Polygon.cs b/X10D/src/Drawing/Polygon.cs index 63abae8b3..9f03b588b 100644 --- a/X10D/src/Drawing/Polygon.cs +++ b/X10D/src/Drawing/Polygon.cs @@ -22,14 +22,10 @@ public Polygon() /// 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 Polygon(Polygon polygon) /// 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 IReadOnlyList Vertices /// 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 void AddVertex(Point vertex) /// 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 51d9eebe9..074edc31e 100644 --- a/X10D/src/Drawing/PolygonF.cs +++ b/X10D/src/Drawing/PolygonF.cs @@ -25,14 +25,10 @@ public 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 PolygonF(PolygonF polygon) /// 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 PolygonF(IEnumerable vertices) /// 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 IReadOnlyList Vertices /// 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 void AddVertex(Vector2 vertex) /// 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 void AddVertices(IEnumerable vertices) /// 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 2f46ca01b..6be327ee6 100644 --- a/X10D/src/Drawing/Polyhedron.cs +++ b/X10D/src/Drawing/Polyhedron.cs @@ -34,14 +34,10 @@ public Polyhedron(Polyhedron polyhedron) /// 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 IReadOnlyList Vertices /// 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 static Polyhedron FromPolygon(Polygon polygon) /// 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 void AddVertex(Vector3 vertex) /// 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 24c7419af..880cd84d8 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 Color NextColorRgb(this Random random) /// 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 5eb0a921b..c6c7e8143 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 a0878bccb..e1a4e6900 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 byte[] GetHash(this FileInfo value) 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 3289fef10..5d9122f1c 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 double ToDouble(this IReadOnlyList source) /// 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 short ToInt16(this IReadOnlyList source) /// 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 int ToInt32(this IReadOnlyList source) /// 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 long ToInt64(this IReadOnlyList source) /// 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 float ToSingle(this IReadOnlyList source) /// 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 float ToSingle(this IReadOnlyList source, int startIndex) /// 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 string ToString(this IReadOnlyList source, Encoding encoding { throw new ArgumentNullException(nameof(encoding)); } -#endif return encoding.GetString(source.ToArray()); } @@ -248,14 +219,10 @@ public static ushort ToUInt16(this IReadOnlyList source) [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 uint ToUInt32(this IReadOnlyList source) [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 ulong ToUInt64(this IReadOnlyList source) [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 c55b784b9..d1d44dbf7 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 decimal ReadDecimal(this Stream stream) /// 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 double ReadDouble(this Stream stream) /// 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 short ReadInt16(this Stream stream) /// 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 int ReadInt32(this Stream stream) /// 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 long ReadInt64(this Stream stream) /// 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 double ReadSingle(this Stream stream) /// 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 ushort ReadUInt16(this Stream stream) [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 uint ReadUInt32(this Stream stream) [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 ulong ReadUInt64(this Stream stream) [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 ulong ReadUInt64(this Stream stream, Endianness endianness) 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 int Write(this Stream stream, short value) /// 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 int Write(this Stream stream, int value) /// 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 int Write(this Stream stream, long value) /// 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 int Write(this Stream stream, ushort value) [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 int Write(this Stream stream, uint value) [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 int Write(this Stream stream, ulong value) [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 int Write(this Stream stream, ulong value, Endianness endianness) /// 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 int Write(this Stream stream, float value, Endianness endianness) /// 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 int Write(this Stream stream, double value, Endianness endianness) [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 4ecb21304..b8bef35aa 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 IEnumerable EnumerateLines(this TextReader reader) /// 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 1a63f42dc..13178466c 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 void WriteLineNoAlloc(this TextWriter writer, double value) /// 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 void WriteLineNoAlloc(this TextWriter writer, double value, ReadOn 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 8836d639f..9640a6aed 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 void WriteLineNoAlloc(this TextWriter writer, int value) /// 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 void WriteLineNoAlloc(this TextWriter writer, int value, ReadOnlyS 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 83deaddd9..8ca58556b 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 void WriteLineNoAlloc(this TextWriter writer, long value) /// 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 void WriteLineNoAlloc(this TextWriter writer, 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 bb6d2e071..9194c620b 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 void WriteLineNoAlloc(this TextWriter writer, float value) /// 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 void WriteLineNoAlloc(this TextWriter writer, float value, ReadOnl 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 98e9d421c..b812afb31 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 void WriteLineNoAlloc(this TextWriter writer, uint value) [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 void WriteLineNoAlloc(this TextWriter writer, 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 68f397f9b..7b55571a1 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 void WriteLineNoAlloc(this TextWriter writer, ulong value) [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 void WriteLineNoAlloc(this TextWriter writer, 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 6b6de186c..a8d5bbb7c 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 void WriteNoAlloc(this TextWriter writer, double value) /// 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 void WriteNoAlloc(this TextWriter writer, double value, ReadOnlySp 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 c2366bf1e..201836349 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 void WriteNoAlloc(this TextWriter writer, int value) /// 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 void WriteNoAlloc(this TextWriter writer, int value, ReadOnlySpan< /// 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 049d8911d..c0cb32f74 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 void WriteNoAlloc(this TextWriter writer, long value) /// 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 void WriteNoAlloc(this TextWriter writer, 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 f59559376..b48a41592 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 void WriteNoAlloc(this TextWriter writer, float value) /// 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 void WriteNoAlloc(this TextWriter writer, float value, ReadOnlySpa 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 f8d32a210..b38fa0ac0 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 void WriteNoAlloc(this TextWriter writer, uint value) [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 void WriteNoAlloc(this TextWriter writer, 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 5e266e484..d9a48f4f9 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 void WriteNoAlloc(this TextWriter writer, ulong value) [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 void WriteNoAlloc(this TextWriter writer, 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 3d7524dfb..64d1c01d0 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 byte Product(this IEnumerable source) [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 sbyte Product(this IEnumerable source) /// 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 byte Product(this IEnumerable source, Func(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 01dde51b3..c5e1bc7f1 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 decimal Product(this IEnumerable source) /// 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 afb38aefb..23628afd9 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 double Product(this IEnumerable source) /// 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 92592bf33..05004c9fd 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 IEnumerable ConcatOne(this IEnumerable /// 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 IEnumerable Except(this IEnumerable sou /// 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 (T? Minimum, T? Maximum) MinMax(this IEnumerable source) /// 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 (T? Minimum, T? Maximum) MinMax(this IEnumerable source, ICo 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 (TResult? Minimum, TResult? Maximum) MinMax(this { throw new ArgumentNullException(nameof(selector)); } -#endif return MinMax(source, selector, Comparer.Default); } @@ -194,10 +173,6 @@ public static (TResult? Minimum, TResult? Maximum) MinMax(this 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 (TResult? Minimum, TResult? Maximum) MinMax(this { throw new ArgumentNullException(nameof(selector)); } -#endif comparer ??= Comparer.Default; @@ -263,10 +237,6 @@ public static (TResult? Minimum, TResult? Maximum) MinMax(this 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 (TSource? Minimum, TSource? Maximum) MinMaxBy(th { throw new ArgumentNullException(nameof(keySelector)); } -#endif return MinMaxBy(source, keySelector, Comparer.Default); } @@ -296,10 +265,6 @@ public static (TSource? Minimum, TSource? Maximum) MinMaxBy(th 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 (TSource? Minimum, TSource? Maximum) MinMaxBy(th { 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 871e42256..876f37325 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 int Product(this IEnumerable source) [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 uint Product(this IEnumerable source) /// 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 int Product(this IEnumerable source, Func(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 07b980275..00061d4a6 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 long Product(this IEnumerable source) [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 ulong Product(this IEnumerable source) /// 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 long Product(this IEnumerable source, Func(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 bf0d1d3d9..9d20ff8c5 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 bool All(this ReadOnlySpan source, Predicate(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 bool Any(this ReadOnlySpan source, Predicate 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 9d4820336..e80ed9b47 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 float Product(this IEnumerable source) /// 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 ce2e3f32b..9b84308b5 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 bool All(this Span source, Predicate pr [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 bool Any(this Span source, Predicate pr /// 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 e1af91fa1..9aea7fc8f 100644 --- a/X10D/src/Math/ComparableExtensions.cs +++ b/X10D/src/Math/ComparableExtensions.cs @@ -56,14 +56,10 @@ public static bool Between(this T1 value, T2 lower, T3 upper, 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 bool Between(this T1 value, T2 lower, T3 upper, 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 T Clamp(this T value, T lower, T upper) 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 bool GreaterThan(this T1 value, T2 other) 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 bool GreaterThanOrEqualTo(this T1 value, T2 other) 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 bool LessThan(this T1 value, T2 other) 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 bool LessThanOrEqualTo(this T1 value, T2 other) 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 T Max(this T value, T other) 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 4bbfacd55..da4147f87 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 string GetHost(this EndPoint endPoint) [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 bd7961239..6c6dc43f0 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 bool IsIPv4(this IPAddress address) [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 5a89e9433..ea2a19c10 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 Quaternion NextRotation(this Random random) /// 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 Quaternion NextRotationUniform(this Random random) /// 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 Vector2 NextUnitVector2(this Random random) /// 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 9073ff961..b9351122d 100644 --- a/X10D/src/Reactive/ObservableDisposer.cs +++ b/X10D/src/Reactive/ObservableDisposer.cs @@ -17,23 +17,8 @@ namespace X10D.Reactive; /// 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 6128a72e8..2eecdd8dc 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 @@ void ProgressChangedHandler(object? sender, T args) /// 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 29a8243c0..32a08707a 100644 --- a/X10D/src/Reactive/ProgressObservable.cs +++ b/X10D/src/Reactive/ProgressObservable.cs @@ -25,14 +25,10 @@ public IObserver[] Observers /// 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 afe472271..362fdd9d5 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 bool HasCustomAttribute(this MemberInfo member) [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 bool HasCustomAttribute(this MemberInfo member, Type attribute) { throw new ArgumentNullException(nameof(attribute)); } -#endif if (!attribute.Inherits()) { @@ -94,10 +86,6 @@ public static bool HasCustomAttribute(this MemberInfo member, Type attribute) 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 bool HasCustomAttribute(this MemberInfo member, Type attribute) { throw new ArgumentNullException(nameof(selector)); } -#endif return member.SelectFromCustomAttribute(selector, default); } @@ -132,10 +119,6 @@ public static bool HasCustomAttribute(this MemberInfo member, Type attribute) 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 bool HasCustomAttribute(this MemberInfo member, Type attribute) { 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 b336b060d..32b4d75f1 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 bool Implements(this Type value) [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 bool Implements(this Type value, Type interfaceType) { throw new ArgumentNullException(nameof(interfaceType)); } -#endif if (!interfaceType.IsInterface) { @@ -90,14 +81,10 @@ public static bool Implements(this Type value, Type interfaceType) 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 bool Inherits(this Type value) [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 bool Inherits(this Type value, Type type) { throw new ArgumentNullException(nameof(type)); } -#endif if (!value.IsClass) { diff --git a/X10D/src/Text/EnumerableExtensions.cs b/X10D/src/Text/EnumerableExtensions.cs index c5552b388..e243ef09b 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 IEnumerable Grep(this IEnumerable source, string p { throw new ArgumentNullException(nameof(pattern)); } -#endif return Grep(source, pattern, false); } @@ -50,10 +45,6 @@ public static IEnumerable Grep(this IEnumerable source, string p /// 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 IEnumerable Grep(this IEnumerable source, string p { 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 337a22c80..fe6e96958 100644 --- a/X10D/src/Text/StringBuilderReader.cs +++ b/X10D/src/Text/StringBuilderReader.cs @@ -55,14 +55,10 @@ public override int Read() /// 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 052b4c50d..44db6bd35 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 string Base64Decode(this string value) [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 string Base64Encode(this string value) [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 string ChangeEncoding(this string value, Encoding sourceEncoding, { throw new ArgumentNullException(nameof(destinationEncoding)); } -#endif return value.GetBytes(sourceEncoding).ToString(destinationEncoding); } @@ -179,14 +165,10 @@ public static int CountSubstring(this ReadOnlySpan haystack, char needle) /// 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 int CountSubstring(this string haystack, string? needle) /// 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 T EnumParse(this string value) 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 byte[] GetBytes(this string value) [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 byte[] GetBytes(this string value, Encoding encoding) { throw new ArgumentNullException(nameof(encoding)); } -#endif return encoding.GetBytes(value); } @@ -464,14 +433,10 @@ public static byte[] GetBytes(this string value, Encoding encoding) [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 bool IsEmoji(this string value) [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 bool IsEmpty(this string value) [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 bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value) [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 bool IsPalindrome(this string value) [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 bool IsUpper(this string value) [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 bool IsWhiteSpace(this string value) [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 string Repeat(this string value, int count) [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 string Randomize(this string source, int length, Random? random = [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 string Reverse(this string value) [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 string Shuffled(this string value, Random? random = null) [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 IEnumerable Split(this string value, int chunkSize) /// 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 bool StartsWithAny(this string? value, params string[] startValues /// 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 4ebc4b09c..668f26df3 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