diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 7281cb2..6d4f91e 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -33,6 +33,7 @@ jobs: run: | mkdir build dotnet pack X10D -p:SymbolPackageFormat=snupkg --include-symbols --include-source -o build -p:VersionSuffix='nightly' -p:BuildNumber=${{ github.run_number }} + dotnet pack X10D.Unity -p:SymbolPackageFormat=snupkg --include-symbols --include-source -o build -p:VersionSuffix='prerelease' -p:BuildNumber=${{ github.run_number }} - name: Push NuGet Package to GitHub run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 1f2cb8d..c400d74 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -32,6 +32,7 @@ jobs: run: | mkdir build dotnet pack X10D -p:SymbolPackageFormat=snupkg --include-symbols --include-source -o build -p:VersionSuffix='prerelease' -p:BuildNumber=${{ github.run_number }} + dotnet pack X10D.Unity -p:SymbolPackageFormat=snupkg --include-symbols --include-source -o build -p:VersionSuffix='prerelease' -p:BuildNumber=${{ github.run_number }} - name: Push NuGet Package to GitHub run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 85ed581..438abed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,6 +32,7 @@ jobs: run: | mkdir build dotnet pack X10D -p:SymbolPackageFormat=snupkg --include-symbols --include-source -o build + dotnet pack X10D.Unity -p:SymbolPackageFormat=snupkg --include-symbols --include-source -o build - name: Push NuGet Package to GitHub run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate diff --git a/.github/workflows/source_validator.yml b/.github/workflows/source_validator.yml index a286122..c664fdd 100644 --- a/.github/workflows/source_validator.yml +++ b/.github/workflows/source_validator.yml @@ -32,5 +32,4 @@ jobs: run: dotnet build -c Debug - name: Run Source Validation - run: dotnet run --project X10D.SourceValidator ./X10D/src - + run: dotnet run --project X10D.SourceValidator ./X10D/src ./X10D.Unity/src diff --git a/X10D.SourceValidator/Program.cs b/X10D.SourceValidator/Program.cs index 2f09427..2667598 100644 --- a/X10D.SourceValidator/Program.cs +++ b/X10D.SourceValidator/Program.cs @@ -1,64 +1,68 @@ using System.Text; -var directories = new Stack(Directory.GetDirectories(args[0])); var problems = 0; -var files = 0; - -while (directories.Count > 0) +foreach (string arg in args) { - string path = Path.GetFullPath(directories.Pop()); + var directories = new Stack(Directory.GetDirectories(arg)); + var files = 0; - foreach (string directory in Directory.EnumerateDirectories(path)) + while (directories.Count > 0) { - directories.Push(directory); - } + string path = Path.GetFullPath(directories.Pop()); - foreach (string file in Directory.EnumerateFiles(path, "*.cs")) - { - files++; - await using var stream = File.OpenRead(file); - using var reader = new StreamReader(stream, Encoding.UTF8); - var blankLine = false; - - var lineNumber = 1; - while (await reader.ReadLineAsync() is { } line) + foreach (string directory in Directory.EnumerateDirectories(path)) { - if (string.IsNullOrWhiteSpace(line)) + directories.Push(directory); + } + + foreach (string file in Directory.EnumerateFiles(path, "*.cs")) + { + files++; + await using var stream = File.OpenRead(file); + using var reader = new StreamReader(stream, Encoding.UTF8); + var blankLine = false; + + var lineNumber = 1; + while (await reader.ReadLineAsync() is { } line) { - if (blankLine) + if (string.IsNullOrWhiteSpace(line)) + { + if (blankLine) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Out.WriteLine($"{file}({lineNumber}): Double blank line"); + Console.ResetColor(); + problems++; + } + + blankLine = true; + } + else + { + blankLine = false; + } + + if (line.Length > 130) { Console.ForegroundColor = ConsoleColor.Red; - Console.Out.WriteLine($"{file}({lineNumber}): Double blank line"); + Console.Out.WriteLine($"{file}({lineNumber}): Line is too long ({line.Length})"); + Console.ResetColor(); + problems++; + } + else if (line.Length > 0 && char.IsWhiteSpace(line[^1])) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Out.WriteLine($"{file}({lineNumber}): Line contains trailing whitespace"); Console.ResetColor(); problems++; } - blankLine = true; + lineNumber++; } - else - { - blankLine = false; - } - - if (line.Length > 130) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Out.WriteLine($"{file}({lineNumber}): Line is too long ({line.Length})"); - Console.ResetColor(); - problems++; - } - else if (line.Length > 0 && char.IsWhiteSpace(line[^1])) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Out.WriteLine($"{file}({lineNumber}): Line contains trailing whitespace"); - Console.ResetColor(); - problems++; - } - - lineNumber++; } } + + Console.Out.WriteLine($"Finished scanning {files} files, {problems} problems encountered."); } -Console.Out.WriteLine($"Finished scanning {files} files, {problems} problems encountered."); return problems; diff --git a/X10D.Unity/X10D.Unity.csproj b/X10D.Unity/X10D.Unity.csproj new file mode 100644 index 0000000..7110951 --- /dev/null +++ b/X10D.Unity/X10D.Unity.csproj @@ -0,0 +1,65 @@ + + + + netstandard2.1 + 10.0 + true + true + Oliver Booth + en + https://github.com/oliverbooth/X10D + git + Extension methods on crack. + LICENSE.md + icon.png + + dotnet extension-methods + true + 3.1.0 + enable + true + true + + + + $(VersionPrefix)-$(VersionSuffix) + $(VersionPrefix).0 + $(VersionPrefix).0 + + + + $(VersionPrefix)-$(VersionSuffix).$(BuildNumber) + $(VersionPrefix).$(BuildNumber) + $(VersionPrefix).$(BuildNumber) + + + + $(VersionPrefix) + $(VersionPrefix).0 + $(VersionPrefix).0 + + + + + + + + + + + + + True + + + + True + + + + True + + + + + diff --git a/X10D.Unity/src/Drawing/RandomExtensions.cs b/X10D.Unity/src/Drawing/RandomExtensions.cs new file mode 100644 index 0000000..2e90807 --- /dev/null +++ b/X10D.Unity/src/Drawing/RandomExtensions.cs @@ -0,0 +1,95 @@ +using UnityEngine; +using X10D.Core; +using Random = System.Random; + +namespace X10D.Unity.Drawing; + +/// +/// Extension methods for . +/// +public static class RandomExtensions +{ + /// + /// Returns an HDR color of random components for red, green, and blue. + /// + /// The instance. + /// A whose red, green, and blue components are all random, and whose alpha is 255 + /// is . + public static Color NextColorRgb(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + int seed = random.Next(); + var seededRandom = new Random(seed); + float r = seededRandom.NextSingle(); + float g = seededRandom.NextSingle(); + float b = seededRandom.NextSingle(); + return new Color(r, g, b, 1.0f); + } + + /// + /// Returns an HDR color composed of random components for apha, red, green, and blue. + /// + /// The instance. + /// A whose alpha, red, green, and blue components are all random. + /// is . + public static Color NextColorArgb(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + int seed = random.Next(); + var seededRandom = new Random(seed); + float a = seededRandom.NextSingle(); + float r = seededRandom.NextSingle(); + float g = seededRandom.NextSingle(); + float b = seededRandom.NextSingle(); + return new Color(r, g, b, a); + } + + /// + /// Returns a color of random components for red, green, and blue. + /// + /// The instance. + /// A whose red, green, and blue components are all random, and whose alpha is 255 + /// is . + public static Color32 NextColor32Rgb(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + int rgb = random.Next(); + var r = (byte)(rgb >> 16 & 0xFF); + var g = (byte)(rgb >> 8 & 0xFF); + var b = (byte)(rgb & 0xFF); + return new Color32(r, g, b, 0xFF); + } + + /// + /// Returns a color composed of random components for apha, red, green, and blue. + /// + /// The instance. + /// A whose alpha, red, green, and blue components are all random. + /// is . + public static Color32 NextColor32Argb(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + int argb = random.Next(); + var a = (byte)(argb >> 24 & 0xFF); + var r = (byte)(argb >> 16 & 0xFF); + var g = (byte)(argb >> 8 & 0xFF); + var b = (byte)(argb & 0xFF); + return new Color32(r, g, b, a); + } +} diff --git a/X10D.Unity/src/GameObjectExtensions.cs b/X10D.Unity/src/GameObjectExtensions.cs new file mode 100644 index 0000000..598d7a1 --- /dev/null +++ b/X10D.Unity/src/GameObjectExtensions.cs @@ -0,0 +1,252 @@ +using UnityEngine; + +namespace X10D.Unity; + +/// +/// Extension methods for . +/// +public static class GameObjectExtensions +{ + /// + /// Rotates the transform component of this game object so the forward vector points at another game object. + /// + /// The game object whose rotation will be changed. + /// The game object to look at. + /// + /// is . + /// -or- + /// is . + /// + public static void LookAt(this GameObject gameObject, GameObject target) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + gameObject.transform.LookAt(target.transform); + } + + /// + /// Rotates the transform component of this game object so the forward vector points at . + /// + /// The game object whose rotation will be changed. + /// The point to look at. + /// is . + public static void LookAt(this GameObject gameObject, Vector3 target) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + gameObject.transform.LookAt(target); + } + + /// + /// Rotates the transform component of this game object so the forward vector points at a specified transform. + /// + /// The game object whose rotation will be changed. + /// The transform to look at. + /// + /// is . + /// -or- + /// is . + /// + public static void LookAt(this GameObject gameObject, Transform target) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + gameObject.transform.LookAt(target); + } + + /// + /// Rotates the transform component of this game object so the forward vector points at another game object. + /// + /// The game object whose rotation will be changed. + /// The game object to look at. + /// A vector specifying the upward direction. + /// + /// is . + /// -or- + /// is . + /// + public static void LookAt(this GameObject gameObject, GameObject target, Vector3 worldUp) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + gameObject.transform.LookAt(target.transform, worldUp); + } + + /// + /// Rotates the transform component of this game object so the forward vector points at . + /// + /// The game object whose rotation will be changed. + /// The point to look at. + /// A vector specifying the upward direction. + /// is . + public static void LookAt(this GameObject gameObject, Vector3 target, Vector3 worldUp) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + gameObject.transform.LookAt(target, worldUp); + } + + /// + /// Rotates the transform component of this game object so the forward vector points at a specified transform. + /// + /// The game object whose rotation will be changed. + /// The transform to look at. + /// A vector specifying the upward direction. + /// + /// is . + /// -or- + /// is . + /// + public static void LookAt(this GameObject gameObject, Transform target, Vector3 worldUp) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + gameObject.transform.LookAt(target, worldUp); + } + + /// + /// Sets the parent of this game object. + /// + /// The game object whose parent to change. + /// The new parent. + /// + /// is . + /// -or- + /// is . + /// + public static void SetParent(this GameObject gameObject, GameObject parent) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + gameObject.transform.SetParent(parent.transform); + } + + /// + /// Sets the parent of this game object. + /// + /// The game object whose parent to change. + /// The new parent. + /// + /// is . + /// -or- + /// is . + /// + public static void SetParent(this GameObject gameObject, Transform parent) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + gameObject.transform.SetParent(parent); + } + + /// + /// Sets the parent of this game object. + /// + /// The game object whose parent to change. + /// The new parent. + /// + /// to modify the parent-relative position, scale and rotation such that the object keeps the same + /// world space position, rotation and scale as before; otherwise, . + /// + /// + /// is . + /// -or- + /// is . + /// + public static void SetParent(this GameObject gameObject, GameObject parent, bool worldPositionStays) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + gameObject.transform.SetParent(parent.transform, worldPositionStays); + } + + /// + /// Sets the parent of this game object. + /// + /// The game object whose parent to change. + /// The new parent. + /// + /// to modify the parent-relative position, scale and rotation such that the object keeps the same + /// world space position, rotation and scale as before; otherwise, . + /// + /// + /// is . + /// -or- + /// is . + /// + public static void SetParent(this GameObject gameObject, Transform parent, bool worldPositionStays) + { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + gameObject.transform.SetParent(parent, worldPositionStays); + } +} diff --git a/X10D.Unity/src/Numerics/RandomExtensions.cs b/X10D.Unity/src/Numerics/RandomExtensions.cs new file mode 100644 index 0000000..98d90d0 --- /dev/null +++ b/X10D.Unity/src/Numerics/RandomExtensions.cs @@ -0,0 +1,118 @@ +using UnityEngine; +using X10D.Core; +using Random = System.Random; + +namespace X10D.Unity.Numerics; + +/// +/// Extension methods for . +/// +public static class RandomExtensions +{ + /// + /// Returns a randomly generated rotation as represented by a . + /// + /// The instance. + /// + /// A constructed from 3 random single-precision floating point numbers representing the + /// yaw, pitch, and roll. + /// + /// is . + public static Quaternion NextRotation(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + int seed = random.Next(); + var seededRandom = new Random(seed); + + float x = seededRandom.NextSingle(0, 360); + float y = seededRandom.NextSingle(0, 360); + float z = seededRandom.NextSingle(0, 360); + + return Quaternion.Euler(x, y, z); + } + + /// + /// Returns a randomly generated rotation with uniform distribution. + /// + /// The instance. + /// A constructed with uniform distribution. + /// is . + public static Quaternion NextRotationUniform(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + int seed = random.Next(); + var seededRandom = new Random(seed); + float normal, w, x, y, z; + + do + { + w = seededRandom.NextSingle(-1f, 1f); + x = seededRandom.NextSingle(-1f, 1f); + y = seededRandom.NextSingle(-1f, 1f); + z = seededRandom.NextSingle(-1f, 1f); + normal = (w * w) + (x * x) + (y * y) + (z * z); + } while (normal is 0f or > 1f); + + normal = MathF.Sqrt(normal); + return new Quaternion(x / normal, y / normal, z / normal, w / normal); + } + + /// + /// Returns a with magnitude 1 whose components indicate a random point on the unit circle. + /// + /// The instance + /// + /// A whose returns 1, and whose components indicate a random + /// point on the unit circle. + /// + public static Vector2 NextUnitVector2(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + // no need to construct a seeded random here, since we only call Next once + + float angle = random.NextSingle(0, MathF.PI * 2.0f); + float x = MathF.Cos(angle); + float y = MathF.Sin(angle); + + return new Vector2(x, y); + } + + /// + /// Returns a with magnitude 1 whose components indicate a random point on the unit sphere. + /// + /// The instance + /// + /// A whose returns 1, and whose components indicate a random + /// point on the unit sphere. + /// + public static Vector3 NextUnitVector3(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + int seed = random.Next(); + var seededRandom = new Random(seed); + + float angle = seededRandom.NextSingle(0, MathF.PI * 2.0f); + float z = seededRandom.NextSingle(-1, 1); + float mp = MathF.Sqrt(1 - (z * z)); + float x = mp * MathF.Cos(angle); + float y = mp * MathF.Sin(angle); + + return new Vector3(x, y, z); + } +} diff --git a/X10D.Unity/src/TransformExtensions.cs b/X10D.Unity/src/TransformExtensions.cs new file mode 100644 index 0000000..922ed5c --- /dev/null +++ b/X10D.Unity/src/TransformExtensions.cs @@ -0,0 +1,114 @@ +using UnityEngine; + +namespace X10D.Unity; + +/// +/// Extension methods for . +/// +public static class TransformExtensions +{ + /// + /// Rotates this transform so the forward vector points at another game object. + /// + /// The transform whose rotation will be changed. + /// The game object to look at. + /// + /// is . + /// -or- + /// is . + /// + public static void LookAt(this Transform transform, GameObject target) + { + if (transform == null) + { + throw new ArgumentNullException(nameof(transform)); + } + + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + transform.LookAt(target.transform); + } + + /// + /// Rotates this transform so the forward vector points at another game object. + /// + /// The transform whose rotation will be changed. + /// The game object to look at. + /// A vector specifying the upward direction. + /// + /// is . + /// -or- + /// is . + /// + public static void LookAt(this Transform transform, GameObject target, Vector3 worldUp) + { + if (transform == null) + { + throw new ArgumentNullException(nameof(transform)); + } + + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + transform.LookAt(target.transform, worldUp); + } + + /// + /// Sets the parent of this transform. + /// + /// The transform whose parent to change. + /// The new parent. + /// + /// is . + /// -or- + /// is . + /// + public static void SetParent(this Transform transform, GameObject parent) + { + if (transform == null) + { + throw new ArgumentNullException(nameof(transform)); + } + + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + transform.transform.SetParent(parent.transform); + } + + /// + /// Sets the parent of this transform. + /// + /// The transform whose parent to change. + /// The new parent. + /// + /// to modify the parent-relative position, scale and rotation such that the object keeps the same + /// world space position, rotation and scale as before; otherwise, . + /// + /// + /// is . + /// -or- + /// is . + /// + public static void SetParent(this Transform transform, GameObject parent, bool worldPositionStays) + { + if (transform == null) + { + throw new ArgumentNullException(nameof(transform)); + } + + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + transform.SetParent(parent.transform, worldPositionStays); + } +} diff --git a/X10D.sln b/X10D.sln index 067e80e..ef76213 100644 --- a/X10D.sln +++ b/X10D.sln @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X10D.SourceValidator", "X10D.SourceValidator\X10D.SourceValidator.csproj", "{84750149-9068-4780-AFDE-CDA1AC57007D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X10D.Unity", "X10D.Unity\X10D.Unity.csproj", "{7EAB3F09-A9FD-4334-B4DB-0394DD0C6568}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -38,6 +40,10 @@ Global {84750149-9068-4780-AFDE-CDA1AC57007D}.Debug|Any CPU.Build.0 = Debug|Any CPU {84750149-9068-4780-AFDE-CDA1AC57007D}.Release|Any CPU.ActiveCfg = Release|Any CPU {84750149-9068-4780-AFDE-CDA1AC57007D}.Release|Any CPU.Build.0 = Release|Any CPU + {7EAB3F09-A9FD-4334-B4DB-0394DD0C6568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7EAB3F09-A9FD-4334-B4DB-0394DD0C6568}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7EAB3F09-A9FD-4334-B4DB-0394DD0C6568}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7EAB3F09-A9FD-4334-B4DB-0394DD0C6568}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/X10D/X10D.csproj b/X10D/X10D.csproj index e221531..b72b7f1 100644 --- a/X10D/X10D.csproj +++ b/X10D/X10D.csproj @@ -1,7 +1,7 @@  - net6.0 + net6.0;netstandard2.1 10.0 true true diff --git a/X10D/src/Collections/ArrayExtensions.cs b/X10D/src/Collections/ArrayExtensions.cs index 7b6d5ee..816fabd 100644 --- a/X10D/src/Collections/ArrayExtensions.cs +++ b/X10D/src/Collections/ArrayExtensions.cs @@ -17,7 +17,14 @@ 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); } @@ -42,7 +49,14 @@ public static class ArrayExtensions /// is . public static void Clear(this T?[] array, Range range) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(array); +#else + if (array is null) + { + throw new ArgumentNullException(nameof(array)); + } +#endif int index = range.Start.Value; int end = range.End.Value; @@ -71,7 +85,14 @@ public static class ArrayExtensions /// public static void Clear(this T?[] array, int index, int length) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(array); +#else + if (array is null) + { + throw new ArgumentNullException(nameof(array)); + } +#endif if (length == 0 || array.Length == 0) { diff --git a/X10D/src/Collections/BoolListExtensions.cs b/X10D/src/Collections/BoolListExtensions.cs index d2b8991..ee70050 100644 --- a/X10D/src/Collections/BoolListExtensions.cs +++ b/X10D/src/Collections/BoolListExtensions.cs @@ -18,7 +18,14 @@ 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) { @@ -45,7 +52,14 @@ public static class BoolListExtensions [Pure] public static short PackInt16(this IReadOnlyList source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif if (source.Count > 16) { @@ -72,7 +86,14 @@ public static class BoolListExtensions [Pure] public static int PackInt32(this IReadOnlyList source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif if (source.Count > 32) { @@ -99,7 +120,14 @@ public static class BoolListExtensions [Pure] public static long PackInt64(this IReadOnlyList source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif if (source.Count > 64) { diff --git a/X10D/src/Collections/DictionaryExtensions.cs b/X10D/src/Collections/DictionaryExtensions.cs index 2abef8a..86ae231 100644 --- a/X10D/src/Collections/DictionaryExtensions.cs +++ b/X10D/src/Collections/DictionaryExtensions.cs @@ -34,8 +34,22 @@ public static class DictionaryExtensions Func updateValueFactory) where TKey : notnull { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(dictionary); +#else + if (dictionary is null) + { + throw new ArgumentNullException(nameof(dictionary)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(updateValueFactory); +#else + if (updateValueFactory is null) + { + throw new ArgumentNullException(nameof(updateValueFactory)); + } +#endif if (dictionary.ContainsKey(key)) { @@ -77,9 +91,30 @@ public static class DictionaryExtensions Func addValueFactory, Func updateValueFactory) where TKey : notnull { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(dictionary); +#else + if (dictionary is null) + { + throw new ArgumentNullException(nameof(dictionary)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(addValueFactory); +#else + if (addValueFactory is null) + { + throw new ArgumentNullException(nameof(addValueFactory)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(updateValueFactory); +#else + if (updateValueFactory is null) + { + throw new ArgumentNullException(nameof(updateValueFactory)); + } +#endif if (dictionary.ContainsKey(key)) { @@ -127,9 +162,30 @@ public static class DictionaryExtensions Func addValueFactory, Func updateValueFactory, TArg factoryArgument) where TKey : notnull { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(dictionary); +#else + if (dictionary is null) + { + throw new ArgumentNullException(nameof(dictionary)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(addValueFactory); +#else + if (addValueFactory is null) + { + throw new ArgumentNullException(nameof(addValueFactory)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(updateValueFactory); +#else + if (updateValueFactory is null) + { + throw new ArgumentNullException(nameof(updateValueFactory)); + } +#endif if (dictionary.ContainsKey(key)) { @@ -155,7 +211,14 @@ public static class DictionaryExtensions [Pure] public static string ToConnectionString(this IEnumerable> source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif static string SanitizeValue(string? value) { @@ -195,8 +258,22 @@ public static class DictionaryExtensions public static string ToConnectionString(this IEnumerable> source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(selector); +#else + if (selector is null) + { + throw new ArgumentNullException(nameof(selector)); + } +#endif static string SanitizeValue(string? value) { @@ -242,9 +319,30 @@ public static class DictionaryExtensions Func keySelector, Func valueSelector) where TKey : notnull { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(keySelector); +#else + if (keySelector is null) + { + throw new ArgumentNullException(nameof(keySelector)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(valueSelector); +#else + if (valueSelector is null) + { + throw new ArgumentNullException(nameof(valueSelector)); + } +#endif static string SanitizeValue(string? value) { @@ -276,7 +374,14 @@ public static class DictionaryExtensions public static string ToGetParameters(this IEnumerable> source) where TKey : notnull { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif static string GetQueryParameter(KeyValuePair pair) { @@ -308,8 +413,22 @@ public static class DictionaryExtensions Func selector) where TKey : notnull { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(selector); +#else + if (selector is null) + { + throw new ArgumentNullException(nameof(selector)); + } +#endif // can't static here because of 'selector' parameter string GetQueryParameter(KeyValuePair pair) @@ -347,9 +466,30 @@ public static class DictionaryExtensions Func keySelector, Func valueSelector) where TKey : notnull { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(keySelector); +#else + if (keySelector is null) + { + throw new ArgumentNullException(nameof(keySelector)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(valueSelector); +#else + if (valueSelector is null) + { + throw new ArgumentNullException(nameof(valueSelector)); + } +#endif // can't static here because of selector parameters string GetQueryParameter(KeyValuePair pair) diff --git a/X10D/src/Collections/EnumerableExtensions.cs b/X10D/src/Collections/EnumerableExtensions.cs index fa44da6..4a75370 100644 --- a/X10D/src/Collections/EnumerableExtensions.cs +++ b/X10D/src/Collections/EnumerableExtensions.cs @@ -139,7 +139,14 @@ public static class EnumerableExtensions [Pure] public static IReadOnlyCollection Shuffled(this IEnumerable source, Random? random = null) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif var list = new List(source); list.Shuffle(random); diff --git a/X10D/src/Collections/ListExtensions.cs b/X10D/src/Collections/ListExtensions.cs index de3c0ab..bb0b601 100644 --- a/X10D/src/Collections/ListExtensions.cs +++ b/X10D/src/Collections/ListExtensions.cs @@ -17,7 +17,14 @@ 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++) { @@ -44,7 +51,14 @@ public static class ListExtensions /// public static void Fill(this IList source, T value, int startIndex, int count) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif if (startIndex < 0) { @@ -78,8 +92,8 @@ public static class ListExtensions /// The element type. /// The source collection from which to draw. /// - /// The instance to use for the shuffling. If is specified, - /// is used. + /// The instance to use for the shuffling. If is specified, a shared + /// instance is used. /// /// A random element of type from . /// is . @@ -92,9 +106,16 @@ public static class ListExtensions [Pure] public static T Random(this IReadOnlyList source, Random? random = null) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif - random ??= System.Random.Shared; + random ??= RandomExtensions.GetShared(); return random.NextFrom(source); } @@ -104,15 +125,22 @@ public static class ListExtensions /// The element type. /// The to shuffle. /// - /// The instance to use for the shuffling. If is specified, - /// is used. + /// The instance to use for the shuffling. If is specified, a shared + /// instance is used. /// /// 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 ??= System.Random.Shared; + random ??= RandomExtensions.GetShared(); int count = source.Count; while (count > 0) diff --git a/X10D/src/Core/EnumExtensions.cs b/X10D/src/Core/EnumExtensions.cs index fbba9b4..29b7649 100644 --- a/X10D/src/Core/EnumExtensions.cs +++ b/X10D/src/Core/EnumExtensions.cs @@ -20,7 +20,11 @@ public static class EnumExtensions public static T Next(this T value) where T : struct, Enum { +#if NET5_0_OR_GREATER T[] values = Enum.GetValues(); +#else + T[] values = Enum.GetValues(typeof(T)).Cast().ToArray(); +#endif int index = Array.IndexOf(values, value) + 1; index %= values.Length; return values[index]; @@ -40,7 +44,11 @@ public static class EnumExtensions public static T NextUnchecked(this T value) where T : struct, Enum { +#if NET5_0_OR_GREATER T[] values = Enum.GetValues(); +#else + T[] values = Enum.GetValues(typeof(T)).Cast().ToArray(); +#endif int index = Array.IndexOf(values, value) + 1; return values[index]; } @@ -58,7 +66,11 @@ public static class EnumExtensions public static T Previous(this T value) where T : struct, Enum { +#if NET5_0_OR_GREATER T[] values = Enum.GetValues(); +#else + T[] values = Enum.GetValues(typeof(T)).Cast().ToArray(); +#endif int index = Array.IndexOf(values, value) - 1; int length = values.Length; @@ -82,7 +94,11 @@ public static class EnumExtensions public static T PreviousUnchecked(this T value) where T : struct, Enum { +#if NET5_0_OR_GREATER T[] values = Enum.GetValues(); +#else + T[] values = Enum.GetValues(typeof(T)).Cast().ToArray(); +#endif int index = Array.IndexOf(values, value) - 1; return values[index]; } diff --git a/X10D/src/Core/Extensions.cs b/X10D/src/Core/Extensions.cs index 21348d6..8817ca0 100644 --- a/X10D/src/Core/Extensions.cs +++ b/X10D/src/Core/Extensions.cs @@ -16,7 +16,7 @@ public static class Extensions /// An array of type with length 1, whose only element is . /// [Pure] - public static T?[] AsArrayValue(this T? value) + public static T[] AsArrayValue(this T value) { return new[] {value}; } @@ -30,7 +30,7 @@ public static class Extensions /// An enumerable collection of type , whose only element is . /// [Pure] - public static IEnumerable AsEnumerableValue(this T? value) + public static IEnumerable AsEnumerableValue(this T value) { yield return value; } diff --git a/X10D/src/Core/RandomExtensions.cs b/X10D/src/Core/RandomExtensions.cs index c075fd3..a111704 100644 --- a/X10D/src/Core/RandomExtensions.cs +++ b/X10D/src/Core/RandomExtensions.cs @@ -9,6 +9,8 @@ namespace X10D.Core; /// public static class RandomExtensions { + private static readonly Random Shared = new(); + /// /// Returns a random value that defined in a specified enum. /// @@ -21,7 +23,14 @@ 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))!; @@ -41,7 +50,14 @@ public static class RandomExtensions /// is . public static bool NextBoolean(this Random random) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif return random.NextDouble() >= 0.5; } @@ -61,7 +77,14 @@ public static class RandomExtensions /// is less than 0. public static double NextDouble(this Random random, double maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif if (maxValue < 0) { @@ -90,7 +113,14 @@ public static class RandomExtensions /// public static double NextDouble(this Random random, double minValue, double maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif if (maxValue < minValue) { @@ -121,8 +151,22 @@ public static class RandomExtensions /// public static T NextFrom(this Random random, IEnumerable source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif if (source is T[] array) { @@ -147,7 +191,14 @@ public static class RandomExtensions /// is . public static byte NextByte(this Random random) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif return random.NextByte(byte.MaxValue); } @@ -168,7 +219,14 @@ public static class RandomExtensions /// is . public static byte NextByte(this Random random, byte maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif return random.NextByte(0, maxValue); } @@ -194,7 +252,14 @@ public static class RandomExtensions /// public static byte NextByte(this Random random, byte minValue, byte maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif return (byte)random.Next(minValue, maxValue); } @@ -209,7 +274,14 @@ public static class RandomExtensions /// is . public static short NextInt16(this Random random) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif return random.NextInt16(short.MaxValue); } @@ -231,7 +303,14 @@ public static class RandomExtensions /// is less than 0. public static short NextInt16(this Random random, short maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif if (maxValue < 0) { @@ -262,11 +341,36 @@ public static class RandomExtensions /// is . public static short NextInt16(this Random random, short minValue, short maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif return (short)random.Next(minValue, maxValue); } +#if !NET6_0_OR_GREATER + /// + /// Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0. + /// + /// The instance. + /// A single-precision floating point number that is greater than or equal to 0.0, and less than 1.0. + /// is . + public static float NextSingle(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + return (float)random.NextDouble(); + } +#endif + /// /// Returns a non-negative random single-precision floating point number that is less than the specified maximum. /// @@ -282,7 +386,14 @@ public static class RandomExtensions /// is less than 0. public static float NextSingle(this Random random, float maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif if (maxValue < 0) { @@ -311,7 +422,14 @@ public static class RandomExtensions /// public static float NextSingle(this Random random, float minValue, float maxValue) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif if (maxValue < minValue) { @@ -339,8 +457,22 @@ public static class RandomExtensions /// is less than 0. public static string NextString(this Random random, IReadOnlyList source, int length) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif if (length < 0) { @@ -365,4 +497,13 @@ public static class RandomExtensions return builder.ToString(); } + + internal static Random GetShared() + { +#if NET6_0_OR_GREATER + return Random.Shared; +#else + return Shared; +#endif + } } diff --git a/X10D/src/Drawing/RandomExtensions.cs b/X10D/src/Drawing/RandomExtensions.cs index e121cb4..edfecd3 100644 --- a/X10D/src/Drawing/RandomExtensions.cs +++ b/X10D/src/Drawing/RandomExtensions.cs @@ -15,7 +15,14 @@ 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)); @@ -29,7 +36,14 @@ public static class RandomExtensions /// is . public static Color NextColorArgb(this Random random) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif int argb = random.Next(); return Color.FromArgb(argb); diff --git a/X10D/src/IO/DoubleExtensions.cs b/X10D/src/IO/DoubleExtensions.cs index b33df1e..ec9fc7d 100644 --- a/X10D/src/IO/DoubleExtensions.cs +++ b/X10D/src/IO/DoubleExtensions.cs @@ -1,5 +1,6 @@ using System.Buffers.Binary; using System.Diagnostics.Contracts; +using System.Runtime.InteropServices; namespace X10D.IO; @@ -55,8 +56,11 @@ public static class DoubleExtensions /// if the conversion was successful; otherwise, . public static bool TryWriteBytes(this double value, Span destination, Endianness endianness) { - return endianness == Endianness.BigEndian - ? BinaryPrimitives.TryWriteDoubleBigEndian(destination, value) - : BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value); + if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); + } + + return MemoryMarshal.TryWrite(destination, ref value); } } diff --git a/X10D/src/IO/FileInfoExtensions.cs b/X10D/src/IO/FileInfoExtensions.cs index 2b36120..a0878bc 100644 --- a/X10D/src/IO/FileInfoExtensions.cs +++ b/X10D/src/IO/FileInfoExtensions.cs @@ -29,7 +29,14 @@ 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(); @@ -62,7 +69,14 @@ public static class FileInfoExtensions public static bool TryWriteHash(this FileInfo value, Span destination, out int bytesWritten) where T : HashAlgorithm { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(value); +#else + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } +#endif using FileStream stream = value.OpenRead(); return stream.TryWriteHash(destination, out bytesWritten); diff --git a/X10D/src/IO/ListOfByteExtensions.cs b/X10D/src/IO/ListOfByteExtensions.cs index 1c8cf39..d9fd480 100644 --- a/X10D/src/IO/ListOfByteExtensions.cs +++ b/X10D/src/IO/ListOfByteExtensions.cs @@ -19,7 +19,14 @@ 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()); } @@ -47,7 +54,14 @@ public static class ListOfByteExtensions /// is . public static double ToDouble(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToDouble(source.ToArray(), startIndex); } @@ -72,7 +86,14 @@ public static class ListOfByteExtensions /// is . public static short ToInt16(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToInt16(source.ToArray(), startIndex); } @@ -97,7 +118,14 @@ public static class ListOfByteExtensions /// is . public static int ToInt32(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToInt32(source.ToArray(), startIndex); } @@ -122,7 +150,14 @@ public static class ListOfByteExtensions /// is . public static long ToInt64(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToInt64(source.ToArray(), startIndex); } @@ -149,7 +184,14 @@ public static class ListOfByteExtensions /// is . public static float ToSingle(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToSingle(source.ToArray(), startIndex); } @@ -167,8 +209,22 @@ public static class ListOfByteExtensions /// public static string ToString(this IReadOnlyList source, Encoding encoding) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(encoding); +#else + if (encoding is null) + { + throw new ArgumentNullException(nameof(encoding)); + } +#endif return encoding.GetString(source.ToArray()); } @@ -195,7 +251,14 @@ public static class ListOfByteExtensions [CLSCompliant(false)] public static ushort ToUInt16(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToUInt16(source.ToArray(), startIndex); } @@ -222,7 +285,14 @@ public static class ListOfByteExtensions [CLSCompliant(false)] public static uint ToUInt32(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToUInt32(source.ToArray(), startIndex); } @@ -249,7 +319,14 @@ public static class ListOfByteExtensions [CLSCompliant(false)] public static ulong ToUInt64(this IReadOnlyList source, int startIndex) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return BitConverter.ToUInt64(source.ToArray(), startIndex); } diff --git a/X10D/src/IO/SingleExtensions.cs b/X10D/src/IO/SingleExtensions.cs index ea9ae4b..f2bf3d9 100644 --- a/X10D/src/IO/SingleExtensions.cs +++ b/X10D/src/IO/SingleExtensions.cs @@ -1,5 +1,6 @@ using System.Buffers.Binary; using System.Diagnostics.Contracts; +using System.Runtime.InteropServices; namespace X10D.IO; @@ -55,8 +56,11 @@ public static class SingleExtensions /// if the conversion was successful; otherwise, . public static bool TryWriteBytes(this float value, Span destination, Endianness endianness) { - return endianness == Endianness.BigEndian - ? BinaryPrimitives.TryWriteSingleBigEndian(destination, value) - : BinaryPrimitives.TryWriteSingleLittleEndian(destination, value); + if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); + } + + return MemoryMarshal.TryWrite(destination, ref value); } } diff --git a/X10D/src/IO/StreamExtensions.cs b/X10D/src/IO/StreamExtensions.cs index 2aa70bc..4b16c5a 100644 --- a/X10D/src/IO/StreamExtensions.cs +++ b/X10D/src/IO/StreamExtensions.cs @@ -1,5 +1,6 @@ using System.Buffers.Binary; using System.Reflection; +using System.Runtime.InteropServices; using System.Security.Cryptography; namespace X10D.IO; @@ -31,10 +32,14 @@ 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) { @@ -81,15 +86,26 @@ public static class StreamExtensions /// A decimal value read from the stream. public static decimal ReadDecimal(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif const int decimalSize = sizeof(decimal); const int int32Size = sizeof(int); @@ -129,22 +145,38 @@ public static class StreamExtensions /// A double-precision floating point value read from the stream. public static double ReadDouble(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(double)]; stream.Read(buffer); - return endianness == Endianness.LittleEndian - ? BinaryPrimitives.ReadDoubleLittleEndian(buffer) - : BinaryPrimitives.ReadDoubleBigEndian(buffer); + var value = MemoryMarshal.Read(buffer); + + if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); + } + + return value; } /// @@ -167,15 +199,26 @@ public static class StreamExtensions /// An two-byte unsigned integer read from the stream. public static short ReadInt16(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(short)]; stream.Read(buffer); @@ -205,15 +248,26 @@ public static class StreamExtensions /// An four-byte unsigned integer read from the stream. public static int ReadInt32(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(int)]; stream.Read(buffer); @@ -243,15 +297,26 @@ public static class StreamExtensions /// An eight-byte unsigned integer read from the stream. public static long ReadInt64(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(long)]; stream.Read(buffer); @@ -281,22 +346,38 @@ public static class StreamExtensions /// A single-precision floating point value read from the stream. public static double 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)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(float)]; stream.Read(buffer); - return endianness == Endianness.LittleEndian - ? BinaryPrimitives.ReadSingleLittleEndian(buffer) - : BinaryPrimitives.ReadSingleBigEndian(buffer); + var value = MemoryMarshal.Read(buffer); + + if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); + } + + return value; } /// @@ -321,15 +402,26 @@ public static class StreamExtensions [CLSCompliant(false)] public static ushort ReadUInt16(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(ushort)]; stream.Read(buffer); @@ -361,15 +453,26 @@ public static class StreamExtensions [CLSCompliant(false)] public static uint ReadUInt32(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(uint)]; stream.Read(buffer); @@ -401,15 +504,26 @@ public static class StreamExtensions [CLSCompliant(false)] public static ulong ReadUInt64(this Stream stream, Endianness endianness) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(ulong)]; stream.Read(buffer); @@ -445,10 +559,14 @@ public static class StreamExtensions public static bool TryWriteHash(this Stream stream, Span destination, out int bytesWritten) where T : HashAlgorithm { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(stream); +#else if (stream is null) { throw new ArgumentNullException(nameof(stream)); } +#endif if (!stream.CanRead) { @@ -504,12 +622,26 @@ public static class StreamExtensions /// The number of bytes written to the stream. public static int Write(this Stream stream, short value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(short)]; @@ -548,12 +680,26 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, int value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(int)]; @@ -593,12 +739,26 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, long value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(long)]; @@ -640,12 +800,26 @@ public static class StreamExtensions [CLSCompliant(false)] public static int Write(this Stream stream, ushort value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(ushort)]; @@ -687,12 +861,26 @@ public static class StreamExtensions [CLSCompliant(false)] public static int Write(this Stream stream, uint value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(uint)]; @@ -734,12 +922,26 @@ public static class StreamExtensions [CLSCompliant(false)] public static int Write(this Stream stream, ulong value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(ulong)]; @@ -766,22 +968,54 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, float value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(float)]; if (endianness == Endianness.LittleEndian) { +#if NET5_0_OR_GREATER BinaryPrimitives.WriteSingleLittleEndian(buffer, value); +#else + if (BitConverter.IsLittleEndian) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); + } + + System.Runtime.InteropServices.MemoryMarshal.Write(buffer, ref value); +#endif } else { +#if NET5_0_OR_GREATER BinaryPrimitives.WriteSingleBigEndian(buffer, value); +#else + if (BitConverter.IsLittleEndian) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); + } + + System.Runtime.InteropServices.MemoryMarshal.Write(buffer, ref value); +#endif } return stream.WriteInternal(buffer); @@ -798,22 +1032,54 @@ public static class StreamExtensions /// is . public static int Write(this Stream stream, double value, Endianness endianness) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(stream); +#else + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } +#endif +#if NET5_0_OR_GREATER if (!Enum.IsDefined(endianness)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif Span buffer = stackalloc byte[sizeof(double)]; if (endianness == Endianness.LittleEndian) { +#if NET5_0_OR_GREATER BinaryPrimitives.WriteDoubleLittleEndian(buffer, value); +#else + if (BitConverter.IsLittleEndian) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); + } + + System.Runtime.InteropServices.MemoryMarshal.Write(buffer, ref value); +#endif } else { +#if NET5_0_OR_GREATER BinaryPrimitives.WriteDoubleBigEndian(buffer, value); +#else + if (BitConverter.IsLittleEndian) + { + value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); + } + + System.Runtime.InteropServices.MemoryMarshal.Write(buffer, ref value); +#endif } return stream.WriteInternal(buffer); @@ -830,12 +1096,26 @@ public static class StreamExtensions /// is . 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)) { throw new ArgumentOutOfRangeException(nameof(endianness)); } +#else + if (!Enum.IsDefined(typeof(Endianness), endianness)) + { + throw new ArgumentOutOfRangeException(nameof(endianness)); + } +#endif int[] bits = decimal.GetBits(value); long preWritePosition = stream.Position; diff --git a/X10D/src/Linq/ByteExtensions.cs b/X10D/src/Linq/ByteExtensions.cs index 32a11f3..3d7524d 100644 --- a/X10D/src/Linq/ByteExtensions.cs +++ b/X10D/src/Linq/ByteExtensions.cs @@ -15,7 +15,14 @@ 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)); } @@ -29,7 +36,14 @@ public static class ByteExtensions [CLSCompliant(false)] public static sbyte Product(this IEnumerable source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Aggregate((sbyte)1, (current, value) => (sbyte)(current * value)); } @@ -45,7 +59,14 @@ public static class ByteExtensions /// is . public static byte Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } @@ -62,7 +83,14 @@ public static class ByteExtensions [CLSCompliant(false)] public static sbyte Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/DecimalExtensions.cs b/X10D/src/Linq/DecimalExtensions.cs index 796a402..01dde51 100644 --- a/X10D/src/Linq/DecimalExtensions.cs +++ b/X10D/src/Linq/DecimalExtensions.cs @@ -13,7 +13,14 @@ 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)); } @@ -29,7 +36,14 @@ public static class DecimalExtensions /// is . public static decimal Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/DoubleExtensions.cs b/X10D/src/Linq/DoubleExtensions.cs index e84343b..afb38ae 100644 --- a/X10D/src/Linq/DoubleExtensions.cs +++ b/X10D/src/Linq/DoubleExtensions.cs @@ -13,7 +13,14 @@ 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)); } @@ -29,7 +36,14 @@ public static class DoubleExtensions /// is . public static double Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/Int32Extensions.cs b/X10D/src/Linq/Int32Extensions.cs index fb636c8..871e422 100644 --- a/X10D/src/Linq/Int32Extensions.cs +++ b/X10D/src/Linq/Int32Extensions.cs @@ -15,7 +15,14 @@ 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); } @@ -29,7 +36,14 @@ public static class Int32Extensions [CLSCompliant(false)] public static uint Product(this IEnumerable source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Aggregate(1u, (current, value) => current * value); } @@ -45,7 +59,14 @@ public static class Int32Extensions /// is . public static int Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } @@ -62,7 +83,14 @@ public static class Int32Extensions [CLSCompliant(false)] public static uint Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/Int64Extensions.cs b/X10D/src/Linq/Int64Extensions.cs index a29c3dc..07b9802 100644 --- a/X10D/src/Linq/Int64Extensions.cs +++ b/X10D/src/Linq/Int64Extensions.cs @@ -15,7 +15,14 @@ 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); } @@ -29,7 +36,14 @@ public static class Int64Extensions [CLSCompliant(false)] public static ulong Product(this IEnumerable source) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Aggregate(1UL, (current, value) => current * value); } @@ -45,7 +59,14 @@ public static class Int64Extensions /// is . public static long Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } @@ -62,7 +83,14 @@ public static class Int64Extensions [CLSCompliant(false)] public static ulong Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/ReadOnlySpanExtensions.cs b/X10D/src/Linq/ReadOnlySpanExtensions.cs index 9c465ea..8b10261 100644 --- a/X10D/src/Linq/ReadOnlySpanExtensions.cs +++ b/X10D/src/Linq/ReadOnlySpanExtensions.cs @@ -21,7 +21,14 @@ 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) { @@ -53,7 +60,14 @@ public static class ReadOnlySpanExtensions [Pure] public static bool Any(this ReadOnlySpan source, Predicate predicate) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(predicate); +#else + if (predicate is null) + { + throw new ArgumentNullException(nameof(predicate)); + } +#endif if (source.IsEmpty) { diff --git a/X10D/src/Linq/SingleExtensions.cs b/X10D/src/Linq/SingleExtensions.cs index 5cf9004..9d48203 100644 --- a/X10D/src/Linq/SingleExtensions.cs +++ b/X10D/src/Linq/SingleExtensions.cs @@ -13,7 +13,14 @@ 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)); } @@ -29,7 +36,14 @@ public static class SingleExtensions /// is . public static float Product(this IEnumerable source, Func selector) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(source); +#else + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } +#endif return source.Select(selector).Product(); } diff --git a/X10D/src/Linq/SpanExtensions.cs b/X10D/src/Linq/SpanExtensions.cs index 4ae07c0..d5a208a 100644 --- a/X10D/src/Linq/SpanExtensions.cs +++ b/X10D/src/Linq/SpanExtensions.cs @@ -21,7 +21,14 @@ 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) { @@ -53,7 +60,14 @@ public static class SpanExtensions [Pure] public static bool Any(this Span source, Predicate predicate) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(predicate); +#else + if (predicate is null) + { + throw new ArgumentNullException(nameof(predicate)); + } +#endif if (source.IsEmpty) { diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index 8e25088..310c4e4 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -19,7 +19,11 @@ public static class ByteExtensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static byte DigitalRoot(this byte value) { int root = value % 9; @@ -32,7 +36,11 @@ public static class ByteExtensions /// The value whose factorial to compute. /// The factorial of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long Factorial(this byte value) { if (value == 0) @@ -58,7 +66,11 @@ public static class ByteExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this byte value) { return value % 2 == 0; @@ -73,7 +85,11 @@ public static class ByteExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this byte value) { return !value.IsEven(); @@ -101,7 +117,11 @@ public static class ByteExtensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this byte value) { return ((long)value).MultiplicativePersistence(); diff --git a/X10D/src/Math/ComparableExtensions.cs b/X10D/src/Math/ComparableExtensions.cs index 211cfff..06cd86a 100644 --- a/X10D/src/Math/ComparableExtensions.cs +++ b/X10D/src/Math/ComparableExtensions.cs @@ -48,14 +48,25 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool Between(this T1 value, T2 lower, T3 upper, InclusiveOptions inclusiveOptions = InclusiveOptions.None) where T1 : IComparable, IComparable 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)) { @@ -102,11 +113,22 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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)) { @@ -141,11 +163,22 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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; } @@ -173,11 +206,22 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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; } @@ -205,11 +249,22 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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; } @@ -237,11 +292,22 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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; } @@ -268,11 +334,22 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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; } @@ -299,11 +376,22 @@ public static class ComparableExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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/Math/DecimalExtensions.cs b/X10D/src/Math/DecimalExtensions.cs index a6dfe60..418909c 100644 --- a/X10D/src/Math/DecimalExtensions.cs +++ b/X10D/src/Math/DecimalExtensions.cs @@ -9,6 +9,7 @@ namespace X10D.Math; /// public static class DecimalExtensions { +#if NETCOREAPP3_0_OR_GREATER /// /// Returns the complex square root of this decimal number. /// @@ -20,6 +21,7 @@ public static class DecimalExtensions { return Complex.Sqrt((double)value); } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -30,7 +32,11 @@ public static class DecimalExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this decimal value) { return value % 2.0m == 0.0m; @@ -45,7 +51,11 @@ public static class DecimalExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this decimal value) { return !value.IsEven(); @@ -57,7 +67,11 @@ public static class DecimalExtensions /// The value to round. /// rounded to the nearest whole number. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static decimal Round(this decimal value) { return value.Round(1.0m); @@ -70,7 +84,11 @@ public static class DecimalExtensions /// The nearest multiple to which should be rounded. /// rounded to the nearest multiple of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static decimal Round(this decimal value, decimal nearest) { return System.Math.Round(value / nearest) * nearest; @@ -104,7 +122,11 @@ public static class DecimalExtensions /// /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Sign(this decimal value) { return System.Math.Sign(value); @@ -138,13 +160,12 @@ public static class DecimalExtensions /// /// /// is negative. - /// - /// For negative input, this method returns . To receive a complex number, see - /// . - /// - /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static decimal Sqrt(this decimal value) { switch (value) diff --git a/X10D/src/Math/DoubleExtensions.cs b/X10D/src/Math/DoubleExtensions.cs index 5b393a7..203eb4a 100644 --- a/X10D/src/Math/DoubleExtensions.cs +++ b/X10D/src/Math/DoubleExtensions.cs @@ -20,7 +20,11 @@ public static class DoubleExtensions /// is equal to , less than -1, or greater than 1, is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Acos(this double value) { return System.Math.Acos(value); @@ -38,7 +42,11 @@ public static class DoubleExtensions /// is less than 1 or equal to , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Acosh(this double value) { return System.Math.Acosh(value); @@ -56,7 +64,11 @@ public static class DoubleExtensions /// is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Asin(this double value) { return System.Math.Asin(value); @@ -74,7 +86,11 @@ public static class DoubleExtensions /// , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Asinh(this double value) { return System.Math.Asinh(value); @@ -91,7 +107,11 @@ public static class DoubleExtensions /// is equal to , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Atan(this double value) { return System.Math.Atan(value); @@ -110,12 +130,17 @@ public static class DoubleExtensions /// is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Atanh(this double value) { return System.Math.Atanh(value); } +#if NETCOREAPP3_0_OR_GREATER /// /// Returns the complex square root of this double-precision floating-point number. /// @@ -141,6 +166,7 @@ public static class DoubleExtensions return new Complex(0, System.Math.Sqrt(-value)); } } +#endif /// /// Returns the cosine of the specified angle. @@ -152,7 +178,11 @@ public static class DoubleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Cos(this double value) { return System.Math.Cos(value); @@ -169,7 +199,11 @@ public static class DoubleExtensions /// , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Cosh(this double value) { return System.Math.Cosh(value); @@ -181,7 +215,11 @@ public static class DoubleExtensions /// The angle in degrees to convert. /// The result of π * / 180. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double DegreesToRadians(this double value) { return value * (System.Math.PI / 180.0); @@ -196,7 +234,11 @@ public static class DoubleExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this double value) { return System.Math.Abs(value % 2.0) < double.Epsilon; @@ -211,7 +253,11 @@ public static class DoubleExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this double value) { return !value.IsEven(); @@ -223,7 +269,11 @@ public static class DoubleExtensions /// The angle in radians to convert. /// The result of π * / 180. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double RadiansToDegrees(this double value) { return value * (180.0 / System.Math.PI); @@ -235,7 +285,11 @@ public static class DoubleExtensions /// The value to round. /// rounded to the nearest whole number. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Round(this double value) { return value.Round(1.0); @@ -248,7 +302,11 @@ public static class DoubleExtensions /// The nearest multiple to which should be rounded. /// rounded to the nearest multiple of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Round(this double value, double nearest) { return System.Math.Round(value / nearest) * nearest; @@ -264,7 +322,11 @@ public static class DoubleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Sin(this double value) { return System.Math.Sin(value); @@ -280,7 +342,11 @@ public static class DoubleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Sinh(this double value) { return System.Math.Sinh(value); @@ -315,7 +381,11 @@ public static class DoubleExtensions /// /// is equal to . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Sign(this double value) { return System.Math.Sign(value); @@ -348,15 +418,14 @@ public static class DoubleExtensions /// /// /// - /// - /// For negative input, this method returns . To receive a complex number, see - /// . - /// - /// /// SLenik https://stackoverflow.com/a/6755197/1467293 /// CC BY-SA 3.0 [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Sqrt(this double value) { switch (value) @@ -395,7 +464,11 @@ public static class DoubleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Tan(this double value) { return System.Math.Tan(value); @@ -412,7 +485,11 @@ public static class DoubleExtensions /// , this method returns . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Tanh(this double value) { return System.Math.Tanh(value); diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index 731c285..50dd890 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -18,7 +18,11 @@ public static class Int16Extensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static short DigitalRoot(this short value) { short root = System.Math.Abs(value).Mod(9); @@ -32,7 +36,11 @@ public static class Int16Extensions /// The factorial of . /// is less than 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long Factorial(this short value) { if (value < 0) @@ -63,7 +71,11 @@ public static class Int16Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this short value) { return (value & 1) == 0; @@ -78,7 +90,11 @@ public static class Int16Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this short value) { return !value.IsEven(); @@ -92,7 +108,11 @@ public static class Int16Extensions /// if is prime; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsPrime(this short value) { return ((long)value).IsPrime(); @@ -113,7 +133,11 @@ public static class Int16Extensions /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 /// CC-BY-SA 2.5 [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static short Mod(this short dividend, short divisor) { int r = dividend % divisor; @@ -129,7 +153,11 @@ public static class Int16Extensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this short value) { return ((long)value).MultiplicativePersistence(); @@ -163,7 +191,11 @@ public static class Int16Extensions /// /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Sign(this short value) { return System.Math.Sign(value); diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index faaeb5d..86d3c2f 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -18,7 +18,11 @@ public static class Int32Extensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int DigitalRoot(this int value) { int root = System.Math.Abs(value).Mod(9); @@ -32,7 +36,11 @@ public static class Int32Extensions /// The factorial of . /// is less than 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long Factorial(this int value) { if (value < 0) @@ -63,7 +71,11 @@ public static class Int32Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this int value) { return (value & 1) == 0; @@ -78,7 +90,11 @@ public static class Int32Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this int value) { return !value.IsEven(); @@ -92,7 +108,11 @@ public static class Int32Extensions /// if is prime; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsPrime(this int value) { return ((long)value).IsPrime(); @@ -113,7 +133,11 @@ public static class Int32Extensions /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 /// CC-BY-SA 2.5 [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Mod(this int dividend, int divisor) { int r = dividend % divisor; @@ -129,7 +153,11 @@ public static class Int32Extensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this int value) { return ((long)value).MultiplicativePersistence(); @@ -163,7 +191,11 @@ public static class Int32Extensions /// /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Sign(this int value) { return System.Math.Sign(value); diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index 48d5ed3..51dfc75 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -18,7 +18,11 @@ public static class Int64Extensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long DigitalRoot(this long value) { long root = System.Math.Abs(value).Mod(9L); @@ -32,7 +36,11 @@ public static class Int64Extensions /// The factorial of . /// is less than 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long Factorial(this long value) { if (value < 0) @@ -63,7 +71,11 @@ public static class Int64Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this long value) { return (value & 1) == 0; @@ -78,7 +90,11 @@ public static class Int64Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this long value) { return !value.IsEven(); @@ -92,7 +108,11 @@ public static class Int64Extensions /// if is prime; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsPrime(this long value) { switch (value) @@ -138,7 +158,11 @@ public static class Int64Extensions /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 /// CC-BY-SA 2.5 [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long Mod(this long dividend, long divisor) { long r = dividend % divisor; @@ -154,7 +178,11 @@ public static class Int64Extensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this long value) { var persistence = 0; @@ -219,7 +247,11 @@ public static class Int64Extensions /// /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Sign(this long value) { return System.Math.Sign(value); diff --git a/X10D/src/Math/MathUtility.cs b/X10D/src/Math/MathUtility.cs index a7aa41c..8613219 100644 --- a/X10D/src/Math/MathUtility.cs +++ b/X10D/src/Math/MathUtility.cs @@ -18,7 +18,11 @@ public static class MathUtility /// The interpolation result as determined by (1 - alpha) * value + alpha * target. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Lerp(float value, float target, float alpha) { // rookie mistake: a + t * (b - a) @@ -36,7 +40,11 @@ public static class MathUtility /// The interpolation result as determined by (1 - alpha) * value + alpha * target. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static double Lerp(double value, double target, double alpha) { // rookie mistake: a + t * (b - a) diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index 8e640a0..07252ef 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -19,7 +19,11 @@ public static class SByteExtensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static sbyte DigitalRoot(this sbyte value) { int root = System.Math.Abs(value).Mod(9); @@ -33,7 +37,11 @@ public static class SByteExtensions /// The factorial of . /// is less than 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long Factorial(this sbyte value) { if (value < 0) @@ -64,7 +72,11 @@ public static class SByteExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this sbyte value) { return value % 2 == 0; @@ -79,7 +91,11 @@ public static class SByteExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this sbyte value) { return !value.IsEven(); @@ -93,7 +109,11 @@ public static class SByteExtensions /// if is prime; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsPrime(this sbyte value) { return ((long)value).IsPrime(); @@ -114,7 +134,11 @@ public static class SByteExtensions /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 /// CC-BY-SA 2.5 [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static sbyte Mod(this sbyte dividend, sbyte divisor) { int r = dividend % divisor; @@ -130,7 +154,11 @@ public static class SByteExtensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this sbyte value) { return ((long)value).MultiplicativePersistence(); @@ -164,7 +192,11 @@ public static class SByteExtensions /// /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Sign(this sbyte value) { return System.Math.Sign(value); diff --git a/X10D/src/Math/SingleExtensions.cs b/X10D/src/Math/SingleExtensions.cs index df6b8b8..d72360a 100644 --- a/X10D/src/Math/SingleExtensions.cs +++ b/X10D/src/Math/SingleExtensions.cs @@ -20,7 +20,11 @@ public static class SingleExtensions /// is equal to , less than -1, or greater than 1, is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Acos(this float value) { return MathF.Acos(value); @@ -38,7 +42,11 @@ public static class SingleExtensions /// is less than 1 or equal to , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Acosh(this float value) { return MathF.Acosh(value); @@ -56,7 +64,11 @@ public static class SingleExtensions /// is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Asin(this float value) { return MathF.Asin(value); @@ -74,7 +86,11 @@ public static class SingleExtensions /// , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Asinh(this float value) { return MathF.Asinh(value); @@ -91,7 +107,11 @@ public static class SingleExtensions /// is equal to , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Atan(this float value) { return MathF.Atan(value); @@ -110,12 +130,17 @@ public static class SingleExtensions /// is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Atanh(this float value) { return MathF.Atanh(value); } +#if NETCOREAPP3_0_OR_GREATER /// /// Returns the complex square root of this single-precision floating-point number. /// @@ -141,6 +166,7 @@ public static class SingleExtensions return new Complex(0, MathF.Sqrt(-value)); } } +#endif /// /// Returns the cosine of the specified angle. @@ -152,7 +178,11 @@ public static class SingleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Cos(this float value) { return MathF.Cos(value); @@ -169,7 +199,11 @@ public static class SingleExtensions /// , is returned. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Cosh(this float value) { return MathF.Cosh(value); @@ -181,7 +215,11 @@ public static class SingleExtensions /// The angle in degrees to convert. /// The result of π * / 180. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float DegreesToRadians(this float value) { return value * (MathF.PI / 180.0f); @@ -196,7 +234,11 @@ public static class SingleExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this float value) { return value % 2 == 0; @@ -211,7 +253,11 @@ public static class SingleExtensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this float value) { return !value.IsEven(); @@ -223,7 +269,11 @@ public static class SingleExtensions /// The angle in radians to convert. /// The result of π * / 180. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float RadiansToDegrees(this float value) { return value * (180.0f / MathF.PI); @@ -235,7 +285,11 @@ public static class SingleExtensions /// The value to round. /// rounded to the nearest whole number. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Round(this float value) { return value.Round(1.0f); @@ -248,7 +302,11 @@ public static class SingleExtensions /// The nearest multiple to which should be rounded. /// rounded to the nearest multiple of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Round(this float value, float nearest) { return MathF.Round(value / nearest) * nearest; @@ -282,7 +340,11 @@ public static class SingleExtensions /// /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Sign(this float value) { return MathF.Sign(value); @@ -315,15 +377,14 @@ public static class SingleExtensions /// /// /// - /// - /// For negative input, this method returns . To receive a complex number, see - /// . - /// - /// /// SLenik https://stackoverflow.com/a/6755197/1467293 /// CC BY-SA 3.0 [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Sqrt(this float value) { switch (value) @@ -362,7 +423,11 @@ public static class SingleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Sin(this float value) { return MathF.Sin(value); @@ -378,7 +443,11 @@ public static class SingleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Sinh(this float value) { return MathF.Sinh(value); @@ -394,7 +463,11 @@ public static class SingleExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Tan(this float value) { return MathF.Sin(value); @@ -411,7 +484,11 @@ public static class SingleExtensions /// , this method returns . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static float Tanh(this float value) { return MathF.Tanh(value); diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index e781942..dca43d9 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -19,7 +19,11 @@ public static class UInt16Extensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ushort DigitalRoot(this ushort value) { var root = (ushort)(value % 9); @@ -32,7 +36,11 @@ public static class UInt16Extensions /// The value whose factorial to compute. /// The factorial of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ulong Factorial(this ushort value) { if (value == 0) @@ -58,7 +66,11 @@ public static class UInt16Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this ushort value) { return (value & 1) == 0; @@ -72,7 +84,11 @@ public static class UInt16Extensions /// if is prime; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsPrime(this ushort value) { return ((ulong)value).IsPrime(); @@ -87,7 +103,11 @@ public static class UInt16Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this ushort value) { return !value.IsEven(); @@ -102,7 +122,11 @@ public static class UInt16Extensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this ushort value) { return ((ulong)value).MultiplicativePersistence(); diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index 65217a4..8b1ffa5 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -19,7 +19,11 @@ public static class UInt32Extensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static uint DigitalRoot(this uint value) { uint root = value % 9; @@ -32,7 +36,11 @@ public static class UInt32Extensions /// The value whose factorial to compute. /// The factorial of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ulong Factorial(this uint value) { if (value == 0) @@ -58,7 +66,11 @@ public static class UInt32Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this uint value) { return (value & 1) == 0; @@ -72,7 +84,11 @@ public static class UInt32Extensions /// if is prime; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsPrime(this uint value) { return ((ulong)value).IsPrime(); @@ -87,7 +103,11 @@ public static class UInt32Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this uint value) { return !value.IsEven(); @@ -102,7 +122,11 @@ public static class UInt32Extensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this uint value) { return ((ulong)value).MultiplicativePersistence(); diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index 08f88ba..d0f78bd 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -19,7 +19,11 @@ public static class UInt64Extensions /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ulong DigitalRoot(this ulong value) { ulong root = value % 9; @@ -32,7 +36,11 @@ public static class UInt64Extensions /// The value whose factorial to compute. /// The factorial of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ulong Factorial(this ulong value) { if (value == 0) @@ -58,7 +66,11 @@ public static class UInt64Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsEven(this ulong value) { return (value & 1) == 0; @@ -72,7 +84,11 @@ public static class UInt64Extensions /// if is prime; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsPrime(this ulong value) { switch (value) @@ -112,7 +128,11 @@ public static class UInt64Extensions /// otherwise. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsOdd(this ulong value) { return !value.IsEven(); @@ -127,7 +147,11 @@ public static class UInt64Extensions /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int MultiplicativePersistence(this ulong value) { var persistence = 0; diff --git a/X10D/src/Net/EndPointExtensions.cs b/X10D/src/Net/EndPointExtensions.cs index 81da9fc..b10de62 100644 --- a/X10D/src/Net/EndPointExtensions.cs +++ b/X10D/src/Net/EndPointExtensions.cs @@ -22,10 +22,21 @@ public static class EndPointExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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 { @@ -48,10 +59,21 @@ public static class EndPointExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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 9b2320b..8198b3b 100644 --- a/X10D/src/Net/IPAddressExtensions.cs +++ b/X10D/src/Net/IPAddressExtensions.cs @@ -19,10 +19,21 @@ public static class IPAddressExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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; } @@ -36,10 +47,21 @@ public static class IPAddressExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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/Net/Int16Extensions.cs b/X10D/src/Net/Int16Extensions.cs index 60b648b..699cef2 100644 --- a/X10D/src/Net/Int16Extensions.cs +++ b/X10D/src/Net/Int16Extensions.cs @@ -15,7 +15,11 @@ public static class Int16Extensions /// The value to convert, expressed in host byte order. /// An integer value, expressed in network byte order. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static short HostToNetworkOrder(this short value) { return IPAddress.HostToNetworkOrder(value); @@ -27,7 +31,11 @@ public static class Int16Extensions /// The value to convert, expressed in network byte order. /// An integer value, expressed in host byte order. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static short NetworkToHostOrder(this short value) { return IPAddress.NetworkToHostOrder(value); diff --git a/X10D/src/Net/Int32Extensions.cs b/X10D/src/Net/Int32Extensions.cs index 7c7acbe..8bf0f59 100644 --- a/X10D/src/Net/Int32Extensions.cs +++ b/X10D/src/Net/Int32Extensions.cs @@ -15,7 +15,11 @@ public static class Int32Extensions /// The value to convert, expressed in host byte order. /// An integer value, expressed in network byte order. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int HostToNetworkOrder(this int value) { return IPAddress.HostToNetworkOrder(value); @@ -27,7 +31,11 @@ public static class Int32Extensions /// The value to convert, expressed in network byte order. /// An integer value, expressed in host byte order. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int NetworkToHostOrder(this int value) { return IPAddress.NetworkToHostOrder(value); diff --git a/X10D/src/Net/Int64Extensions.cs b/X10D/src/Net/Int64Extensions.cs index a586ca8..ede22c4 100644 --- a/X10D/src/Net/Int64Extensions.cs +++ b/X10D/src/Net/Int64Extensions.cs @@ -15,7 +15,11 @@ public static class Int64Extensions /// The value to convert, expressed in host byte order. /// An integer value, expressed in network byte order. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long HostToNetworkOrder(this long value) { return IPAddress.HostToNetworkOrder(value); @@ -27,7 +31,11 @@ public static class Int64Extensions /// The value to convert, expressed in network byte order. /// An integer value, expressed in host byte order. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long NetworkToHostOrder(this long value) { return IPAddress.NetworkToHostOrder(value); diff --git a/X10D/src/Numerics/ByteExtensions.cs b/X10D/src/Numerics/ByteExtensions.cs index ccd97a3..02c6e74 100644 --- a/X10D/src/Numerics/ByteExtensions.cs +++ b/X10D/src/Numerics/ByteExtensions.cs @@ -18,7 +18,11 @@ public static class ByteExtensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static byte RotateLeft(this byte value, int count) { count = count.Mod(8); @@ -34,7 +38,11 @@ public static class ByteExtensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static byte RotateRight(this byte value, int count) { count = count.Mod(8); diff --git a/X10D/src/Numerics/Int16Extensions.cs b/X10D/src/Numerics/Int16Extensions.cs index 789eeb5..1a3656b 100644 --- a/X10D/src/Numerics/Int16Extensions.cs +++ b/X10D/src/Numerics/Int16Extensions.cs @@ -17,7 +17,11 @@ public static class Int16Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static short RotateLeft(this short value, int count) { var unsigned = unchecked((ushort)value); @@ -33,7 +37,11 @@ public static class Int16Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static short RotateRight(this short value, int count) { var unsigned = unchecked((ushort)value); diff --git a/X10D/src/Numerics/Int32Extensions.cs b/X10D/src/Numerics/Int32Extensions.cs index 75dfea8..3bf74b9 100644 --- a/X10D/src/Numerics/Int32Extensions.cs +++ b/X10D/src/Numerics/Int32Extensions.cs @@ -17,7 +17,11 @@ public static class Int32Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int RotateLeft(this int value, int count) { var unsigned = unchecked((uint)value); @@ -33,7 +37,11 @@ public static class Int32Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int RotateRight(this int value, int count) { var unsigned = unchecked((uint)value); diff --git a/X10D/src/Numerics/Int64Extensions.cs b/X10D/src/Numerics/Int64Extensions.cs index 5f25a59..695ed4b 100644 --- a/X10D/src/Numerics/Int64Extensions.cs +++ b/X10D/src/Numerics/Int64Extensions.cs @@ -17,7 +17,11 @@ public static class Int64Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long RotateLeft(this long value, int count) { var unsigned = unchecked((ulong)value); @@ -33,7 +37,11 @@ public static class Int64Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long RotateRight(this long value, int count) { var unsigned = unchecked((ulong)value); diff --git a/X10D/src/Numerics/RandomExtensions.cs b/X10D/src/Numerics/RandomExtensions.cs index ef94c17..cdf464f 100644 --- a/X10D/src/Numerics/RandomExtensions.cs +++ b/X10D/src/Numerics/RandomExtensions.cs @@ -19,7 +19,14 @@ 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); @@ -39,7 +46,14 @@ public static class RandomExtensions /// is . public static Quaternion NextRotationUniform(this Random random) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif int seed = random.Next(); var seededRandom = new Random(seed); @@ -68,7 +82,14 @@ public static class RandomExtensions /// public static Vector2 NextUnitVector2(this Random random) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif // no need to construct a seeded random here, since we only call Next once @@ -89,7 +110,14 @@ public static class RandomExtensions /// public static Vector3 NextUnitVector3(this Random random) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(random); +#else + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } +#endif int seed = random.Next(); var seededRandom = new Random(seed); diff --git a/X10D/src/Numerics/SByteExtensions.cs b/X10D/src/Numerics/SByteExtensions.cs index e3d9d24..eb6ce07 100644 --- a/X10D/src/Numerics/SByteExtensions.cs +++ b/X10D/src/Numerics/SByteExtensions.cs @@ -18,7 +18,11 @@ public static class SByteExtensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static sbyte RotateLeft(this sbyte value, int count) { var signed = unchecked((byte)value); @@ -34,7 +38,11 @@ public static class SByteExtensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static sbyte RotateRight(this sbyte value, int count) { var signed = unchecked((byte)value); diff --git a/X10D/src/Numerics/UInt16Extensions.cs b/X10D/src/Numerics/UInt16Extensions.cs index 1cd8c8d..54403c9 100644 --- a/X10D/src/Numerics/UInt16Extensions.cs +++ b/X10D/src/Numerics/UInt16Extensions.cs @@ -18,7 +18,11 @@ public static class UInt16Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ushort RotateLeft(this ushort value, int count) { return (ushort)((ushort)(value << count) | (ushort)(value >> (16 - count))); @@ -33,7 +37,11 @@ public static class UInt16Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ushort RotateRight(this ushort value, int count) { return (ushort)((ushort)(value >> count) | (ushort)(value << (16 - count))); diff --git a/X10D/src/Numerics/UInt32Extensions.cs b/X10D/src/Numerics/UInt32Extensions.cs index d5b619c..7381b1b 100644 --- a/X10D/src/Numerics/UInt32Extensions.cs +++ b/X10D/src/Numerics/UInt32Extensions.cs @@ -1,5 +1,4 @@ using System.Diagnostics.Contracts; -using System.Numerics; using System.Runtime.CompilerServices; namespace X10D.Numerics; @@ -19,10 +18,14 @@ public static class UInt32Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static uint RotateLeft(this uint value, int count) { - return BitOperations.RotateLeft(value, count); + return (value << count) | (value >> (32 - count)); } /// @@ -34,9 +37,13 @@ public static class UInt32Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static uint RotateRight(this uint value, int count) { - return BitOperations.RotateRight(value, count); + return (value >> count) | (value << (32 - count)); } } diff --git a/X10D/src/Numerics/UInt64Extensions.cs b/X10D/src/Numerics/UInt64Extensions.cs index 709ca93..d41d6e2 100644 --- a/X10D/src/Numerics/UInt64Extensions.cs +++ b/X10D/src/Numerics/UInt64Extensions.cs @@ -1,5 +1,4 @@ using System.Diagnostics.Contracts; -using System.Numerics; using System.Runtime.CompilerServices; namespace X10D.Numerics; @@ -19,10 +18,14 @@ public static class UInt64Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ulong RotateLeft(this ulong value, int count) { - return BitOperations.RotateLeft(value, count); + return (value << count) | (value >> (64 - count)); } /// @@ -34,9 +37,13 @@ public static class UInt64Extensions /// /// The rotated value. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static ulong RotateRight(this ulong value, int count) { - return BitOperations.RotateRight(value, count); + return (value >> count) | (value << (32 - count)); } } diff --git a/X10D/src/Reflection/MemberInfoExtensions.cs b/X10D/src/Reflection/MemberInfoExtensions.cs index 826759c..5c9bc7e 100644 --- a/X10D/src/Reflection/MemberInfoExtensions.cs +++ b/X10D/src/Reflection/MemberInfoExtensions.cs @@ -21,11 +21,22 @@ public static class MemberInfoExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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 member.HasCustomAttribute(typeof(T)); } @@ -41,11 +52,29 @@ public static class MemberInfoExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool HasCustomAttribute(this MemberInfo member, Type attribute) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(member); +#else + if (member is null) + { + throw new ArgumentNullException(nameof(member)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(attribute); +#else + if (attribute is null) + { + throw new ArgumentNullException(nameof(attribute)); + } +#endif if (!attribute.Inherits()) { @@ -75,8 +104,22 @@ public static class MemberInfoExtensions Func selector) where TAttribute : Attribute { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(member); +#else + if (member is null) + { + throw new ArgumentNullException(nameof(member)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(selector); +#else + if (selector is null) + { + throw new ArgumentNullException(nameof(selector)); + } +#endif return member.SelectFromCustomAttribute(selector, default); } @@ -101,8 +144,22 @@ public static class MemberInfoExtensions Func selector, TReturn? defaultValue) where TAttribute : Attribute { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(member); +#else + if (member is null) + { + throw new ArgumentNullException(nameof(member)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(selector); +#else + if (selector is null) + { + throw new ArgumentNullException(nameof(selector)); + } +#endif return member.GetCustomAttribute() is { } attribute ? selector(attribute) diff --git a/X10D/src/Reflection/TypeExtensions.cs b/X10D/src/Reflection/TypeExtensions.cs index 001abc8..9d53c39 100644 --- a/X10D/src/Reflection/TypeExtensions.cs +++ b/X10D/src/Reflection/TypeExtensions.cs @@ -17,10 +17,21 @@ public static class TypeExtensions /// if the current exists on the type; otherwise, . /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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)); } @@ -37,11 +48,29 @@ public static class TypeExtensions /// is . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool Implements(this Type value, Type interfaceType) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(value); +#else + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(interfaceType); +#else + if (interfaceType is null) + { + throw new ArgumentNullException(nameof(interfaceType)); + } +#endif if (!interfaceType.IsInterface) { @@ -66,11 +95,22 @@ public static class TypeExtensions /// is . /// is not a class. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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)); } @@ -95,11 +135,29 @@ public static class TypeExtensions /// is not a class. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool Inherits(this Type value, Type type) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(value); +#else + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(type); +#else + if (type is null) + { + throw new ArgumentNullException(nameof(type)); + } +#endif if (!value.IsClass) { diff --git a/X10D/src/Text/CharExtensions.cs b/X10D/src/Text/CharExtensions.cs index 9d59738..c16e201 100644 --- a/X10D/src/Text/CharExtensions.cs +++ b/X10D/src/Text/CharExtensions.cs @@ -17,7 +17,11 @@ public static class CharExtensions /// A composed of repeated times. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static string Repeat(this char value, int count) { return count switch diff --git a/X10D/src/Text/Extensions.cs b/X10D/src/Text/Extensions.cs index 574083c..97e434c 100644 --- a/X10D/src/Text/Extensions.cs +++ b/X10D/src/Text/Extensions.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.Contracts; +#if NET5_0_OR_GREATER +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Text.Json; @@ -23,3 +24,4 @@ public static class Extensions return JsonSerializer.Serialize(value, options); } } +#endif diff --git a/X10D/src/Text/RuneExtensions.cs b/X10D/src/Text/RuneExtensions.cs index 5c0b146..0a70866 100644 --- a/X10D/src/Text/RuneExtensions.cs +++ b/X10D/src/Text/RuneExtensions.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.Contracts; +#if NETCOREAPP3_0_OR_GREATER +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Text; @@ -44,3 +45,4 @@ public static class RuneExtensions return Encoding.UTF8.GetString(buffer); } } +#endif diff --git a/X10D/src/Text/StringExtensions.cs b/X10D/src/Text/StringExtensions.cs index ba9a97e..c4cdfa0 100644 --- a/X10D/src/Text/StringExtensions.cs +++ b/X10D/src/Text/StringExtensions.cs @@ -2,7 +2,9 @@ using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Text; +#if NET5_0_OR_GREATER using System.Text.Json; +#endif using X10D.Collections; using X10D.Core; using X10D.IO; @@ -23,7 +25,11 @@ public static class StringExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif [return: NotNullIfNotNull("value")] public static string? AsNullIfEmpty(this string? value) { @@ -40,7 +46,11 @@ public static class StringExtensions /// whitespace; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif [return: NotNullIfNotNull("value")] public static string? AsNullIfWhiteSpace(this string? value) { @@ -54,10 +64,21 @@ public static class StringExtensions /// The plain text string representation of . /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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); } @@ -69,10 +90,21 @@ public static class StringExtensions /// The string representation, in base 64, of . /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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)); } @@ -95,12 +127,37 @@ public static class StringExtensions /// is . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static string ChangeEncoding(this string value, Encoding sourceEncoding, Encoding destinationEncoding) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(value); +#else + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(sourceEncoding); +#else + if (sourceEncoding is null) + { + throw new ArgumentNullException(nameof(sourceEncoding)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(destinationEncoding); +#else + if (destinationEncoding is null) + { + throw new ArgumentNullException(nameof(destinationEncoding)); + } +#endif return value.GetBytes(sourceEncoding).ToString(destinationEncoding); } @@ -116,7 +173,11 @@ public static class StringExtensions /// (http://geekswithblogs.net/sdorman/Default.aspx). /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static T EnumParse(this string value) where T : struct, Enum { @@ -135,11 +196,22 @@ public static class StringExtensions /// (http://geekswithblogs.net/sdorman/Default.aspx). /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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(); @@ -151,6 +223,7 @@ public static class StringExtensions return Enum.Parse(value, ignoreCase); } +#if NET5_0_OR_GREATER /// /// Returns an object from the specified JSON string. /// @@ -161,11 +234,11 @@ public static class StringExtensions /// An object constructed from the JSON string, or if deserialization could not be performed. /// [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static T? FromJson(this string value, JsonSerializerOptions? options = null) { return JsonSerializer.Deserialize(value, options); } +#endif /// /// Gets a [] representing the value the with @@ -174,7 +247,11 @@ public static class StringExtensions /// The string to convert. /// Returns a []. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static byte[] GetBytes(this string value) { return value.GetBytes(Encoding.UTF8); @@ -191,11 +268,29 @@ public static class StringExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static byte[] GetBytes(this string value, Encoding encoding) { +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(value); +#else + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } +#endif +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(encoding); +#else + if (encoding is null) + { + throw new ArgumentNullException(nameof(encoding)); + } +#endif return encoding.GetBytes(value); } @@ -208,13 +303,25 @@ public static class StringExtensions /// if all alpha characters in this string are lowercase; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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++) { +#if NETCOREAPP3_0_OR_GREATER var rune = new Rune(value[index]); if (!Rune.IsLetter(rune)) @@ -226,6 +333,19 @@ public static class StringExtensions { return false; } +#else + char current = value[index]; + + if (!char.IsLetter(current)) + { + continue; + } + + if (!char.IsLower(current)) + { + return false; + } +#endif } return true; @@ -242,10 +362,21 @@ public static class StringExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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)) { @@ -255,6 +386,7 @@ public static class StringExtensions for (int index = 0, endIndex = value.Length - 1; index < value.Length; index++, endIndex--) { +#if NETCOREAPP3_0_OR_GREATER Rune startRune = new Rune(value[index]); Rune endRune = new Rune(value[endIndex]); @@ -274,6 +406,27 @@ public static class StringExtensions { return false; } +#else + char startChar = value[index]; + char endChar = value[endIndex]; + + if (!char.IsLetter(startChar) && !char.IsNumber(startChar)) + { + endIndex++; + continue; + } + + if (!char.IsLetter(endChar) && !char.IsNumber(endChar)) + { + index--; + continue; + } + + if (char.ToUpperInvariant(startChar) != char.ToUpperInvariant(endChar)) + { + return false; + } +#endif } return true; @@ -287,13 +440,25 @@ public static class StringExtensions /// if all alpha characters in this string are uppercase; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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++) { +#if NETCOREAPP3_0_OR_GREATER var rune = new Rune(value[index]); if (!Rune.IsLetter(rune)) @@ -305,6 +470,19 @@ public static class StringExtensions { return false; } +#else + char current = value[index]; + + if (!char.IsLetter(current)) + { + continue; + } + + if (!char.IsUpper(current)) + { + return false; + } +#endif } return true; @@ -319,10 +497,21 @@ public static class StringExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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) { @@ -357,10 +546,21 @@ public static class StringExtensions /// is . /// is less than 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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) { @@ -372,7 +572,7 @@ public static class StringExtensions return string.Empty; } - random ??= Random.Shared; + random ??= RandomExtensions.GetShared(); char[] array = source.ToCharArray(); var builder = new StringBuilder(length); @@ -392,10 +592,21 @@ public static class StringExtensions /// The string to reverse. /// A whose characters are that of in reverse order. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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) { @@ -417,18 +628,29 @@ public static class StringExtensions /// /// The string to shuffle. /// - /// The instance to use for the shuffling. If is specified, - /// is used. + /// The instance to use for the shuffling. If is specified, a shared + /// instance is used. /// /// A new containing the characters in , rearranged. /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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 ??= Random.Shared; + random ??= RandomExtensions.GetShared(); char[] array = value.ToCharArray(); array.Shuffle(random); @@ -446,10 +668,21 @@ public static class StringExtensions /// /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif 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) { @@ -473,7 +706,11 @@ public static class StringExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif [return: NotNullIfNotNull("alternative")] public static string? WithEmptyAlternative(this string? value, string? alternative) { @@ -491,7 +728,11 @@ public static class StringExtensions /// whitespace; otherwise, . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif [return: NotNullIfNotNull("alternative")] public static string? WithWhiteSpaceAlternative(this string? value, string? alternative) { diff --git a/X10D/src/Time/ByteExtensions.cs b/X10D/src/Time/ByteExtensions.cs index b15a91d..7273fce 100644 --- a/X10D/src/Time/ByteExtensions.cs +++ b/X10D/src/Time/ByteExtensions.cs @@ -17,7 +17,11 @@ public static class ByteExtensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this byte value) { if (value == 0) @@ -43,7 +47,11 @@ public static class ByteExtensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this byte value) { return DateTimeOffset.FromUnixTimeMilliseconds(value); @@ -64,7 +72,11 @@ public static class ByteExtensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this byte value) { return DateTimeOffset.FromUnixTimeSeconds(value); @@ -76,7 +88,11 @@ public static class ByteExtensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this byte value) { return TimeSpan.FromTicks(value); @@ -90,7 +106,11 @@ public static class ByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this byte value) { return TimeSpan.FromMilliseconds(value); @@ -104,7 +124,11 @@ public static class ByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this byte value) { return TimeSpan.FromSeconds(value); @@ -118,7 +142,11 @@ public static class ByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this byte value) { return TimeSpan.FromMinutes(value); @@ -132,7 +160,11 @@ public static class ByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this byte value) { return TimeSpan.FromHours(value); @@ -144,7 +176,11 @@ public static class ByteExtensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this byte value) { return TimeSpan.FromDays(value); @@ -158,7 +194,11 @@ public static class ByteExtensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this byte value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/DateTimeExtensions.cs b/X10D/src/Time/DateTimeExtensions.cs index b546722..f06a4f0 100644 --- a/X10D/src/Time/DateTimeExtensions.cs +++ b/X10D/src/Time/DateTimeExtensions.cs @@ -10,7 +10,11 @@ public static class DateTimeExtensions { /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Age(this DateTime value) { return value.Age(DateTime.Today); @@ -18,7 +22,11 @@ public static class DateTimeExtensions /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Age(this DateTime value, DateTime asOf) { return ((DateTimeOffset)value).Age(asOf); @@ -27,7 +35,11 @@ public static class DateTimeExtensions /// /// A representing the first occurence of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTime First(this DateTime value, DayOfWeek dayOfWeek) { return ((DateTimeOffset)value).First(dayOfWeek).DateTime; @@ -36,7 +48,11 @@ public static class DateTimeExtensions /// /// A representing the first day of the current month. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTime FirstDayOfMonth(this DateTime value) { return ((DateTimeOffset)value).FirstDayOfMonth().DateTime; @@ -51,7 +67,11 @@ public static class DateTimeExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this DateTime value) { return DateTime.IsLeapYear(value.Year); @@ -60,7 +80,11 @@ public static class DateTimeExtensions /// /// A representing the final occurence of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTime Last(this DateTime value, DayOfWeek dayOfWeek) { return ((DateTimeOffset)value).Last(dayOfWeek).DateTime; @@ -69,7 +93,11 @@ public static class DateTimeExtensions /// /// A representing the last day of the current month. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTime LastDayOfMonth(this DateTime value) { return ((DateTimeOffset)value).LastDayOfMonth().DateTime; @@ -78,7 +106,11 @@ public static class DateTimeExtensions /// /// A representing the next occurence of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTime Next(this DateTime value, DayOfWeek dayOfWeek) { return ((DateTimeOffset)value).Next(dayOfWeek).DateTime; @@ -90,7 +122,11 @@ public static class DateTimeExtensions /// The current date. /// The number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long ToUnixTimeMilliseconds(this DateTime value) { return ((DateTimeOffset)value).ToUnixTimeMilliseconds(); @@ -102,7 +138,11 @@ public static class DateTimeExtensions /// The current date. /// The number of seconds that have elapsed since 1970-01-01T00:00:00.000Z. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static long ToUnixTimeSeconds(this DateTime value) { return ((DateTimeOffset)value).ToUnixTimeSeconds(); diff --git a/X10D/src/Time/DateTimeOffsetExtensions.cs b/X10D/src/Time/DateTimeOffsetExtensions.cs index ca06ec0..e30560b 100644 --- a/X10D/src/Time/DateTimeOffsetExtensions.cs +++ b/X10D/src/Time/DateTimeOffsetExtensions.cs @@ -14,7 +14,11 @@ public static class DateTimeOffsetExtensions /// The date from which to calculate. /// The rounded-down integer number of years since as of today. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Age(this DateTimeOffset value) { return value.Age(DateTime.Today); @@ -30,7 +34,11 @@ public static class DateTimeOffsetExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static int Age(this DateTimeOffset value, DateTimeOffset asOf) { return (int)(((asOf.Date - TimeSpan.FromDays(1) - value.Date).TotalDays + 1) / 365.2425); @@ -43,7 +51,11 @@ public static class DateTimeOffsetExtensions /// The day of the week. /// A representing the first occurence of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset First(this DateTimeOffset value, DayOfWeek dayOfWeek) { var first = value.FirstDayOfMonth(); @@ -62,7 +74,11 @@ public static class DateTimeOffsetExtensions /// The current date. /// A representing the first day of the current month. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FirstDayOfMonth(this DateTimeOffset value) { return value.AddDays(1 - value.Day); @@ -77,7 +93,11 @@ public static class DateTimeOffsetExtensions /// . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this DateTimeOffset value) { return DateTime.IsLeapYear(value.Year); @@ -90,7 +110,11 @@ public static class DateTimeOffsetExtensions /// The day of the week. /// A representing the final occurence of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset Last(this DateTimeOffset value, DayOfWeek dayOfWeek) { var last = value.LastDayOfMonth(); @@ -108,7 +132,11 @@ public static class DateTimeOffsetExtensions /// The current date. /// A representing the last day of the current month. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset LastDayOfMonth(this DateTimeOffset value) { int daysInMonth = DateTime.DaysInMonth(value.Year, value.Month); @@ -122,7 +150,11 @@ public static class DateTimeOffsetExtensions /// The day of the week. /// A representing the next occurence of . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset Next(this DateTimeOffset value, DayOfWeek dayOfWeek) { int offsetDays = dayOfWeek - value.DayOfWeek; diff --git a/X10D/src/Time/DecimalExtensions.cs b/X10D/src/Time/DecimalExtensions.cs index 880e1a9..ee1318f 100644 --- a/X10D/src/Time/DecimalExtensions.cs +++ b/X10D/src/Time/DecimalExtensions.cs @@ -16,7 +16,11 @@ public static class DecimalExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this decimal value) { return TimeSpan.FromMilliseconds((double)value); @@ -30,7 +34,11 @@ public static class DecimalExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this decimal value) { return TimeSpan.FromSeconds((double)value); @@ -44,7 +52,11 @@ public static class DecimalExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this decimal value) { return TimeSpan.FromMinutes((double)value); @@ -58,7 +70,11 @@ public static class DecimalExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this decimal value) { return TimeSpan.FromHours((double)value); @@ -70,7 +86,11 @@ public static class DecimalExtensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this decimal value) { return TimeSpan.FromDays((double)value); @@ -84,7 +104,11 @@ public static class DecimalExtensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this decimal value) { return TimeSpan.FromDays((double)value * 7); diff --git a/X10D/src/Time/DoubleExtensions.cs b/X10D/src/Time/DoubleExtensions.cs index 81d6b38..6b16e76 100644 --- a/X10D/src/Time/DoubleExtensions.cs +++ b/X10D/src/Time/DoubleExtensions.cs @@ -16,7 +16,11 @@ public static class DoubleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this double value) { return TimeSpan.FromMilliseconds(value); @@ -30,7 +34,11 @@ public static class DoubleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this double value) { return TimeSpan.FromSeconds(value); @@ -44,7 +52,11 @@ public static class DoubleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this double value) { return TimeSpan.FromMinutes(value); @@ -58,7 +70,11 @@ public static class DoubleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this double value) { return TimeSpan.FromHours(value); @@ -70,7 +86,11 @@ public static class DoubleExtensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this double value) { return TimeSpan.FromDays(value); @@ -84,7 +104,11 @@ public static class DoubleExtensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this double value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/HalfExtensions.cs b/X10D/src/Time/HalfExtensions.cs index 396fc68..e217ea9 100644 --- a/X10D/src/Time/HalfExtensions.cs +++ b/X10D/src/Time/HalfExtensions.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.Contracts; +#if NET5_0_OR_GREATER +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace X10D.Time; @@ -90,3 +91,4 @@ public static class HalfExtensions return TimeSpan.FromDays((float)value * 7); } } +#endif diff --git a/X10D/src/Time/Int16Extensions.cs b/X10D/src/Time/Int16Extensions.cs index bfc1605..a0fbb7d 100644 --- a/X10D/src/Time/Int16Extensions.cs +++ b/X10D/src/Time/Int16Extensions.cs @@ -18,7 +18,11 @@ public static class Int16Extensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this short value) { if (value == 0) @@ -49,7 +53,11 @@ public static class Int16Extensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this short value) { return DateTimeOffset.FromUnixTimeMilliseconds(value); @@ -70,7 +78,11 @@ public static class Int16Extensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this short value) { return DateTimeOffset.FromUnixTimeSeconds(value); @@ -82,7 +94,11 @@ public static class Int16Extensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this short value) { return TimeSpan.FromTicks(value); @@ -96,7 +112,11 @@ public static class Int16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this short value) { return TimeSpan.FromMilliseconds(value); @@ -110,7 +130,11 @@ public static class Int16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this short value) { return TimeSpan.FromSeconds(value); @@ -124,7 +148,11 @@ public static class Int16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this short value) { return TimeSpan.FromMinutes(value); @@ -138,7 +166,11 @@ public static class Int16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this short value) { return TimeSpan.FromHours(value); @@ -150,7 +182,11 @@ public static class Int16Extensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this short value) { return TimeSpan.FromDays(value); @@ -164,7 +200,11 @@ public static class Int16Extensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this short value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/Int32Extensions.cs b/X10D/src/Time/Int32Extensions.cs index 576f84f..6811b82 100644 --- a/X10D/src/Time/Int32Extensions.cs +++ b/X10D/src/Time/Int32Extensions.cs @@ -18,7 +18,11 @@ public static class Int32Extensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this int value) { if (value == 0) @@ -49,7 +53,11 @@ public static class Int32Extensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this int value) { return DateTimeOffset.FromUnixTimeMilliseconds(value); @@ -70,7 +78,11 @@ public static class Int32Extensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this int value) { return DateTimeOffset.FromUnixTimeSeconds(value); @@ -82,7 +94,11 @@ public static class Int32Extensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this int value) { return TimeSpan.FromTicks(value); @@ -96,7 +112,11 @@ public static class Int32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this int value) { return TimeSpan.FromMilliseconds(value); @@ -110,7 +130,11 @@ public static class Int32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this int value) { return TimeSpan.FromSeconds(value); @@ -124,7 +148,11 @@ public static class Int32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this int value) { return TimeSpan.FromMinutes(value); @@ -138,7 +166,11 @@ public static class Int32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this int value) { return TimeSpan.FromHours(value); @@ -150,7 +182,11 @@ public static class Int32Extensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this int value) { return TimeSpan.FromDays(value); @@ -164,7 +200,11 @@ public static class Int32Extensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this int value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/Int64Extensions.cs b/X10D/src/Time/Int64Extensions.cs index f07969c..8f6ea07 100644 --- a/X10D/src/Time/Int64Extensions.cs +++ b/X10D/src/Time/Int64Extensions.cs @@ -18,7 +18,11 @@ public static class Int64Extensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this long value) { if (value == 0) @@ -49,7 +53,11 @@ public static class Int64Extensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this long value) { return DateTimeOffset.FromUnixTimeMilliseconds(value); @@ -70,7 +78,11 @@ public static class Int64Extensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this long value) { return DateTimeOffset.FromUnixTimeSeconds(value); @@ -82,7 +94,11 @@ public static class Int64Extensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this long value) { return TimeSpan.FromTicks(value); @@ -96,7 +112,11 @@ public static class Int64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this long value) { return TimeSpan.FromMilliseconds(value); @@ -110,7 +130,11 @@ public static class Int64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this long value) { return TimeSpan.FromSeconds(value); @@ -124,7 +148,11 @@ public static class Int64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this long value) { return TimeSpan.FromMinutes(value); @@ -138,7 +166,11 @@ public static class Int64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this long value) { return TimeSpan.FromHours(value); @@ -150,7 +182,11 @@ public static class Int64Extensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this long value) { return TimeSpan.FromDays(value); @@ -164,7 +200,11 @@ public static class Int64Extensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this long value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/SByteExtensions.cs b/X10D/src/Time/SByteExtensions.cs index 606df12..926c894 100644 --- a/X10D/src/Time/SByteExtensions.cs +++ b/X10D/src/Time/SByteExtensions.cs @@ -19,7 +19,11 @@ public static class SByteExtensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this sbyte value) { if (value == 0) @@ -50,7 +54,11 @@ public static class SByteExtensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this sbyte value) { return DateTimeOffset.FromUnixTimeMilliseconds(value); @@ -71,7 +79,11 @@ public static class SByteExtensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this sbyte value) { return DateTimeOffset.FromUnixTimeSeconds(value); @@ -83,7 +95,11 @@ public static class SByteExtensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this sbyte value) { return TimeSpan.FromTicks(value); @@ -97,7 +113,11 @@ public static class SByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this sbyte value) { return TimeSpan.FromMilliseconds(value); @@ -111,7 +131,11 @@ public static class SByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this sbyte value) { return TimeSpan.FromSeconds(value); @@ -125,7 +149,11 @@ public static class SByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this sbyte value) { return TimeSpan.FromMinutes(value); @@ -139,7 +167,11 @@ public static class SByteExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this sbyte value) { return TimeSpan.FromHours(value); @@ -151,7 +183,11 @@ public static class SByteExtensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this sbyte value) { return TimeSpan.FromDays(value); @@ -165,7 +201,11 @@ public static class SByteExtensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this sbyte value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/SingleExtensions.cs b/X10D/src/Time/SingleExtensions.cs index f1d0546..f3e546c 100644 --- a/X10D/src/Time/SingleExtensions.cs +++ b/X10D/src/Time/SingleExtensions.cs @@ -16,7 +16,11 @@ public static class SingleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this float value) { return TimeSpan.FromMilliseconds(value); @@ -30,7 +34,11 @@ public static class SingleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this float value) { return TimeSpan.FromSeconds(value); @@ -44,7 +52,11 @@ public static class SingleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this float value) { return TimeSpan.FromMinutes(value); @@ -58,7 +70,11 @@ public static class SingleExtensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this float value) { return TimeSpan.FromHours(value); @@ -70,7 +86,11 @@ public static class SingleExtensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this float value) { return TimeSpan.FromDays(value); @@ -84,7 +104,11 @@ public static class SingleExtensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this float value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/StringExtensions.cs b/X10D/src/Time/StringExtensions.cs index cf22f71..ea3eb77 100644 --- a/X10D/src/Time/StringExtensions.cs +++ b/X10D/src/Time/StringExtensions.cs @@ -57,7 +57,11 @@ public static class StringExtensions /// A new instance of . /// is . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan ToTimeSpan(this string input) { if (input is null) diff --git a/X10D/src/Time/TimeSpanExtensions.cs b/X10D/src/Time/TimeSpanExtensions.cs index d9424f1..1e3a500 100644 --- a/X10D/src/Time/TimeSpanExtensions.cs +++ b/X10D/src/Time/TimeSpanExtensions.cs @@ -16,7 +16,11 @@ public static class TimeSpanExtensions /// A that is a duration of in the past relative to the current time. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTime Ago(this TimeSpan value) { return DateTime.Now.Subtract(value); @@ -30,7 +34,11 @@ public static class TimeSpanExtensions /// A that is a duration of in the future relative to the current time. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTime FromNow(this TimeSpan value) { return DateTime.Now.Add(value); diff --git a/X10D/src/Time/UInt16Extensions.cs b/X10D/src/Time/UInt16Extensions.cs index b0ee2c9..d8eec67 100644 --- a/X10D/src/Time/UInt16Extensions.cs +++ b/X10D/src/Time/UInt16Extensions.cs @@ -24,7 +24,11 @@ public static class UInt16Extensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this ushort value) { return DateTimeOffset.FromUnixTimeMilliseconds(value); @@ -45,7 +49,11 @@ public static class UInt16Extensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this ushort value) { return DateTimeOffset.FromUnixTimeSeconds(value); @@ -60,7 +68,11 @@ public static class UInt16Extensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this ushort value) { if (value == 0) @@ -77,7 +89,11 @@ public static class UInt16Extensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this ushort value) { return TimeSpan.FromTicks(value); @@ -91,7 +107,11 @@ public static class UInt16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this ushort value) { return TimeSpan.FromMilliseconds(value); @@ -105,7 +125,11 @@ public static class UInt16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this ushort value) { return TimeSpan.FromSeconds(value); @@ -119,7 +143,11 @@ public static class UInt16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this ushort value) { return TimeSpan.FromMinutes(value); @@ -133,7 +161,11 @@ public static class UInt16Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this ushort value) { return TimeSpan.FromHours(value); @@ -145,7 +177,11 @@ public static class UInt16Extensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this ushort value) { return TimeSpan.FromDays(value); @@ -159,7 +195,11 @@ public static class UInt16Extensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this ushort value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/UInt32Extensions.cs b/X10D/src/Time/UInt32Extensions.cs index 9a4b09f..2f6fb81 100644 --- a/X10D/src/Time/UInt32Extensions.cs +++ b/X10D/src/Time/UInt32Extensions.cs @@ -24,7 +24,11 @@ public static class UInt32Extensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this uint value) { return DateTimeOffset.FromUnixTimeMilliseconds(value); @@ -45,7 +49,11 @@ public static class UInt32Extensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this uint value) { return DateTimeOffset.FromUnixTimeSeconds(value); @@ -60,7 +68,11 @@ public static class UInt32Extensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this uint value) { if (value == 0) @@ -77,7 +89,11 @@ public static class UInt32Extensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this uint value) { return TimeSpan.FromTicks(value); @@ -91,7 +107,11 @@ public static class UInt32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this uint value) { return TimeSpan.FromMilliseconds(value); @@ -105,7 +125,11 @@ public static class UInt32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this uint value) { return TimeSpan.FromSeconds(value); @@ -119,7 +143,11 @@ public static class UInt32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this uint value) { return TimeSpan.FromMinutes(value); @@ -133,7 +161,11 @@ public static class UInt32Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this uint value) { return TimeSpan.FromHours(value); @@ -145,7 +177,11 @@ public static class UInt32Extensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this uint value) { return TimeSpan.FromDays(value); @@ -159,7 +195,11 @@ public static class UInt32Extensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this uint value) { return TimeSpan.FromDays(value * 7); diff --git a/X10D/src/Time/UInt64Extensions.cs b/X10D/src/Time/UInt64Extensions.cs index 2dfb049..d415cbb 100644 --- a/X10D/src/Time/UInt64Extensions.cs +++ b/X10D/src/Time/UInt64Extensions.cs @@ -24,7 +24,11 @@ public static class UInt64Extensions /// is greater than 253,402,300,799,999. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeMilliseconds(this ulong value) { return DateTimeOffset.FromUnixTimeMilliseconds((long)value); @@ -45,7 +49,11 @@ public static class UInt64Extensions /// is greater than 253,402,300,799. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static DateTimeOffset FromUnixTimeSeconds(this ulong value) { return DateTimeOffset.FromUnixTimeSeconds((long)value); @@ -60,7 +68,11 @@ public static class UInt64Extensions /// /// is 0. [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static bool IsLeapYear(this ulong value) { if (value == 0) @@ -77,7 +89,11 @@ public static class UInt64Extensions /// The duration, in ticks. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Ticks(this ulong value) { return TimeSpan.FromTicks((long)value); @@ -91,7 +107,11 @@ public static class UInt64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Milliseconds(this ulong value) { return TimeSpan.FromMilliseconds((long)value); @@ -105,7 +125,11 @@ public static class UInt64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Seconds(this ulong value) { return TimeSpan.FromSeconds((long)value); @@ -119,7 +143,11 @@ public static class UInt64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Minutes(this ulong value) { return TimeSpan.FromMinutes((long)value); @@ -133,7 +161,11 @@ public static class UInt64Extensions /// A whose will equal . /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Hours(this ulong value) { return TimeSpan.FromHours((long)value); @@ -145,7 +177,11 @@ public static class UInt64Extensions /// The duration, in days. /// A whose will equal . [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Days(this ulong value) { return TimeSpan.FromDays((long)value); @@ -159,7 +195,11 @@ public static class UInt64Extensions /// A whose will equal × 7. /// [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif public static TimeSpan Weeks(this ulong value) { return TimeSpan.FromDays((long)value * 7);