1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 23:58:48 +00:00

Add .NET Standard 2.1 target, reintroduce Unity support

This commit is contained in:
Oliver Booth 2022-05-05 18:00:38 +01:00
parent 2d51f65834
commit f257aebc28
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
83 changed files with 3170 additions and 95 deletions

View File

@ -33,6 +33,7 @@ jobs:
run: | run: |
mkdir build 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 -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 - name: Push NuGet Package to GitHub
run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

View File

@ -32,6 +32,7 @@ jobs:
run: | run: |
mkdir build 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 -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 - name: Push NuGet Package to GitHub
run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

View File

@ -32,6 +32,7 @@ jobs:
run: | run: |
mkdir build mkdir build
dotnet pack X10D -p:SymbolPackageFormat=snupkg --include-symbols --include-source -o 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 - name: Push NuGet Package to GitHub
run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate run: dotnet nuget push "build/*" --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

View File

@ -32,5 +32,4 @@ jobs:
run: dotnet build -c Debug run: dotnet build -c Debug
- name: Run Source Validation - name: Run Source Validation
run: dotnet run --project X10D.SourceValidator ./X10D/src run: dotnet run --project X10D.SourceValidator ./X10D/src ./X10D.Unity/src

View File

@ -1,11 +1,13 @@
using System.Text; using System.Text;
var directories = new Stack<string>(Directory.GetDirectories(args[0]));
var problems = 0; var problems = 0;
var files = 0; foreach (string arg in args)
while (directories.Count > 0)
{ {
var directories = new Stack<string>(Directory.GetDirectories(arg));
var files = 0;
while (directories.Count > 0)
{
string path = Path.GetFullPath(directories.Pop()); string path = Path.GetFullPath(directories.Pop());
foreach (string directory in Directory.EnumerateDirectories(path)) foreach (string directory in Directory.EnumerateDirectories(path))
@ -58,7 +60,9 @@ while (directories.Count > 0)
lineNumber++; lineNumber++;
} }
} }
}
Console.Out.WriteLine($"Finished scanning {files} files, {problems} problems encountered.");
} }
Console.Out.WriteLine($"Finished scanning {files} files, {problems} problems encountered.");
return problems; return problems;

View File

@ -0,0 +1,65 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>10.0</LangVersion>
<Optimize>true</Optimize>
<ImplicitUsings>true</ImplicitUsings>
<Authors>Oliver Booth</Authors>
<NeutralLanguage>en</NeutralLanguage>
<RepositoryUrl>https://github.com/oliverbooth/X10D</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Description>Extension methods on crack.</Description>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
<PackageIconUrl />
<PackageTags>dotnet extension-methods</PackageTags>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<VersionPrefix>3.1.0</VersionPrefix>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' == ''">
<Version>$(VersionPrefix)-$(VersionSuffix)</Version>
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
<FileVersion>$(VersionPrefix).0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' != ''">
<Version>$(VersionPrefix)-$(VersionSuffix).$(BuildNumber)</Version>
<AssemblyVersion>$(VersionPrefix).$(BuildNumber)</AssemblyVersion>
<FileVersion>$(VersionPrefix).$(BuildNumber)</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(VersionSuffix)' == ''">
<Version>$(VersionPrefix)</Version>
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
<FileVersion>$(VersionPrefix).0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Unity3D.SDK" Version="2020.3.13.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\X10D\X10D.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="..\icon.png">
<Pack>True</Pack>
<PackagePath />
</None>
<None Include="..\LICENSE.md">
<Pack>True</Pack>
<PackagePath />
</None>
<None Include="..\CHANGELOG.md">
<Pack>True</Pack>
<PackagePath />
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,95 @@
using UnityEngine;
using X10D.Core;
using Random = System.Random;
namespace X10D.Unity.Drawing;
/// <summary>
/// Extension methods for <see cref="System.Random" />.
/// </summary>
public static class RandomExtensions
{
/// <summary>
/// Returns an HDR color of random components for red, green, and blue.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>A <see cref="Color" /> whose red, green, and blue components are all random, and whose alpha is 255</returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
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);
}
/// <summary>
/// Returns an HDR color composed of random components for apha, red, green, and blue.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>A <see cref="Color" /> whose alpha, red, green, and blue components are all random.</returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
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);
}
/// <summary>
/// Returns a color of random components for red, green, and blue.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>A <see cref="Color" /> whose red, green, and blue components are all random, and whose alpha is 255</returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
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);
}
/// <summary>
/// Returns a color composed of random components for apha, red, green, and blue.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>A <see cref="Color" /> whose alpha, red, green, and blue components are all random.</returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
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);
}
}

View File

@ -0,0 +1,252 @@
using UnityEngine;
namespace X10D.Unity;
/// <summary>
/// Extension methods for <see cref="GameObject" />.
/// </summary>
public static class GameObjectExtensions
{
/// <summary>
/// Rotates the transform component of this game object so the forward vector points at another game object.
/// </summary>
/// <param name="gameObject">The game object whose rotation will be changed.</param>
/// <param name="target">The game object to look at.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="target" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Rotates the transform component of this game object so the forward vector points at <paramref name="target" />.
/// </summary>
/// <param name="gameObject">The game object whose rotation will be changed.</param>
/// <param name="target">The point to look at.</param>
/// <exception cref="ArgumentNullException"><paramref name="gameObject" /> is <see langword="null" />.</exception>
public static void LookAt(this GameObject gameObject, Vector3 target)
{
if (gameObject == null)
{
throw new ArgumentNullException(nameof(gameObject));
}
gameObject.transform.LookAt(target);
}
/// <summary>
/// Rotates the transform component of this game object so the forward vector points at a specified transform.
/// </summary>
/// <param name="gameObject">The game object whose rotation will be changed.</param>
/// <param name="target">The transform to look at.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="target" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Rotates the transform component of this game object so the forward vector points at another game object.
/// </summary>
/// <param name="gameObject">The game object whose rotation will be changed.</param>
/// <param name="target">The game object to look at.</param>
/// <param name="worldUp">A vector specifying the upward direction.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="target" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Rotates the transform component of this game object so the forward vector points at <paramref name="target" />.
/// </summary>
/// <param name="gameObject">The game object whose rotation will be changed.</param>
/// <param name="target">The point to look at.</param>
/// <param name="worldUp">A vector specifying the upward direction.</param>
/// <exception cref="ArgumentNullException"><paramref name="gameObject" /> is <see langword="null" />.</exception>
public static void LookAt(this GameObject gameObject, Vector3 target, Vector3 worldUp)
{
if (gameObject == null)
{
throw new ArgumentNullException(nameof(gameObject));
}
gameObject.transform.LookAt(target, worldUp);
}
/// <summary>
/// Rotates the transform component of this game object so the forward vector points at a specified transform.
/// </summary>
/// <param name="gameObject">The game object whose rotation will be changed.</param>
/// <param name="target">The transform to look at.</param>
/// <param name="worldUp">A vector specifying the upward direction.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="target" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Sets the parent of this game object.
/// </summary>
/// <param name="gameObject">The game object whose parent to change.</param>
/// <param name="parent">The new parent.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="parent" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Sets the parent of this game object.
/// </summary>
/// <param name="gameObject">The game object whose parent to change.</param>
/// <param name="parent">The new parent.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="parent" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Sets the parent of this game object.
/// </summary>
/// <param name="gameObject">The game object whose parent to change.</param>
/// <param name="parent">The new parent.</param>
/// <param name="worldPositionStays">
/// <see langword="true" /> 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, <see langword="false" />.
/// </param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="parent" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Sets the parent of this game object.
/// </summary>
/// <param name="gameObject">The game object whose parent to change.</param>
/// <param name="parent">The new parent.</param>
/// <param name="worldPositionStays">
/// <see langword="true" /> 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, <see langword="false" />.
/// </param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="gameObject" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="parent" /> is <see langword="null" />.</para>
/// </exception>
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);
}
}

View File

@ -0,0 +1,118 @@
using UnityEngine;
using X10D.Core;
using Random = System.Random;
namespace X10D.Unity.Numerics;
/// <summary>
/// Extension methods for <see cref="System.Random" />.
/// </summary>
public static class RandomExtensions
{
/// <summary>
/// Returns a randomly generated rotation as represented by a <see cref="Quaternion" />.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>
/// A <see cref="Quaternion" /> constructed from 3 random single-precision floating point numbers representing the
/// yaw, pitch, and roll.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
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);
}
/// <summary>
/// Returns a randomly generated rotation with uniform distribution.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>A <see cref="Quaternion" /> constructed with uniform distribution.</returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
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);
}
/// <summary>
/// Returns a <see cref="Vector2" /> with magnitude 1 whose components indicate a random point on the unit circle.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance</param>
/// <returns>
/// A <see cref="Vector2" /> whose <see cref="Vector2.Length()" /> returns 1, and whose components indicate a random
/// point on the unit circle.
/// </returns>
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);
}
/// <summary>
/// Returns a <see cref="Vector3" /> with magnitude 1 whose components indicate a random point on the unit sphere.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance</param>
/// <returns>
/// A <see cref="Vector3" /> whose <see cref="Vector3.Length()" /> returns 1, and whose components indicate a random
/// point on the unit sphere.
/// </returns>
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);
}
}

View File

@ -0,0 +1,114 @@
using UnityEngine;
namespace X10D.Unity;
/// <summary>
/// Extension methods for <see cref="Transform" />.
/// </summary>
public static class TransformExtensions
{
/// <summary>
/// Rotates this transform so the forward vector points at another game object.
/// </summary>
/// <param name="transform">The transform whose rotation will be changed.</param>
/// <param name="target">The game object to look at.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="transform" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="target" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Rotates this transform so the forward vector points at another game object.
/// </summary>
/// <param name="transform">The transform whose rotation will be changed.</param>
/// <param name="target">The game object to look at.</param>
/// <param name="worldUp">A vector specifying the upward direction.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="transform" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="target" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Sets the parent of this transform.
/// </summary>
/// <param name="transform">The transform whose parent to change.</param>
/// <param name="parent">The new parent.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="transform" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="parent" /> is <see langword="null" />.</para>
/// </exception>
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);
}
/// <summary>
/// Sets the parent of this transform.
/// </summary>
/// <param name="transform">The transform whose parent to change.</param>
/// <param name="parent">The new parent.</param>
/// <param name="worldPositionStays">
/// <see langword="true" /> 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, <see langword="false" />.
/// </param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="transform" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="parent" /> is <see langword="null" />.</para>
/// </exception>
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);
}
}

View File

@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X10D.SourceValidator", "X10D.SourceValidator\X10D.SourceValidator.csproj", "{84750149-9068-4780-AFDE-CDA1AC57007D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X10D.SourceValidator", "X10D.SourceValidator\X10D.SourceValidator.csproj", "{84750149-9068-4780-AFDE-CDA1AC57007D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X10D.Unity", "X10D.Unity\X10D.Unity.csproj", "{7EAB3F09-A9FD-4334-B4DB-0394DD0C6568}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{84750149-9068-4780-AFDE-CDA1AC57007D}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<ImplicitUsings>true</ImplicitUsings> <ImplicitUsings>true</ImplicitUsings>

View File

@ -17,7 +17,14 @@ public static class ArrayExtensions
[Pure] [Pure]
public static IReadOnlyCollection<T> AsReadOnly<T>(this T[] array) public static IReadOnlyCollection<T> AsReadOnly<T>(this T[] array)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(array); ArgumentNullException.ThrowIfNull(array);
#else
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
#endif
return Array.AsReadOnly(array); return Array.AsReadOnly(array);
} }
@ -42,7 +49,14 @@ public static class ArrayExtensions
/// <exception cref="ArgumentNullException"><paramref name="array" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="array" /> is <see langword="null" />.</exception>
public static void Clear<T>(this T?[] array, Range range) public static void Clear<T>(this T?[] array, Range range)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(array); ArgumentNullException.ThrowIfNull(array);
#else
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
#endif
int index = range.Start.Value; int index = range.Start.Value;
int end = range.End.Value; int end = range.End.Value;
@ -71,7 +85,14 @@ public static class ArrayExtensions
/// </exception> /// </exception>
public static void Clear<T>(this T?[] array, int index, int length) public static void Clear<T>(this T?[] array, int index, int length)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(array); ArgumentNullException.ThrowIfNull(array);
#else
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
#endif
if (length == 0 || array.Length == 0) if (length == 0 || array.Length == 0)
{ {

View File

@ -18,7 +18,14 @@ public static class BoolListExtensions
[Pure] [Pure]
public static byte PackByte(this IReadOnlyList<bool> source) public static byte PackByte(this IReadOnlyList<bool> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (source.Count > 8) if (source.Count > 8)
{ {
@ -45,7 +52,14 @@ public static class BoolListExtensions
[Pure] [Pure]
public static short PackInt16(this IReadOnlyList<bool> source) public static short PackInt16(this IReadOnlyList<bool> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (source.Count > 16) if (source.Count > 16)
{ {
@ -72,7 +86,14 @@ public static class BoolListExtensions
[Pure] [Pure]
public static int PackInt32(this IReadOnlyList<bool> source) public static int PackInt32(this IReadOnlyList<bool> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (source.Count > 32) if (source.Count > 32)
{ {
@ -99,7 +120,14 @@ public static class BoolListExtensions
[Pure] [Pure]
public static long PackInt64(this IReadOnlyList<bool> source) public static long PackInt64(this IReadOnlyList<bool> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (source.Count > 64) if (source.Count > 64)
{ {

View File

@ -34,8 +34,22 @@ public static class DictionaryExtensions
Func<TKey, TValue, TValue> updateValueFactory) Func<TKey, TValue, TValue> updateValueFactory)
where TKey : notnull where TKey : notnull
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary); ArgumentNullException.ThrowIfNull(dictionary);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory); ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif
if (dictionary.ContainsKey(key)) if (dictionary.ContainsKey(key))
{ {
@ -77,9 +91,30 @@ public static class DictionaryExtensions
Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory) Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
where TKey : notnull where TKey : notnull
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary); ArgumentNullException.ThrowIfNull(dictionary);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(addValueFactory); ArgumentNullException.ThrowIfNull(addValueFactory);
#else
if (addValueFactory is null)
{
throw new ArgumentNullException(nameof(addValueFactory));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory); ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif
if (dictionary.ContainsKey(key)) if (dictionary.ContainsKey(key))
{ {
@ -127,9 +162,30 @@ public static class DictionaryExtensions
Func<TKey, TArg, TValue> addValueFactory, Func<TKey, TValue, TArg, TValue> updateValueFactory, TArg factoryArgument) Func<TKey, TArg, TValue> addValueFactory, Func<TKey, TValue, TArg, TValue> updateValueFactory, TArg factoryArgument)
where TKey : notnull where TKey : notnull
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(dictionary); ArgumentNullException.ThrowIfNull(dictionary);
#else
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(addValueFactory); ArgumentNullException.ThrowIfNull(addValueFactory);
#else
if (addValueFactory is null)
{
throw new ArgumentNullException(nameof(addValueFactory));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(updateValueFactory); ArgumentNullException.ThrowIfNull(updateValueFactory);
#else
if (updateValueFactory is null)
{
throw new ArgumentNullException(nameof(updateValueFactory));
}
#endif
if (dictionary.ContainsKey(key)) if (dictionary.ContainsKey(key))
{ {
@ -155,7 +211,14 @@ public static class DictionaryExtensions
[Pure] [Pure]
public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source) public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
static string SanitizeValue(string? value) static string SanitizeValue(string? value)
{ {
@ -195,8 +258,22 @@ public static class DictionaryExtensions
public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source,
Func<TValue, string?> selector) Func<TValue, string?> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector); ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
}
#endif
static string SanitizeValue(string? value) static string SanitizeValue(string? value)
{ {
@ -242,9 +319,30 @@ public static class DictionaryExtensions
Func<TKey, string> keySelector, Func<TValue, string?> valueSelector) Func<TKey, string> keySelector, Func<TValue, string?> valueSelector)
where TKey : notnull where TKey : notnull
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(keySelector); ArgumentNullException.ThrowIfNull(keySelector);
#else
if (keySelector is null)
{
throw new ArgumentNullException(nameof(keySelector));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(valueSelector); ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (valueSelector is null)
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif
static string SanitizeValue(string? value) static string SanitizeValue(string? value)
{ {
@ -276,7 +374,14 @@ public static class DictionaryExtensions
public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source) public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
where TKey : notnull where TKey : notnull
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
static string GetQueryParameter(KeyValuePair<TKey, TValue> pair) static string GetQueryParameter(KeyValuePair<TKey, TValue> pair)
{ {
@ -308,8 +413,22 @@ public static class DictionaryExtensions
Func<TValue, string?> selector) Func<TValue, string?> selector)
where TKey : notnull where TKey : notnull
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector); ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
}
#endif
// can't static here because of 'selector' parameter // can't static here because of 'selector' parameter
string GetQueryParameter(KeyValuePair<TKey, TValue> pair) string GetQueryParameter(KeyValuePair<TKey, TValue> pair)
@ -347,9 +466,30 @@ public static class DictionaryExtensions
Func<TKey, string> keySelector, Func<TValue, string?> valueSelector) Func<TKey, string> keySelector, Func<TValue, string?> valueSelector)
where TKey : notnull where TKey : notnull
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(keySelector); ArgumentNullException.ThrowIfNull(keySelector);
#else
if (keySelector is null)
{
throw new ArgumentNullException(nameof(keySelector));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(valueSelector); ArgumentNullException.ThrowIfNull(valueSelector);
#else
if (valueSelector is null)
{
throw new ArgumentNullException(nameof(valueSelector));
}
#endif
// can't static here because of selector parameters // can't static here because of selector parameters
string GetQueryParameter(KeyValuePair<TKey, TValue> pair) string GetQueryParameter(KeyValuePair<TKey, TValue> pair)

View File

@ -139,7 +139,14 @@ public static class EnumerableExtensions
[Pure] [Pure]
public static IReadOnlyCollection<T> Shuffled<T>(this IEnumerable<T> source, Random? random = null) public static IReadOnlyCollection<T> Shuffled<T>(this IEnumerable<T> source, Random? random = null)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
var list = new List<T>(source); var list = new List<T>(source);
list.Shuffle(random); list.Shuffle(random);

View File

@ -17,7 +17,14 @@ public static class ListExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static void Fill<T>(this IList<T> source, T value) public static void Fill<T>(this IList<T> source, T value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
for (var i = 0; i < source.Count; i++) for (var i = 0; i < source.Count; i++)
{ {
@ -44,7 +51,14 @@ public static class ListExtensions
/// </exception> /// </exception>
public static void Fill<T>(this IList<T> source, T value, int startIndex, int count) public static void Fill<T>(this IList<T> source, T value, int startIndex, int count)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (startIndex < 0) if (startIndex < 0)
{ {
@ -78,8 +92,8 @@ public static class ListExtensions
/// <typeparam name="T">The element type.</typeparam> /// <typeparam name="T">The element type.</typeparam>
/// <param name="source">The source collection from which to draw.</param> /// <param name="source">The source collection from which to draw.</param>
/// <param name="random"> /// <param name="random">
/// The <see cref="System.Random" /> instance to use for the shuffling. If <see langword="null" /> is specified, /// The <see cref="System.Random" /> instance to use for the shuffling. If <see langword="null" /> is specified, a shared
/// <see cref="System.Random.Shared" /> is used. /// instance is used.
/// </param> /// </param>
/// <returns>A random element of type <typeparamref name="T" /> from <paramref name="source" />.</returns> /// <returns>A random element of type <typeparamref name="T" /> from <paramref name="source" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
@ -92,9 +106,16 @@ public static class ListExtensions
[Pure] [Pure]
public static T Random<T>(this IReadOnlyList<T> source, Random? random = null) public static T Random<T>(this IReadOnlyList<T> source, Random? random = null)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); 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); return random.NextFrom(source);
} }
@ -104,15 +125,22 @@ public static class ListExtensions
/// <typeparam name="T">The element type.</typeparam> /// <typeparam name="T">The element type.</typeparam>
/// <param name="source">The <see cref="IList{T}" /> to shuffle.</param> /// <param name="source">The <see cref="IList{T}" /> to shuffle.</param>
/// <param name="random"> /// <param name="random">
/// The <see cref="System.Random" /> instance to use for the shuffling. If <see langword="null" /> is specified, /// The <see cref="System.Random" /> instance to use for the shuffling. If <see langword="null" /> is specified, a shared
/// <see cref="System.Random.Shared" /> is used. /// instance is used.
/// </param> /// </param>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static void Shuffle<T>(this IList<T> source, Random? random = null) public static void Shuffle<T>(this IList<T> source, Random? random = null)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); 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; int count = source.Count;
while (count > 0) while (count > 0)

View File

@ -20,7 +20,11 @@ public static class EnumExtensions
public static T Next<T>(this T value) public static T Next<T>(this T value)
where T : struct, Enum where T : struct, Enum
{ {
#if NET5_0_OR_GREATER
T[] values = Enum.GetValues<T>(); T[] values = Enum.GetValues<T>();
#else
T[] values = Enum.GetValues(typeof(T)).Cast<T>().ToArray();
#endif
int index = Array.IndexOf(values, value) + 1; int index = Array.IndexOf(values, value) + 1;
index %= values.Length; index %= values.Length;
return values[index]; return values[index];
@ -40,7 +44,11 @@ public static class EnumExtensions
public static T NextUnchecked<T>(this T value) public static T NextUnchecked<T>(this T value)
where T : struct, Enum where T : struct, Enum
{ {
#if NET5_0_OR_GREATER
T[] values = Enum.GetValues<T>(); T[] values = Enum.GetValues<T>();
#else
T[] values = Enum.GetValues(typeof(T)).Cast<T>().ToArray();
#endif
int index = Array.IndexOf(values, value) + 1; int index = Array.IndexOf(values, value) + 1;
return values[index]; return values[index];
} }
@ -58,7 +66,11 @@ public static class EnumExtensions
public static T Previous<T>(this T value) public static T Previous<T>(this T value)
where T : struct, Enum where T : struct, Enum
{ {
#if NET5_0_OR_GREATER
T[] values = Enum.GetValues<T>(); T[] values = Enum.GetValues<T>();
#else
T[] values = Enum.GetValues(typeof(T)).Cast<T>().ToArray();
#endif
int index = Array.IndexOf(values, value) - 1; int index = Array.IndexOf(values, value) - 1;
int length = values.Length; int length = values.Length;
@ -82,7 +94,11 @@ public static class EnumExtensions
public static T PreviousUnchecked<T>(this T value) public static T PreviousUnchecked<T>(this T value)
where T : struct, Enum where T : struct, Enum
{ {
#if NET5_0_OR_GREATER
T[] values = Enum.GetValues<T>(); T[] values = Enum.GetValues<T>();
#else
T[] values = Enum.GetValues(typeof(T)).Cast<T>().ToArray();
#endif
int index = Array.IndexOf(values, value) - 1; int index = Array.IndexOf(values, value) - 1;
return values[index]; return values[index];
} }

View File

@ -16,7 +16,7 @@ public static class Extensions
/// An array of type <typeparamref name="T" /> with length 1, whose only element is <paramref name="value" />. /// An array of type <typeparamref name="T" /> with length 1, whose only element is <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
public static T?[] AsArrayValue<T>(this T? value) public static T[] AsArrayValue<T>(this T value)
{ {
return new[] {value}; return new[] {value};
} }
@ -30,7 +30,7 @@ public static class Extensions
/// An enumerable collection of type <typeparamref name="T" />, whose only element is <paramref name="value" />. /// An enumerable collection of type <typeparamref name="T" />, whose only element is <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
public static IEnumerable<T?> AsEnumerableValue<T>(this T? value) public static IEnumerable<T> AsEnumerableValue<T>(this T value)
{ {
yield return value; yield return value;
} }

View File

@ -9,6 +9,8 @@ namespace X10D.Core;
/// </summary> /// </summary>
public static class RandomExtensions public static class RandomExtensions
{ {
private static readonly Random Shared = new();
/// <summary> /// <summary>
/// Returns a random value that defined in a specified enum. /// Returns a random value that defined in a specified enum.
/// </summary> /// </summary>
@ -21,7 +23,14 @@ public static class RandomExtensions
public static T Next<T>(this Random random) public static T Next<T>(this Random random)
where T : struct, Enum where T : struct, Enum
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
var values = Enum.GetValues(typeof(T)); var values = Enum.GetValues(typeof(T));
return (T)values.GetValue(random.Next(values.Length))!; return (T)values.GetValue(random.Next(values.Length))!;
@ -41,7 +50,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static bool NextBoolean(this Random random) public static bool NextBoolean(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
return random.NextDouble() >= 0.5; return random.NextDouble() >= 0.5;
} }
@ -61,7 +77,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentOutOfRangeException"><paramref name="maxValue" /> is less than 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxValue" /> is less than 0.</exception>
public static double NextDouble(this Random random, double maxValue) public static double NextDouble(this Random random, double maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
if (maxValue < 0) if (maxValue < 0)
{ {
@ -90,7 +113,14 @@ public static class RandomExtensions
/// </exception> /// </exception>
public static double NextDouble(this Random random, double minValue, double maxValue) public static double NextDouble(this Random random, double minValue, double maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
if (maxValue < minValue) if (maxValue < minValue)
{ {
@ -121,8 +151,22 @@ public static class RandomExtensions
/// </example> /// </example>
public static T NextFrom<T>(this Random random, IEnumerable<T> source) public static T NextFrom<T>(this Random random, IEnumerable<T> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (source is T[] array) if (source is T[] array)
{ {
@ -147,7 +191,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static byte NextByte(this Random random) public static byte NextByte(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
return random.NextByte(byte.MaxValue); return random.NextByte(byte.MaxValue);
} }
@ -168,7 +219,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static byte NextByte(this Random random, byte maxValue) public static byte NextByte(this Random random, byte maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
return random.NextByte(0, maxValue); return random.NextByte(0, maxValue);
} }
@ -194,7 +252,14 @@ public static class RandomExtensions
/// </exception> /// </exception>
public static byte NextByte(this Random random, byte minValue, byte maxValue) public static byte NextByte(this Random random, byte minValue, byte maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
return (byte)random.Next(minValue, maxValue); return (byte)random.Next(minValue, maxValue);
} }
@ -209,7 +274,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static short NextInt16(this Random random) public static short NextInt16(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
return random.NextInt16(short.MaxValue); return random.NextInt16(short.MaxValue);
} }
@ -231,7 +303,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentOutOfRangeException"><paramref name="maxValue" /> is less than 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxValue" /> is less than 0.</exception>
public static short NextInt16(this Random random, short maxValue) public static short NextInt16(this Random random, short maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
if (maxValue < 0) if (maxValue < 0)
{ {
@ -262,11 +341,36 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static short NextInt16(this Random random, short minValue, short maxValue) public static short NextInt16(this Random random, short minValue, short maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
return (short)random.Next(minValue, maxValue); return (short)random.Next(minValue, maxValue);
} }
#if !NET6_0_OR_GREATER
/// <summary>
/// Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0.
/// </summary>
/// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>A single-precision floating point number that is greater than or equal to 0.0, and less than 1.0.</returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static float NextSingle(this Random random)
{
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
return (float)random.NextDouble();
}
#endif
/// <summary> /// <summary>
/// Returns a non-negative random single-precision floating point number that is less than the specified maximum. /// Returns a non-negative random single-precision floating point number that is less than the specified maximum.
/// </summary> /// </summary>
@ -282,7 +386,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentException"><paramref name="maxValue" /> is less than 0.</exception> /// <exception cref="ArgumentException"><paramref name="maxValue" /> is less than 0.</exception>
public static float NextSingle(this Random random, float maxValue) public static float NextSingle(this Random random, float maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
if (maxValue < 0) if (maxValue < 0)
{ {
@ -311,7 +422,14 @@ public static class RandomExtensions
/// </exception> /// </exception>
public static float NextSingle(this Random random, float minValue, float maxValue) public static float NextSingle(this Random random, float minValue, float maxValue)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
if (maxValue < minValue) if (maxValue < minValue)
{ {
@ -339,8 +457,22 @@ public static class RandomExtensions
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is less than 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is less than 0.</exception>
public static string NextString(this Random random, IReadOnlyList<char> source, int length) public static string NextString(this Random random, IReadOnlyList<char> source, int length)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (length < 0) if (length < 0)
{ {
@ -365,4 +497,13 @@ public static class RandomExtensions
return builder.ToString(); return builder.ToString();
} }
internal static Random GetShared()
{
#if NET6_0_OR_GREATER
return Random.Shared;
#else
return Shared;
#endif
}
} }

View File

@ -15,7 +15,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static Color NextColorRgb(this Random random) public static Color NextColorRgb(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
int rgb = random.Next(); int rgb = random.Next();
return Color.FromArgb(0xFF, (byte)(rgb >> 16 & 0xFF), (byte)(rgb >> 8 & 0xFF), (byte)(rgb & 0xFF)); return Color.FromArgb(0xFF, (byte)(rgb >> 16 & 0xFF), (byte)(rgb >> 8 & 0xFF), (byte)(rgb & 0xFF));
@ -29,7 +36,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static Color NextColorArgb(this Random random) public static Color NextColorArgb(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
int argb = random.Next(); int argb = random.Next();
return Color.FromArgb(argb); return Color.FromArgb(argb);

View File

@ -1,5 +1,6 @@
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace X10D.IO; namespace X10D.IO;
@ -55,8 +56,11 @@ public static class DoubleExtensions
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
public static bool TryWriteBytes(this double value, Span<byte> destination, Endianness endianness) public static bool TryWriteBytes(this double value, Span<byte> destination, Endianness endianness)
{ {
return endianness == Endianness.BigEndian if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
? BinaryPrimitives.TryWriteDoubleBigEndian(destination, value) {
: BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value); value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value));
}
return MemoryMarshal.TryWrite(destination, ref value);
} }
} }

View File

@ -29,7 +29,14 @@ public static class FileInfoExtensions
public static byte[] GetHash<T>(this FileInfo value) public static byte[] GetHash<T>(this FileInfo value)
where T : HashAlgorithm where T : HashAlgorithm
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
using FileStream stream = value.OpenRead(); using FileStream stream = value.OpenRead();
return stream.GetHash<T>(); return stream.GetHash<T>();
@ -62,7 +69,14 @@ public static class FileInfoExtensions
public static bool TryWriteHash<T>(this FileInfo value, Span<byte> destination, out int bytesWritten) public static bool TryWriteHash<T>(this FileInfo value, Span<byte> destination, out int bytesWritten)
where T : HashAlgorithm where T : HashAlgorithm
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
using FileStream stream = value.OpenRead(); using FileStream stream = value.OpenRead();
return stream.TryWriteHash<T>(destination, out bytesWritten); return stream.TryWriteHash<T>(destination, out bytesWritten);

View File

@ -19,7 +19,14 @@ public static class ListOfByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static string AsString(this IReadOnlyList<byte> source) public static string AsString(this IReadOnlyList<byte> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToString(source.ToArray()); return BitConverter.ToString(source.ToArray());
} }
@ -47,7 +54,14 @@ public static class ListOfByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static double ToDouble(this IReadOnlyList<byte> source, int startIndex) public static double ToDouble(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToDouble(source.ToArray(), startIndex); return BitConverter.ToDouble(source.ToArray(), startIndex);
} }
@ -72,7 +86,14 @@ public static class ListOfByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static short ToInt16(this IReadOnlyList<byte> source, int startIndex) public static short ToInt16(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToInt16(source.ToArray(), startIndex); return BitConverter.ToInt16(source.ToArray(), startIndex);
} }
@ -97,7 +118,14 @@ public static class ListOfByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static int ToInt32(this IReadOnlyList<byte> source, int startIndex) public static int ToInt32(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToInt32(source.ToArray(), startIndex); return BitConverter.ToInt32(source.ToArray(), startIndex);
} }
@ -122,7 +150,14 @@ public static class ListOfByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static long ToInt64(this IReadOnlyList<byte> source, int startIndex) public static long ToInt64(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToInt64(source.ToArray(), startIndex); return BitConverter.ToInt64(source.ToArray(), startIndex);
} }
@ -149,7 +184,14 @@ public static class ListOfByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static float ToSingle(this IReadOnlyList<byte> source, int startIndex) public static float ToSingle(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToSingle(source.ToArray(), startIndex); return BitConverter.ToSingle(source.ToArray(), startIndex);
} }
@ -167,8 +209,22 @@ public static class ListOfByteExtensions
/// </exception> /// </exception>
public static string ToString(this IReadOnlyList<byte> source, Encoding encoding) public static string ToString(this IReadOnlyList<byte> source, Encoding encoding)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(encoding); ArgumentNullException.ThrowIfNull(encoding);
#else
if (encoding is null)
{
throw new ArgumentNullException(nameof(encoding));
}
#endif
return encoding.GetString(source.ToArray()); return encoding.GetString(source.ToArray());
} }
@ -195,7 +251,14 @@ public static class ListOfByteExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static ushort ToUInt16(this IReadOnlyList<byte> source, int startIndex) public static ushort ToUInt16(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToUInt16(source.ToArray(), startIndex); return BitConverter.ToUInt16(source.ToArray(), startIndex);
} }
@ -222,7 +285,14 @@ public static class ListOfByteExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static uint ToUInt32(this IReadOnlyList<byte> source, int startIndex) public static uint ToUInt32(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToUInt32(source.ToArray(), startIndex); return BitConverter.ToUInt32(source.ToArray(), startIndex);
} }
@ -249,7 +319,14 @@ public static class ListOfByteExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static ulong ToUInt64(this IReadOnlyList<byte> source, int startIndex) public static ulong ToUInt64(this IReadOnlyList<byte> source, int startIndex)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return BitConverter.ToUInt64(source.ToArray(), startIndex); return BitConverter.ToUInt64(source.ToArray(), startIndex);
} }

View File

@ -1,5 +1,6 @@
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace X10D.IO; namespace X10D.IO;
@ -55,8 +56,11 @@ public static class SingleExtensions
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
public static bool TryWriteBytes(this float value, Span<byte> destination, Endianness endianness) public static bool TryWriteBytes(this float value, Span<byte> destination, Endianness endianness)
{ {
return endianness == Endianness.BigEndian if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
? BinaryPrimitives.TryWriteSingleBigEndian(destination, value) {
: BinaryPrimitives.TryWriteSingleLittleEndian(destination, value); value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value));
}
return MemoryMarshal.TryWrite(destination, ref value);
} }
} }

View File

@ -1,5 +1,6 @@
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace X10D.IO; namespace X10D.IO;
@ -31,10 +32,14 @@ public static class StreamExtensions
public static byte[] GetHash<T>(this Stream stream) public static byte[] GetHash<T>(this Stream stream)
where T : HashAlgorithm where T : HashAlgorithm
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
if (!stream.CanRead) if (!stream.CanRead)
{ {
@ -81,15 +86,26 @@ public static class StreamExtensions
/// <returns>A decimal value read from the stream.</returns> /// <returns>A decimal value read from the stream.</returns>
public static decimal ReadDecimal(this Stream stream, Endianness endianness) public static decimal ReadDecimal(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(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 decimalSize = sizeof(decimal);
const int int32Size = sizeof(int); const int int32Size = sizeof(int);
@ -129,22 +145,38 @@ public static class StreamExtensions
/// <returns>A double-precision floating point value read from the stream.</returns> /// <returns>A double-precision floating point value read from the stream.</returns>
public static double ReadDouble(this Stream stream, Endianness endianness) public static double ReadDouble(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(double)]; Span<byte> buffer = stackalloc byte[sizeof(double)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian var value = MemoryMarshal.Read<double>(buffer);
? BinaryPrimitives.ReadDoubleLittleEndian(buffer)
: BinaryPrimitives.ReadDoubleBigEndian(buffer); if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
{
value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value));
}
return value;
} }
/// <summary> /// <summary>
@ -167,15 +199,26 @@ public static class StreamExtensions
/// <returns>An two-byte unsigned integer read from the stream.</returns> /// <returns>An two-byte unsigned integer read from the stream.</returns>
public static short ReadInt16(this Stream stream, Endianness endianness) public static short ReadInt16(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(short)]; Span<byte> buffer = stackalloc byte[sizeof(short)];
stream.Read(buffer); stream.Read(buffer);
@ -205,15 +248,26 @@ public static class StreamExtensions
/// <returns>An four-byte unsigned integer read from the stream.</returns> /// <returns>An four-byte unsigned integer read from the stream.</returns>
public static int ReadInt32(this Stream stream, Endianness endianness) public static int ReadInt32(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
stream.Read(buffer); stream.Read(buffer);
@ -243,15 +297,26 @@ public static class StreamExtensions
/// <returns>An eight-byte unsigned integer read from the stream.</returns> /// <returns>An eight-byte unsigned integer read from the stream.</returns>
public static long ReadInt64(this Stream stream, Endianness endianness) public static long ReadInt64(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(long)]; Span<byte> buffer = stackalloc byte[sizeof(long)];
stream.Read(buffer); stream.Read(buffer);
@ -281,22 +346,38 @@ public static class StreamExtensions
/// <returns>A single-precision floating point value read from the stream.</returns> /// <returns>A single-precision floating point value read from the stream.</returns>
public static double ReadSingle(this Stream stream, Endianness endianness) public static double ReadSingle(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(float)]; Span<byte> buffer = stackalloc byte[sizeof(float)];
stream.Read(buffer); stream.Read(buffer);
return endianness == Endianness.LittleEndian var value = MemoryMarshal.Read<float>(buffer);
? BinaryPrimitives.ReadSingleLittleEndian(buffer)
: BinaryPrimitives.ReadSingleBigEndian(buffer); if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
{
value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value));
}
return value;
} }
/// <summary> /// <summary>
@ -321,15 +402,26 @@ public static class StreamExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static ushort ReadUInt16(this Stream stream, Endianness endianness) public static ushort ReadUInt16(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(ushort)]; Span<byte> buffer = stackalloc byte[sizeof(ushort)];
stream.Read(buffer); stream.Read(buffer);
@ -361,15 +453,26 @@ public static class StreamExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static uint ReadUInt32(this Stream stream, Endianness endianness) public static uint ReadUInt32(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(uint)]; Span<byte> buffer = stackalloc byte[sizeof(uint)];
stream.Read(buffer); stream.Read(buffer);
@ -401,15 +504,26 @@ public static class StreamExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static ulong ReadUInt64(this Stream stream, Endianness endianness) public static ulong ReadUInt64(this Stream stream, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(ulong)]; Span<byte> buffer = stackalloc byte[sizeof(ulong)];
stream.Read(buffer); stream.Read(buffer);
@ -445,10 +559,14 @@ public static class StreamExtensions
public static bool TryWriteHash<T>(this Stream stream, Span<byte> destination, out int bytesWritten) public static bool TryWriteHash<T>(this Stream stream, Span<byte> destination, out int bytesWritten)
where T : HashAlgorithm where T : HashAlgorithm
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null) if (stream is null)
{ {
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
#endif
if (!stream.CanRead) if (!stream.CanRead)
{ {
@ -504,12 +622,26 @@ public static class StreamExtensions
/// <returns>The number of bytes written to the stream.</returns> /// <returns>The number of bytes written to the stream.</returns>
public static int Write(this Stream stream, short value, Endianness endianness) public static int Write(this Stream stream, short value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(short)]; Span<byte> buffer = stackalloc byte[sizeof(short)];
@ -548,12 +680,26 @@ public static class StreamExtensions
/// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception>
public static int Write(this Stream stream, int value, Endianness endianness) public static int Write(this Stream stream, int value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(int)]; Span<byte> buffer = stackalloc byte[sizeof(int)];
@ -593,12 +739,26 @@ public static class StreamExtensions
/// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception>
public static int Write(this Stream stream, long value, Endianness endianness) public static int Write(this Stream stream, long value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(long)]; Span<byte> buffer = stackalloc byte[sizeof(long)];
@ -640,12 +800,26 @@ public static class StreamExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static int Write(this Stream stream, ushort value, Endianness endianness) public static int Write(this Stream stream, ushort value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(ushort)]; Span<byte> buffer = stackalloc byte[sizeof(ushort)];
@ -687,12 +861,26 @@ public static class StreamExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static int Write(this Stream stream, uint value, Endianness endianness) public static int Write(this Stream stream, uint value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(uint)]; Span<byte> buffer = stackalloc byte[sizeof(uint)];
@ -734,12 +922,26 @@ public static class StreamExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static int Write(this Stream stream, ulong value, Endianness endianness) public static int Write(this Stream stream, ulong value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(ulong)]; Span<byte> buffer = stackalloc byte[sizeof(ulong)];
@ -766,22 +968,54 @@ public static class StreamExtensions
/// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception>
public static int Write(this Stream stream, float value, Endianness endianness) public static int Write(this Stream stream, float value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(float)]; Span<byte> buffer = stackalloc byte[sizeof(float)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
{ {
#if NET5_0_OR_GREATER
BinaryPrimitives.WriteSingleLittleEndian(buffer, value); BinaryPrimitives.WriteSingleLittleEndian(buffer, value);
#else
if (BitConverter.IsLittleEndian)
{
value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value));
}
System.Runtime.InteropServices.MemoryMarshal.Write(buffer, ref value);
#endif
} }
else else
{ {
#if NET5_0_OR_GREATER
BinaryPrimitives.WriteSingleBigEndian(buffer, value); 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); return stream.WriteInternal(buffer);
@ -798,22 +1032,54 @@ public static class StreamExtensions
/// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception>
public static int Write(this Stream stream, double value, Endianness endianness) public static int Write(this Stream stream, double value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
Span<byte> buffer = stackalloc byte[sizeof(double)]; Span<byte> buffer = stackalloc byte[sizeof(double)];
if (endianness == Endianness.LittleEndian) if (endianness == Endianness.LittleEndian)
{ {
#if NET5_0_OR_GREATER
BinaryPrimitives.WriteDoubleLittleEndian(buffer, value); BinaryPrimitives.WriteDoubleLittleEndian(buffer, value);
#else
if (BitConverter.IsLittleEndian)
{
value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value));
}
System.Runtime.InteropServices.MemoryMarshal.Write(buffer, ref value);
#endif
} }
else else
{ {
#if NET5_0_OR_GREATER
BinaryPrimitives.WriteDoubleBigEndian(buffer, value); 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); return stream.WriteInternal(buffer);
@ -830,12 +1096,26 @@ public static class StreamExtensions
/// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception>
public static int Write(this Stream stream, decimal value, Endianness endianness) public static int Write(this Stream stream, decimal value, Endianness endianness)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(stream); ArgumentNullException.ThrowIfNull(stream);
#else
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
#endif
#if NET5_0_OR_GREATER
if (!Enum.IsDefined(endianness)) if (!Enum.IsDefined(endianness))
{ {
throw new ArgumentOutOfRangeException(nameof(endianness)); throw new ArgumentOutOfRangeException(nameof(endianness));
} }
#else
if (!Enum.IsDefined(typeof(Endianness), endianness))
{
throw new ArgumentOutOfRangeException(nameof(endianness));
}
#endif
int[] bits = decimal.GetBits(value); int[] bits = decimal.GetBits(value);
long preWritePosition = stream.Position; long preWritePosition = stream.Position;

View File

@ -15,7 +15,14 @@ public static class ByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static byte Product(this IEnumerable<byte> source) public static byte Product(this IEnumerable<byte> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate((byte)1, (current, value) => (byte)(current * value)); return source.Aggregate((byte)1, (current, value) => (byte)(current * value));
} }
@ -29,7 +36,14 @@ public static class ByteExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static sbyte Product(this IEnumerable<sbyte> source) public static sbyte Product(this IEnumerable<sbyte> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate((sbyte)1, (current, value) => (sbyte)(current * value)); return source.Aggregate((sbyte)1, (current, value) => (sbyte)(current * value));
} }
@ -45,7 +59,14 @@ public static class ByteExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static byte Product<TSource>(this IEnumerable<TSource> source, Func<TSource, byte> selector) public static byte Product<TSource>(this IEnumerable<TSource> source, Func<TSource, byte> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }
@ -62,7 +83,14 @@ public static class ByteExtensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static sbyte Product<TSource>(this IEnumerable<TSource> source, Func<TSource, sbyte> selector) public static sbyte Product<TSource>(this IEnumerable<TSource> source, Func<TSource, sbyte> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }

View File

@ -13,7 +13,14 @@ public static class DecimalExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static decimal Product(this IEnumerable<decimal> source) public static decimal Product(this IEnumerable<decimal> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate(1m, (current, value) => (current * value)); return source.Aggregate(1m, (current, value) => (current * value));
} }
@ -29,7 +36,14 @@ public static class DecimalExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static decimal Product<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector) public static decimal Product<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }

View File

@ -13,7 +13,14 @@ public static class DoubleExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static double Product(this IEnumerable<double> source) public static double Product(this IEnumerable<double> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate(1.0, (current, value) => (current * value)); return source.Aggregate(1.0, (current, value) => (current * value));
} }
@ -29,7 +36,14 @@ public static class DoubleExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static double Product<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector) public static double Product<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }

View File

@ -15,7 +15,14 @@ public static class Int32Extensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static int Product(this IEnumerable<int> source) public static int Product(this IEnumerable<int> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate(1, (current, value) => current * value); return source.Aggregate(1, (current, value) => current * value);
} }
@ -29,7 +36,14 @@ public static class Int32Extensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static uint Product(this IEnumerable<uint> source) public static uint Product(this IEnumerable<uint> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate(1u, (current, value) => current * value); return source.Aggregate(1u, (current, value) => current * value);
} }
@ -45,7 +59,14 @@ public static class Int32Extensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static int Product<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector) public static int Product<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }
@ -62,7 +83,14 @@ public static class Int32Extensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static uint Product<TSource>(this IEnumerable<TSource> source, Func<TSource, uint> selector) public static uint Product<TSource>(this IEnumerable<TSource> source, Func<TSource, uint> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }

View File

@ -15,7 +15,14 @@ public static class Int64Extensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static long Product(this IEnumerable<long> source) public static long Product(this IEnumerable<long> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate(1L, (current, value) => current * value); return source.Aggregate(1L, (current, value) => current * value);
} }
@ -29,7 +36,14 @@ public static class Int64Extensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static ulong Product(this IEnumerable<ulong> source) public static ulong Product(this IEnumerable<ulong> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate(1UL, (current, value) => current * value); return source.Aggregate(1UL, (current, value) => current * value);
} }
@ -45,7 +59,14 @@ public static class Int64Extensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static long Product<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector) public static long Product<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }
@ -62,7 +83,14 @@ public static class Int64Extensions
[CLSCompliant(false)] [CLSCompliant(false)]
public static ulong Product<TSource>(this IEnumerable<TSource> source, Func<TSource, ulong> selector) public static ulong Product<TSource>(this IEnumerable<TSource> source, Func<TSource, ulong> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }

View File

@ -21,7 +21,14 @@ public static class ReadOnlySpanExtensions
[Pure] [Pure]
public static bool All<TSource>(this ReadOnlySpan<TSource> source, Predicate<TSource> predicate) public static bool All<TSource>(this ReadOnlySpan<TSource> source, Predicate<TSource> predicate)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(predicate); ArgumentNullException.ThrowIfNull(predicate);
#else
if (predicate is null)
{
throw new ArgumentNullException(nameof(predicate));
}
#endif
if (source.IsEmpty) if (source.IsEmpty)
{ {
@ -53,7 +60,14 @@ public static class ReadOnlySpanExtensions
[Pure] [Pure]
public static bool Any<TSource>(this ReadOnlySpan<TSource> source, Predicate<TSource> predicate) public static bool Any<TSource>(this ReadOnlySpan<TSource> source, Predicate<TSource> predicate)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(predicate); ArgumentNullException.ThrowIfNull(predicate);
#else
if (predicate is null)
{
throw new ArgumentNullException(nameof(predicate));
}
#endif
if (source.IsEmpty) if (source.IsEmpty)
{ {

View File

@ -13,7 +13,14 @@ public static class SingleExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static float Product(this IEnumerable<float> source) public static float Product(this IEnumerable<float> source)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Aggregate(1f, (current, value) => (current * value)); return source.Aggregate(1f, (current, value) => (current * value));
} }
@ -29,7 +36,14 @@ public static class SingleExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
public static float Product<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector) public static float Product<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
return source.Select(selector).Product(); return source.Select(selector).Product();
} }

View File

@ -21,7 +21,14 @@ public static class SpanExtensions
[Pure] [Pure]
public static bool All<TSource>(this Span<TSource> source, Predicate<TSource> predicate) public static bool All<TSource>(this Span<TSource> source, Predicate<TSource> predicate)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(predicate); ArgumentNullException.ThrowIfNull(predicate);
#else
if (predicate is null)
{
throw new ArgumentNullException(nameof(predicate));
}
#endif
if (source.IsEmpty) if (source.IsEmpty)
{ {
@ -53,7 +60,14 @@ public static class SpanExtensions
[Pure] [Pure]
public static bool Any<TSource>(this Span<TSource> source, Predicate<TSource> predicate) public static bool Any<TSource>(this Span<TSource> source, Predicate<TSource> predicate)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(predicate); ArgumentNullException.ThrowIfNull(predicate);
#else
if (predicate is null)
{
throw new ArgumentNullException(nameof(predicate));
}
#endif
if (source.IsEmpty) if (source.IsEmpty)
{ {

View File

@ -19,7 +19,11 @@ public static class ByteExtensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static byte DigitalRoot(this byte value) public static byte DigitalRoot(this byte value)
{ {
int root = value % 9; int root = value % 9;
@ -32,7 +36,11 @@ public static class ByteExtensions
/// <param name="value">The value whose factorial to compute.</param> /// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long Factorial(this byte value) public static long Factorial(this byte value)
{ {
if (value == 0) if (value == 0)
@ -58,7 +66,11 @@ public static class ByteExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this byte value) public static bool IsEven(this byte value)
{ {
return value % 2 == 0; return value % 2 == 0;
@ -73,7 +85,11 @@ public static class ByteExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this byte value) public static bool IsOdd(this byte value)
{ {
return !value.IsEven(); 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this byte value) public static int MultiplicativePersistence(this byte value)
{ {
return ((long)value).MultiplicativePersistence(); return ((long)value).MultiplicativePersistence();

View File

@ -48,14 +48,25 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool Between<T1, T2, T3>(this T1 value, T2 lower, T3 upper, public static bool Between<T1, T2, T3>(this T1 value, T2 lower, T3 upper,
InclusiveOptions inclusiveOptions = InclusiveOptions.None) InclusiveOptions inclusiveOptions = InclusiveOptions.None)
where T1 : IComparable<T2>, IComparable<T3> where T1 : IComparable<T2>, IComparable<T3>
where T2 : IComparable<T3> where T2 : IComparable<T3>
where T3 : IComparable<T2> where T3 : IComparable<T2>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
if (lower.GreaterThan(upper)) if (lower.GreaterThan(upper))
{ {
@ -102,11 +113,22 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static T Clamp<T>(this T value, T lower, T upper) public static T Clamp<T>(this T value, T lower, T upper)
where T : IComparable<T> where T : IComparable<T>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
if (lower.GreaterThan(upper)) if (lower.GreaterThan(upper))
{ {
@ -141,11 +163,22 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool GreaterThan<T1, T2>(this T1 value, T2 other) public static bool GreaterThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.CompareTo(other) > 0; return value.CompareTo(other) > 0;
} }
@ -173,11 +206,22 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool GreaterThanOrEqualTo<T1, T2>(this T1 value, T2 other) public static bool GreaterThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.CompareTo(other) >= 0; return value.CompareTo(other) >= 0;
} }
@ -205,11 +249,22 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool LessThan<T1, T2>(this T1 value, T2 other) public static bool LessThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.CompareTo(other) < 0; return value.CompareTo(other) < 0;
} }
@ -237,11 +292,22 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool LessThanOrEqualTo<T1, T2>(this T1 value, T2 other) public static bool LessThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.CompareTo(other) <= 0; return value.CompareTo(other) <= 0;
} }
@ -268,11 +334,22 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static T Max<T>(this T value, T other) public static T Max<T>(this T value, T other)
where T : IComparable<T> where T : IComparable<T>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.GreaterThan(other) ? value : other; return value.GreaterThan(other) ? value : other;
} }
@ -299,11 +376,22 @@ public static class ComparableExtensions
/// </example> /// </example>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static T Min<T>(this T value, T other) public static T Min<T>(this T value, T other)
where T : IComparable<T> where T : IComparable<T>
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.LessThan(other) ? value : other; return value.LessThan(other) ? value : other;
} }

View File

@ -9,6 +9,7 @@ namespace X10D.Math;
/// </summary> /// </summary>
public static class DecimalExtensions public static class DecimalExtensions
{ {
#if NETCOREAPP3_0_OR_GREATER
/// <summary> /// <summary>
/// Returns the complex square root of this decimal number. /// Returns the complex square root of this decimal number.
/// </summary> /// </summary>
@ -20,6 +21,7 @@ public static class DecimalExtensions
{ {
return Complex.Sqrt((double)value); return Complex.Sqrt((double)value);
} }
#endif
/// <summary> /// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2. /// Returns a value indicating whether the current value is evenly divisible by 2.
@ -30,7 +32,11 @@ public static class DecimalExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this decimal value) public static bool IsEven(this decimal value)
{ {
return value % 2.0m == 0.0m; return value % 2.0m == 0.0m;
@ -45,7 +51,11 @@ public static class DecimalExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this decimal value) public static bool IsOdd(this decimal value)
{ {
return !value.IsEven(); return !value.IsEven();
@ -57,7 +67,11 @@ public static class DecimalExtensions
/// <param name="value">The value to round.</param> /// <param name="value">The value to round.</param>
/// <returns><paramref name="value" /> rounded to the nearest whole number.</returns> /// <returns><paramref name="value" /> rounded to the nearest whole number.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static decimal Round(this decimal value) public static decimal Round(this decimal value)
{ {
return value.Round(1.0m); return value.Round(1.0m);
@ -70,7 +84,11 @@ public static class DecimalExtensions
/// <param name="nearest">The nearest multiple to which <paramref name="value" /> should be rounded.</param> /// <param name="nearest">The nearest multiple to which <paramref name="value" /> should be rounded.</param>
/// <returns><paramref name="value" /> rounded to the nearest multiple of <paramref name="nearest" />.</returns> /// <returns><paramref name="value" /> rounded to the nearest multiple of <paramref name="nearest" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static decimal Round(this decimal value, decimal nearest) public static decimal Round(this decimal value, decimal nearest)
{ {
return System.Math.Round(value / nearest) * nearest; return System.Math.Round(value / nearest) * nearest;
@ -104,7 +122,11 @@ public static class DecimalExtensions
/// </list> /// </list>
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Sign(this decimal value) public static int Sign(this decimal value)
{ {
return System.Math.Sign(value); return System.Math.Sign(value);
@ -138,13 +160,12 @@ public static class DecimalExtensions
/// </list> /// </list>
/// </returns> /// </returns>
/// <exception cref="ArgumentException"><paramref name="value" /> is negative.</exception> /// <exception cref="ArgumentException"><paramref name="value" /> is negative.</exception>
/// <remarks>
/// For negative input, this method returns <see cref="double.NaN" />. To receive a complex number, see
/// <see cref="Numerics.DoubleExtensions.ComplexSqrt" />.
/// </remarks>
/// <seealso cref="Numerics.DoubleExtensions.ComplexSqrt" />
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static decimal Sqrt(this decimal value) public static decimal Sqrt(this decimal value)
{ {
switch (value) switch (value)

View File

@ -20,7 +20,11 @@ public static class DoubleExtensions
/// is equal to <see cref="double.NaN" />, less than -1, or greater than 1, <see cref="double.NaN" /> is returned. /// is equal to <see cref="double.NaN" />, less than -1, or greater than 1, <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Acos(this double value) public static double Acos(this double value)
{ {
return System.Math.Acos(value); return System.Math.Acos(value);
@ -38,7 +42,11 @@ public static class DoubleExtensions
/// <paramref name="value" /> is less than 1 or equal to <see cref="double.NaN" />, <see cref="double.NaN" /> is returned. /// <paramref name="value" /> is less than 1 or equal to <see cref="double.NaN" />, <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Acosh(this double value) public static double Acosh(this double value)
{ {
return System.Math.Acosh(value); return System.Math.Acosh(value);
@ -56,7 +64,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" /> is returned. /// <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Asin(this double value) public static double Asin(this double value)
{ {
return System.Math.Asin(value); return System.Math.Asin(value);
@ -74,7 +86,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" />, <see cref="double.NaN" /> is returned. /// <see cref="double.NaN" />, <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Asinh(this double value) public static double Asinh(this double value)
{ {
return System.Math.Asinh(value); return System.Math.Asinh(value);
@ -91,7 +107,11 @@ public static class DoubleExtensions
/// <paramref name="value" /> is equal to <see cref="double.NaN" />, <see cref="double.NaN" /> is returned. /// <paramref name="value" /> is equal to <see cref="double.NaN" />, <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Atan(this double value) public static double Atan(this double value)
{ {
return System.Math.Atan(value); return System.Math.Atan(value);
@ -110,12 +130,17 @@ public static class DoubleExtensions
/// <see cref="double.NaN" /> is returned. /// <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Atanh(this double value) public static double Atanh(this double value)
{ {
return System.Math.Atanh(value); return System.Math.Atanh(value);
} }
#if NETCOREAPP3_0_OR_GREATER
/// <summary> /// <summary>
/// Returns the complex square root of this double-precision floating-point number. /// Returns the complex square root of this double-precision floating-point number.
/// </summary> /// </summary>
@ -141,6 +166,7 @@ public static class DoubleExtensions
return new Complex(0, System.Math.Sqrt(-value)); return new Complex(0, System.Math.Sqrt(-value));
} }
} }
#endif
/// <summary> /// <summary>
/// Returns the cosine of the specified angle. /// Returns the cosine of the specified angle.
@ -152,7 +178,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" />. /// <see cref="double.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Cos(this double value) public static double Cos(this double value)
{ {
return System.Math.Cos(value); return System.Math.Cos(value);
@ -169,7 +199,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" />, <see cref="double.NaN" /> is returned. /// <see cref="double.NaN" />, <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Cosh(this double value) public static double Cosh(this double value)
{ {
return System.Math.Cosh(value); return System.Math.Cosh(value);
@ -181,7 +215,11 @@ public static class DoubleExtensions
/// <param name="value">The angle in degrees to convert.</param> /// <param name="value">The angle in degrees to convert.</param>
/// <returns>The result of π * <paramref name="value" /> / 180.</returns> /// <returns>The result of π * <paramref name="value" /> / 180.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double DegreesToRadians(this double value) public static double DegreesToRadians(this double value)
{ {
return value * (System.Math.PI / 180.0); return value * (System.Math.PI / 180.0);
@ -196,7 +234,11 @@ public static class DoubleExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this double value) public static bool IsEven(this double value)
{ {
return System.Math.Abs(value % 2.0) < double.Epsilon; return System.Math.Abs(value % 2.0) < double.Epsilon;
@ -211,7 +253,11 @@ public static class DoubleExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this double value) public static bool IsOdd(this double value)
{ {
return !value.IsEven(); return !value.IsEven();
@ -223,7 +269,11 @@ public static class DoubleExtensions
/// <param name="value">The angle in radians to convert.</param> /// <param name="value">The angle in radians to convert.</param>
/// <returns>The result of π * <paramref name="value" /> / 180.</returns> /// <returns>The result of π * <paramref name="value" /> / 180.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double RadiansToDegrees(this double value) public static double RadiansToDegrees(this double value)
{ {
return value * (180.0 / System.Math.PI); return value * (180.0 / System.Math.PI);
@ -235,7 +285,11 @@ public static class DoubleExtensions
/// <param name="value">The value to round.</param> /// <param name="value">The value to round.</param>
/// <returns><paramref name="value" /> rounded to the nearest whole number.</returns> /// <returns><paramref name="value" /> rounded to the nearest whole number.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Round(this double value) public static double Round(this double value)
{ {
return value.Round(1.0); return value.Round(1.0);
@ -248,7 +302,11 @@ public static class DoubleExtensions
/// <param name="nearest">The nearest multiple to which <paramref name="value" /> should be rounded.</param> /// <param name="nearest">The nearest multiple to which <paramref name="value" /> should be rounded.</param>
/// <returns><paramref name="value" /> rounded to the nearest multiple of <paramref name="nearest" />.</returns> /// <returns><paramref name="value" /> rounded to the nearest multiple of <paramref name="nearest" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Round(this double value, double nearest) public static double Round(this double value, double nearest)
{ {
return System.Math.Round(value / nearest) * nearest; return System.Math.Round(value / nearest) * nearest;
@ -264,7 +322,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" />. /// <see cref="double.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Sin(this double value) public static double Sin(this double value)
{ {
return System.Math.Sin(value); return System.Math.Sin(value);
@ -280,7 +342,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" />. /// <see cref="double.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Sinh(this double value) public static double Sinh(this double value)
{ {
return System.Math.Sinh(value); return System.Math.Sinh(value);
@ -315,7 +381,11 @@ public static class DoubleExtensions
/// </returns> /// </returns>
/// <exception cref="ArithmeticException"><paramref name="value" /> is equal to <see cref="double.NaN" />.</exception> /// <exception cref="ArithmeticException"><paramref name="value" /> is equal to <see cref="double.NaN" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Sign(this double value) public static int Sign(this double value)
{ {
return System.Math.Sign(value); return System.Math.Sign(value);
@ -348,15 +418,14 @@ public static class DoubleExtensions
/// </item> /// </item>
/// </list> /// </list>
/// </returns> /// </returns>
/// <remarks>
/// For negative input, this method returns <see cref="double.NaN" />. To receive a complex number, see
/// <see cref="Numerics.DoubleExtensions.ComplexSqrt" />.
/// </remarks>
/// <seealso cref="Numerics.DoubleExtensions.ComplexSqrt" />
/// <author>SLenik https://stackoverflow.com/a/6755197/1467293</author> /// <author>SLenik https://stackoverflow.com/a/6755197/1467293</author>
/// <license>CC BY-SA 3.0</license> /// <license>CC BY-SA 3.0</license>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Sqrt(this double value) public static double Sqrt(this double value)
{ {
switch (value) switch (value)
@ -395,7 +464,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" />. /// <see cref="double.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Tan(this double value) public static double Tan(this double value)
{ {
return System.Math.Tan(value); return System.Math.Tan(value);
@ -412,7 +485,11 @@ public static class DoubleExtensions
/// <see cref="double.NaN" />, this method returns <see cref="double.NaN" />. /// <see cref="double.NaN" />, this method returns <see cref="double.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Tanh(this double value) public static double Tanh(this double value)
{ {
return System.Math.Tanh(value); return System.Math.Tanh(value);

View File

@ -18,7 +18,11 @@ public static class Int16Extensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static short DigitalRoot(this short value) public static short DigitalRoot(this short value)
{ {
short root = System.Math.Abs(value).Mod(9); short root = System.Math.Abs(value).Mod(9);
@ -32,7 +36,11 @@ public static class Int16Extensions
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
/// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception> /// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long Factorial(this short value) public static long Factorial(this short value)
{ {
if (value < 0) if (value < 0)
@ -63,7 +71,11 @@ public static class Int16Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this short value) public static bool IsEven(this short value)
{ {
return (value & 1) == 0; return (value & 1) == 0;
@ -78,7 +90,11 @@ public static class Int16Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this short value) public static bool IsOdd(this short value)
{ {
return !value.IsEven(); return !value.IsEven();
@ -92,7 +108,11 @@ public static class Int16Extensions
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />. /// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPrime(this short value) public static bool IsPrime(this short value)
{ {
return ((long)value).IsPrime(); return ((long)value).IsPrime();
@ -113,7 +133,11 @@ public static class Int16Extensions
/// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author> /// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author>
/// <license>CC-BY-SA 2.5</license> /// <license>CC-BY-SA 2.5</license>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static short Mod(this short dividend, short divisor) public static short Mod(this short dividend, short divisor)
{ {
int r = dividend % 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this short value) public static int MultiplicativePersistence(this short value)
{ {
return ((long)value).MultiplicativePersistence(); return ((long)value).MultiplicativePersistence();
@ -163,7 +191,11 @@ public static class Int16Extensions
/// </list> /// </list>
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Sign(this short value) public static int Sign(this short value)
{ {
return System.Math.Sign(value); return System.Math.Sign(value);

View File

@ -18,7 +18,11 @@ public static class Int32Extensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int DigitalRoot(this int value) public static int DigitalRoot(this int value)
{ {
int root = System.Math.Abs(value).Mod(9); int root = System.Math.Abs(value).Mod(9);
@ -32,7 +36,11 @@ public static class Int32Extensions
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
/// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception> /// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long Factorial(this int value) public static long Factorial(this int value)
{ {
if (value < 0) if (value < 0)
@ -63,7 +71,11 @@ public static class Int32Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this int value) public static bool IsEven(this int value)
{ {
return (value & 1) == 0; return (value & 1) == 0;
@ -78,7 +90,11 @@ public static class Int32Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this int value) public static bool IsOdd(this int value)
{ {
return !value.IsEven(); return !value.IsEven();
@ -92,7 +108,11 @@ public static class Int32Extensions
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />. /// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPrime(this int value) public static bool IsPrime(this int value)
{ {
return ((long)value).IsPrime(); return ((long)value).IsPrime();
@ -113,7 +133,11 @@ public static class Int32Extensions
/// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author> /// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author>
/// <license>CC-BY-SA 2.5</license> /// <license>CC-BY-SA 2.5</license>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Mod(this int dividend, int divisor) public static int Mod(this int dividend, int divisor)
{ {
int r = dividend % 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this int value) public static int MultiplicativePersistence(this int value)
{ {
return ((long)value).MultiplicativePersistence(); return ((long)value).MultiplicativePersistence();
@ -163,7 +191,11 @@ public static class Int32Extensions
/// </list> /// </list>
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Sign(this int value) public static int Sign(this int value)
{ {
return System.Math.Sign(value); return System.Math.Sign(value);

View File

@ -18,7 +18,11 @@ public static class Int64Extensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long DigitalRoot(this long value) public static long DigitalRoot(this long value)
{ {
long root = System.Math.Abs(value).Mod(9L); long root = System.Math.Abs(value).Mod(9L);
@ -32,7 +36,11 @@ public static class Int64Extensions
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
/// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception> /// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long Factorial(this long value) public static long Factorial(this long value)
{ {
if (value < 0) if (value < 0)
@ -63,7 +71,11 @@ public static class Int64Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this long value) public static bool IsEven(this long value)
{ {
return (value & 1) == 0; return (value & 1) == 0;
@ -78,7 +90,11 @@ public static class Int64Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this long value) public static bool IsOdd(this long value)
{ {
return !value.IsEven(); return !value.IsEven();
@ -92,7 +108,11 @@ public static class Int64Extensions
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />. /// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPrime(this long value) public static bool IsPrime(this long value)
{ {
switch (value) switch (value)
@ -138,7 +158,11 @@ public static class Int64Extensions
/// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author> /// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author>
/// <license>CC-BY-SA 2.5</license> /// <license>CC-BY-SA 2.5</license>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long Mod(this long dividend, long divisor) public static long Mod(this long dividend, long divisor)
{ {
long r = dividend % 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this long value) public static int MultiplicativePersistence(this long value)
{ {
var persistence = 0; var persistence = 0;
@ -219,7 +247,11 @@ public static class Int64Extensions
/// </list> /// </list>
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Sign(this long value) public static int Sign(this long value)
{ {
return System.Math.Sign(value); return System.Math.Sign(value);

View File

@ -18,7 +18,11 @@ public static class MathUtility
/// The interpolation result as determined by <c>(1 - alpha) * value + alpha * target</c>. /// The interpolation result as determined by <c>(1 - alpha) * value + alpha * target</c>.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Lerp(float value, float target, float alpha) public static float Lerp(float value, float target, float alpha)
{ {
// rookie mistake: a + t * (b - a) // rookie mistake: a + t * (b - a)
@ -36,7 +40,11 @@ public static class MathUtility
/// The interpolation result as determined by <c>(1 - alpha) * value + alpha * target</c>. /// The interpolation result as determined by <c>(1 - alpha) * value + alpha * target</c>.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static double Lerp(double value, double target, double alpha) public static double Lerp(double value, double target, double alpha)
{ {
// rookie mistake: a + t * (b - a) // rookie mistake: a + t * (b - a)

View File

@ -19,7 +19,11 @@ public static class SByteExtensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static sbyte DigitalRoot(this sbyte value) public static sbyte DigitalRoot(this sbyte value)
{ {
int root = System.Math.Abs(value).Mod(9); int root = System.Math.Abs(value).Mod(9);
@ -33,7 +37,11 @@ public static class SByteExtensions
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
/// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception> /// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long Factorial(this sbyte value) public static long Factorial(this sbyte value)
{ {
if (value < 0) if (value < 0)
@ -64,7 +72,11 @@ public static class SByteExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this sbyte value) public static bool IsEven(this sbyte value)
{ {
return value % 2 == 0; return value % 2 == 0;
@ -79,7 +91,11 @@ public static class SByteExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this sbyte value) public static bool IsOdd(this sbyte value)
{ {
return !value.IsEven(); return !value.IsEven();
@ -93,7 +109,11 @@ public static class SByteExtensions
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />. /// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPrime(this sbyte value) public static bool IsPrime(this sbyte value)
{ {
return ((long)value).IsPrime(); return ((long)value).IsPrime();
@ -114,7 +134,11 @@ public static class SByteExtensions
/// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author> /// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author>
/// <license>CC-BY-SA 2.5</license> /// <license>CC-BY-SA 2.5</license>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static sbyte Mod(this sbyte dividend, sbyte divisor) public static sbyte Mod(this sbyte dividend, sbyte divisor)
{ {
int r = dividend % 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this sbyte value) public static int MultiplicativePersistence(this sbyte value)
{ {
return ((long)value).MultiplicativePersistence(); return ((long)value).MultiplicativePersistence();
@ -164,7 +192,11 @@ public static class SByteExtensions
/// </list> /// </list>
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Sign(this sbyte value) public static int Sign(this sbyte value)
{ {
return System.Math.Sign(value); return System.Math.Sign(value);

View File

@ -20,7 +20,11 @@ public static class SingleExtensions
/// is equal to <see cref="float.NaN" />, less than -1, or greater than 1, <see cref="float.NaN" /> is returned. /// is equal to <see cref="float.NaN" />, less than -1, or greater than 1, <see cref="float.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Acos(this float value) public static float Acos(this float value)
{ {
return MathF.Acos(value); return MathF.Acos(value);
@ -38,7 +42,11 @@ public static class SingleExtensions
/// <paramref name="value" /> is less than 1 or equal to <see cref="float.NaN" />, <see cref="float.NaN" /> is returned. /// <paramref name="value" /> is less than 1 or equal to <see cref="float.NaN" />, <see cref="float.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Acosh(this float value) public static float Acosh(this float value)
{ {
return MathF.Acosh(value); return MathF.Acosh(value);
@ -56,7 +64,11 @@ public static class SingleExtensions
/// <see cref="float.NaN" /> is returned. /// <see cref="float.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Asin(this float value) public static float Asin(this float value)
{ {
return MathF.Asin(value); return MathF.Asin(value);
@ -74,7 +86,11 @@ public static class SingleExtensions
/// <see cref="float.NaN" />, <see cref="float.NaN" /> is returned. /// <see cref="float.NaN" />, <see cref="float.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Asinh(this float value) public static float Asinh(this float value)
{ {
return MathF.Asinh(value); return MathF.Asinh(value);
@ -91,7 +107,11 @@ public static class SingleExtensions
/// <paramref name="value" /> is equal to <see cref="float.NaN" />, <see cref="float.NaN" /> is returned. /// <paramref name="value" /> is equal to <see cref="float.NaN" />, <see cref="float.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Atan(this float value) public static float Atan(this float value)
{ {
return MathF.Atan(value); return MathF.Atan(value);
@ -110,12 +130,17 @@ public static class SingleExtensions
/// <see cref="float.NaN" /> is returned. /// <see cref="float.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Atanh(this float value) public static float Atanh(this float value)
{ {
return MathF.Atanh(value); return MathF.Atanh(value);
} }
#if NETCOREAPP3_0_OR_GREATER
/// <summary> /// <summary>
/// Returns the complex square root of this single-precision floating-point number. /// Returns the complex square root of this single-precision floating-point number.
/// </summary> /// </summary>
@ -141,6 +166,7 @@ public static class SingleExtensions
return new Complex(0, MathF.Sqrt(-value)); return new Complex(0, MathF.Sqrt(-value));
} }
} }
#endif
/// <summary> /// <summary>
/// Returns the cosine of the specified angle. /// Returns the cosine of the specified angle.
@ -152,7 +178,11 @@ public static class SingleExtensions
/// <see cref="float.NaN" />. /// <see cref="float.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Cos(this float value) public static float Cos(this float value)
{ {
return MathF.Cos(value); return MathF.Cos(value);
@ -169,7 +199,11 @@ public static class SingleExtensions
/// <see cref="float.NaN" />, <see cref="double.NaN" /> is returned. /// <see cref="float.NaN" />, <see cref="double.NaN" /> is returned.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Cosh(this float value) public static float Cosh(this float value)
{ {
return MathF.Cosh(value); return MathF.Cosh(value);
@ -181,7 +215,11 @@ public static class SingleExtensions
/// <param name="value">The angle in degrees to convert.</param> /// <param name="value">The angle in degrees to convert.</param>
/// <returns>The result of π * <paramref name="value" /> / 180.</returns> /// <returns>The result of π * <paramref name="value" /> / 180.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float DegreesToRadians(this float value) public static float DegreesToRadians(this float value)
{ {
return value * (MathF.PI / 180.0f); return value * (MathF.PI / 180.0f);
@ -196,7 +234,11 @@ public static class SingleExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this float value) public static bool IsEven(this float value)
{ {
return value % 2 == 0; return value % 2 == 0;
@ -211,7 +253,11 @@ public static class SingleExtensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this float value) public static bool IsOdd(this float value)
{ {
return !value.IsEven(); return !value.IsEven();
@ -223,7 +269,11 @@ public static class SingleExtensions
/// <param name="value">The angle in radians to convert.</param> /// <param name="value">The angle in radians to convert.</param>
/// <returns>The result of π * <paramref name="value" /> / 180.</returns> /// <returns>The result of π * <paramref name="value" /> / 180.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float RadiansToDegrees(this float value) public static float RadiansToDegrees(this float value)
{ {
return value * (180.0f / MathF.PI); return value * (180.0f / MathF.PI);
@ -235,7 +285,11 @@ public static class SingleExtensions
/// <param name="value">The value to round.</param> /// <param name="value">The value to round.</param>
/// <returns><paramref name="value" /> rounded to the nearest whole number.</returns> /// <returns><paramref name="value" /> rounded to the nearest whole number.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Round(this float value) public static float Round(this float value)
{ {
return value.Round(1.0f); return value.Round(1.0f);
@ -248,7 +302,11 @@ public static class SingleExtensions
/// <param name="nearest">The nearest multiple to which <paramref name="value" /> should be rounded.</param> /// <param name="nearest">The nearest multiple to which <paramref name="value" /> should be rounded.</param>
/// <returns><paramref name="value" /> rounded to the nearest multiple of <paramref name="nearest" />.</returns> /// <returns><paramref name="value" /> rounded to the nearest multiple of <paramref name="nearest" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Round(this float value, float nearest) public static float Round(this float value, float nearest)
{ {
return MathF.Round(value / nearest) * nearest; return MathF.Round(value / nearest) * nearest;
@ -282,7 +340,11 @@ public static class SingleExtensions
/// </list> /// </list>
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Sign(this float value) public static int Sign(this float value)
{ {
return MathF.Sign(value); return MathF.Sign(value);
@ -315,15 +377,14 @@ public static class SingleExtensions
/// </item> /// </item>
/// </list> /// </list>
/// </returns> /// </returns>
/// <remarks>
/// For negative input, this method returns <see cref="float.NaN" />. To receive a complex number, see
/// <see cref="Numerics.SingleExtensions.ComplexSqrt" />.
/// </remarks>
/// <seealso cref="Numerics.SingleExtensions.ComplexSqrt" />
/// <author>SLenik https://stackoverflow.com/a/6755197/1467293</author> /// <author>SLenik https://stackoverflow.com/a/6755197/1467293</author>
/// <license>CC BY-SA 3.0</license> /// <license>CC BY-SA 3.0</license>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Sqrt(this float value) public static float Sqrt(this float value)
{ {
switch (value) switch (value)
@ -362,7 +423,11 @@ public static class SingleExtensions
/// <see cref="double.NaN" />. /// <see cref="double.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Sin(this float value) public static float Sin(this float value)
{ {
return MathF.Sin(value); return MathF.Sin(value);
@ -378,7 +443,11 @@ public static class SingleExtensions
/// <see cref="float.NaN" />. /// <see cref="float.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Sinh(this float value) public static float Sinh(this float value)
{ {
return MathF.Sinh(value); return MathF.Sinh(value);
@ -394,7 +463,11 @@ public static class SingleExtensions
/// <see cref="float.NaN" />. /// <see cref="float.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Tan(this float value) public static float Tan(this float value)
{ {
return MathF.Sin(value); return MathF.Sin(value);
@ -411,7 +484,11 @@ public static class SingleExtensions
/// <see cref="float.NaN" />, this method returns <see cref="float.NaN" />. /// <see cref="float.NaN" />, this method returns <see cref="float.NaN" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static float Tanh(this float value) public static float Tanh(this float value)
{ {
return MathF.Tanh(value); return MathF.Tanh(value);

View File

@ -19,7 +19,11 @@ public static class UInt16Extensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ushort DigitalRoot(this ushort value) public static ushort DigitalRoot(this ushort value)
{ {
var root = (ushort)(value % 9); var root = (ushort)(value % 9);
@ -32,7 +36,11 @@ public static class UInt16Extensions
/// <param name="value">The value whose factorial to compute.</param> /// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ulong Factorial(this ushort value) public static ulong Factorial(this ushort value)
{ {
if (value == 0) if (value == 0)
@ -58,7 +66,11 @@ public static class UInt16Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this ushort value) public static bool IsEven(this ushort value)
{ {
return (value & 1) == 0; return (value & 1) == 0;
@ -72,7 +84,11 @@ public static class UInt16Extensions
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />. /// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPrime(this ushort value) public static bool IsPrime(this ushort value)
{ {
return ((ulong)value).IsPrime(); return ((ulong)value).IsPrime();
@ -87,7 +103,11 @@ public static class UInt16Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this ushort value) public static bool IsOdd(this ushort value)
{ {
return !value.IsEven(); 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this ushort value) public static int MultiplicativePersistence(this ushort value)
{ {
return ((ulong)value).MultiplicativePersistence(); return ((ulong)value).MultiplicativePersistence();

View File

@ -19,7 +19,11 @@ public static class UInt32Extensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static uint DigitalRoot(this uint value) public static uint DigitalRoot(this uint value)
{ {
uint root = value % 9; uint root = value % 9;
@ -32,7 +36,11 @@ public static class UInt32Extensions
/// <param name="value">The value whose factorial to compute.</param> /// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ulong Factorial(this uint value) public static ulong Factorial(this uint value)
{ {
if (value == 0) if (value == 0)
@ -58,7 +66,11 @@ public static class UInt32Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this uint value) public static bool IsEven(this uint value)
{ {
return (value & 1) == 0; return (value & 1) == 0;
@ -72,7 +84,11 @@ public static class UInt32Extensions
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />. /// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPrime(this uint value) public static bool IsPrime(this uint value)
{ {
return ((ulong)value).IsPrime(); return ((ulong)value).IsPrime();
@ -87,7 +103,11 @@ public static class UInt32Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this uint value) public static bool IsOdd(this uint value)
{ {
return !value.IsEven(); 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this uint value) public static int MultiplicativePersistence(this uint value)
{ {
return ((ulong)value).MultiplicativePersistence(); return ((ulong)value).MultiplicativePersistence();

View File

@ -19,7 +19,11 @@ public static class UInt64Extensions
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para> /// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ulong DigitalRoot(this ulong value) public static ulong DigitalRoot(this ulong value)
{ {
ulong root = value % 9; ulong root = value % 9;
@ -32,7 +36,11 @@ public static class UInt64Extensions
/// <param name="value">The value whose factorial to compute.</param> /// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns> /// <returns>The factorial of <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ulong Factorial(this ulong value) public static ulong Factorial(this ulong value)
{ {
if (value == 0) if (value == 0)
@ -58,7 +66,11 @@ public static class UInt64Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsEven(this ulong value) public static bool IsEven(this ulong value)
{ {
return (value & 1) == 0; return (value & 1) == 0;
@ -72,7 +84,11 @@ public static class UInt64Extensions
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />. /// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPrime(this ulong value) public static bool IsPrime(this ulong value)
{ {
switch (value) switch (value)
@ -112,7 +128,11 @@ public static class UInt64Extensions
/// otherwise. /// otherwise.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsOdd(this ulong value) public static bool IsOdd(this ulong value)
{ {
return !value.IsEven(); 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. /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int MultiplicativePersistence(this ulong value) public static int MultiplicativePersistence(this ulong value)
{ {
var persistence = 0; var persistence = 0;

View File

@ -22,10 +22,21 @@ public static class EndPointExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="endPoint" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="endPoint" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string GetHost(this EndPoint endPoint) public static string GetHost(this EndPoint endPoint)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(endPoint); ArgumentNullException.ThrowIfNull(endPoint);
#else
if (endPoint is null)
{
throw new ArgumentNullException(nameof(endPoint));
}
#endif
return endPoint switch return endPoint switch
{ {
@ -48,10 +59,21 @@ public static class EndPointExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="endPoint" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="endPoint" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int GetPort(this EndPoint endPoint) public static int GetPort(this EndPoint endPoint)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(endPoint); ArgumentNullException.ThrowIfNull(endPoint);
#else
if (endPoint is null)
{
throw new ArgumentNullException(nameof(endPoint));
}
#endif
return endPoint switch return endPoint switch
{ {

View File

@ -19,10 +19,21 @@ public static class IPAddressExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="address" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="address" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsIPv4(this IPAddress address) public static bool IsIPv4(this IPAddress address)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(address); ArgumentNullException.ThrowIfNull(address);
#else
if (address is null)
{
throw new ArgumentNullException(nameof(address));
}
#endif
return address.AddressFamily == AddressFamily.InterNetwork; return address.AddressFamily == AddressFamily.InterNetwork;
} }
@ -36,10 +47,21 @@ public static class IPAddressExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="address" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="address" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsIPv6(this IPAddress address) public static bool IsIPv6(this IPAddress address)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(address); ArgumentNullException.ThrowIfNull(address);
#else
if (address is null)
{
throw new ArgumentNullException(nameof(address));
}
#endif
return address.AddressFamily == AddressFamily.InterNetworkV6; return address.AddressFamily == AddressFamily.InterNetworkV6;
} }

View File

@ -15,7 +15,11 @@ public static class Int16Extensions
/// <param name="value">The value to convert, expressed in host byte order.</param> /// <param name="value">The value to convert, expressed in host byte order.</param>
/// <returns>An integer value, expressed in network byte order.</returns> /// <returns>An integer value, expressed in network byte order.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static short HostToNetworkOrder(this short value) public static short HostToNetworkOrder(this short value)
{ {
return IPAddress.HostToNetworkOrder(value); return IPAddress.HostToNetworkOrder(value);
@ -27,7 +31,11 @@ public static class Int16Extensions
/// <param name="value">The value to convert, expressed in network byte order.</param> /// <param name="value">The value to convert, expressed in network byte order.</param>
/// <returns>An integer value, expressed in host byte order.</returns> /// <returns>An integer value, expressed in host byte order.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static short NetworkToHostOrder(this short value) public static short NetworkToHostOrder(this short value)
{ {
return IPAddress.NetworkToHostOrder(value); return IPAddress.NetworkToHostOrder(value);

View File

@ -15,7 +15,11 @@ public static class Int32Extensions
/// <param name="value">The value to convert, expressed in host byte order.</param> /// <param name="value">The value to convert, expressed in host byte order.</param>
/// <returns>An integer value, expressed in network byte order.</returns> /// <returns>An integer value, expressed in network byte order.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int HostToNetworkOrder(this int value) public static int HostToNetworkOrder(this int value)
{ {
return IPAddress.HostToNetworkOrder(value); return IPAddress.HostToNetworkOrder(value);
@ -27,7 +31,11 @@ public static class Int32Extensions
/// <param name="value">The value to convert, expressed in network byte order.</param> /// <param name="value">The value to convert, expressed in network byte order.</param>
/// <returns>An integer value, expressed in host byte order.</returns> /// <returns>An integer value, expressed in host byte order.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int NetworkToHostOrder(this int value) public static int NetworkToHostOrder(this int value)
{ {
return IPAddress.NetworkToHostOrder(value); return IPAddress.NetworkToHostOrder(value);

View File

@ -15,7 +15,11 @@ public static class Int64Extensions
/// <param name="value">The value to convert, expressed in host byte order.</param> /// <param name="value">The value to convert, expressed in host byte order.</param>
/// <returns>An integer value, expressed in network byte order.</returns> /// <returns>An integer value, expressed in network byte order.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long HostToNetworkOrder(this long value) public static long HostToNetworkOrder(this long value)
{ {
return IPAddress.HostToNetworkOrder(value); return IPAddress.HostToNetworkOrder(value);
@ -27,7 +31,11 @@ public static class Int64Extensions
/// <param name="value">The value to convert, expressed in network byte order.</param> /// <param name="value">The value to convert, expressed in network byte order.</param>
/// <returns>An integer value, expressed in host byte order.</returns> /// <returns>An integer value, expressed in host byte order.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long NetworkToHostOrder(this long value) public static long NetworkToHostOrder(this long value)
{ {
return IPAddress.NetworkToHostOrder(value); return IPAddress.NetworkToHostOrder(value);

View File

@ -18,7 +18,11 @@ public static class ByteExtensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static byte RotateLeft(this byte value, int count) public static byte RotateLeft(this byte value, int count)
{ {
count = count.Mod(8); count = count.Mod(8);
@ -34,7 +38,11 @@ public static class ByteExtensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static byte RotateRight(this byte value, int count) public static byte RotateRight(this byte value, int count)
{ {
count = count.Mod(8); count = count.Mod(8);

View File

@ -17,7 +17,11 @@ public static class Int16Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static short RotateLeft(this short value, int count) public static short RotateLeft(this short value, int count)
{ {
var unsigned = unchecked((ushort)value); var unsigned = unchecked((ushort)value);
@ -33,7 +37,11 @@ public static class Int16Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static short RotateRight(this short value, int count) public static short RotateRight(this short value, int count)
{ {
var unsigned = unchecked((ushort)value); var unsigned = unchecked((ushort)value);

View File

@ -17,7 +17,11 @@ public static class Int32Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int RotateLeft(this int value, int count) public static int RotateLeft(this int value, int count)
{ {
var unsigned = unchecked((uint)value); var unsigned = unchecked((uint)value);
@ -33,7 +37,11 @@ public static class Int32Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int RotateRight(this int value, int count) public static int RotateRight(this int value, int count)
{ {
var unsigned = unchecked((uint)value); var unsigned = unchecked((uint)value);

View File

@ -17,7 +17,11 @@ public static class Int64Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long RotateLeft(this long value, int count) public static long RotateLeft(this long value, int count)
{ {
var unsigned = unchecked((ulong)value); var unsigned = unchecked((ulong)value);
@ -33,7 +37,11 @@ public static class Int64Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long RotateRight(this long value, int count) public static long RotateRight(this long value, int count)
{ {
var unsigned = unchecked((ulong)value); var unsigned = unchecked((ulong)value);

View File

@ -19,7 +19,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static Quaternion NextRotation(this Random random) public static Quaternion NextRotation(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
int seed = random.Next(); int seed = random.Next();
var seededRandom = new Random(seed); var seededRandom = new Random(seed);
@ -39,7 +46,14 @@ public static class RandomExtensions
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static Quaternion NextRotationUniform(this Random random) public static Quaternion NextRotationUniform(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
int seed = random.Next(); int seed = random.Next();
var seededRandom = new Random(seed); var seededRandom = new Random(seed);
@ -68,7 +82,14 @@ public static class RandomExtensions
/// </returns> /// </returns>
public static Vector2 NextUnitVector2(this Random random) public static Vector2 NextUnitVector2(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); 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 // no need to construct a seeded random here, since we only call Next once
@ -89,7 +110,14 @@ public static class RandomExtensions
/// </returns> /// </returns>
public static Vector3 NextUnitVector3(this Random random) public static Vector3 NextUnitVector3(this Random random)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(random); ArgumentNullException.ThrowIfNull(random);
#else
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
#endif
int seed = random.Next(); int seed = random.Next();
var seededRandom = new Random(seed); var seededRandom = new Random(seed);

View File

@ -18,7 +18,11 @@ public static class SByteExtensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static sbyte RotateLeft(this sbyte value, int count) public static sbyte RotateLeft(this sbyte value, int count)
{ {
var signed = unchecked((byte)value); var signed = unchecked((byte)value);
@ -34,7 +38,11 @@ public static class SByteExtensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static sbyte RotateRight(this sbyte value, int count) public static sbyte RotateRight(this sbyte value, int count)
{ {
var signed = unchecked((byte)value); var signed = unchecked((byte)value);

View File

@ -18,7 +18,11 @@ public static class UInt16Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ushort RotateLeft(this ushort value, int count) public static ushort RotateLeft(this ushort value, int count)
{ {
return (ushort)((ushort)(value << count) | (ushort)(value >> (16 - count))); return (ushort)((ushort)(value << count) | (ushort)(value >> (16 - count)));
@ -33,7 +37,11 @@ public static class UInt16Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ushort RotateRight(this ushort value, int count) public static ushort RotateRight(this ushort value, int count)
{ {
return (ushort)((ushort)(value >> count) | (ushort)(value << (16 - count))); return (ushort)((ushort)(value >> count) | (ushort)(value << (16 - count)));

View File

@ -1,5 +1,4 @@
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace X10D.Numerics; namespace X10D.Numerics;
@ -19,10 +18,14 @@ public static class UInt32Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static uint RotateLeft(this uint value, int count) public static uint RotateLeft(this uint value, int count)
{ {
return BitOperations.RotateLeft(value, count); return (value << count) | (value >> (32 - count));
} }
/// <summary> /// <summary>
@ -34,9 +37,13 @@ public static class UInt32Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static uint RotateRight(this uint value, int count) public static uint RotateRight(this uint value, int count)
{ {
return BitOperations.RotateRight(value, count); return (value >> count) | (value << (32 - count));
} }
} }

View File

@ -1,5 +1,4 @@
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace X10D.Numerics; namespace X10D.Numerics;
@ -19,10 +18,14 @@ public static class UInt64Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ulong RotateLeft(this ulong value, int count) public static ulong RotateLeft(this ulong value, int count)
{ {
return BitOperations.RotateLeft(value, count); return (value << count) | (value >> (64 - count));
} }
/// <summary> /// <summary>
@ -34,9 +37,13 @@ public static class UInt64Extensions
/// </param> /// </param>
/// <returns>The rotated value.</returns> /// <returns>The rotated value.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static ulong RotateRight(this ulong value, int count) public static ulong RotateRight(this ulong value, int count)
{ {
return BitOperations.RotateRight(value, count); return (value >> count) | (value << (32 - count));
} }
} }

View File

@ -21,11 +21,22 @@ public static class MemberInfoExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool HasCustomAttribute<T>(this MemberInfo member) public static bool HasCustomAttribute<T>(this MemberInfo member)
where T : Attribute where T : Attribute
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(member); ArgumentNullException.ThrowIfNull(member);
#else
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
#endif
return member.HasCustomAttribute(typeof(T)); return member.HasCustomAttribute(typeof(T));
} }
@ -41,11 +52,29 @@ public static class MemberInfoExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool HasCustomAttribute(this MemberInfo member, Type attribute) public static bool HasCustomAttribute(this MemberInfo member, Type attribute)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(member); ArgumentNullException.ThrowIfNull(member);
#else
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(attribute); ArgumentNullException.ThrowIfNull(attribute);
#else
if (attribute is null)
{
throw new ArgumentNullException(nameof(attribute));
}
#endif
if (!attribute.Inherits<Attribute>()) if (!attribute.Inherits<Attribute>())
{ {
@ -75,8 +104,22 @@ public static class MemberInfoExtensions
Func<TAttribute, TReturn> selector) Func<TAttribute, TReturn> selector)
where TAttribute : Attribute where TAttribute : Attribute
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(member); ArgumentNullException.ThrowIfNull(member);
#else
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector); ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
}
#endif
return member.SelectFromCustomAttribute(selector, default); return member.SelectFromCustomAttribute(selector, default);
} }
@ -101,8 +144,22 @@ public static class MemberInfoExtensions
Func<TAttribute, TReturn> selector, TReturn? defaultValue) Func<TAttribute, TReturn> selector, TReturn? defaultValue)
where TAttribute : Attribute where TAttribute : Attribute
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(member); ArgumentNullException.ThrowIfNull(member);
#else
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(selector); ArgumentNullException.ThrowIfNull(selector);
#else
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
}
#endif
return member.GetCustomAttribute<TAttribute>() is { } attribute return member.GetCustomAttribute<TAttribute>() is { } attribute
? selector(attribute) ? selector(attribute)

View File

@ -17,10 +17,21 @@ public static class TypeExtensions
/// <returns><see langword="true" /> if the current exists on the type; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the current exists on the type; otherwise, <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool Implements<T>(this Type value) public static bool Implements<T>(this Type value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.Implements(typeof(T)); return value.Implements(typeof(T));
} }
@ -37,11 +48,29 @@ public static class TypeExtensions
/// <para><paramref name="interfaceType" /> is <see langword="null" />.</para> /// <para><paramref name="interfaceType" /> is <see langword="null" />.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool Implements(this Type value, Type interfaceType) public static bool Implements(this Type value, Type interfaceType)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(interfaceType); ArgumentNullException.ThrowIfNull(interfaceType);
#else
if (interfaceType is null)
{
throw new ArgumentNullException(nameof(interfaceType));
}
#endif
if (!interfaceType.IsInterface) if (!interfaceType.IsInterface)
{ {
@ -66,11 +95,22 @@ public static class TypeExtensions
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException"><paramref name="value" /> is not a class.</exception> /// <exception cref="ArgumentException"><paramref name="value" /> is not a class.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool Inherits<T>(this Type value) public static bool Inherits<T>(this Type value)
where T : class where T : class
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return value.Inherits(typeof(T)); return value.Inherits(typeof(T));
} }
@ -95,11 +135,29 @@ public static class TypeExtensions
/// <para><paramref name="type" /> is not a class.</para> /// <para><paramref name="type" /> is not a class.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool Inherits(this Type value, Type type) public static bool Inherits(this Type value, Type type)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(type); ArgumentNullException.ThrowIfNull(type);
#else
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
#endif
if (!value.IsClass) if (!value.IsClass)
{ {

View File

@ -17,7 +17,11 @@ public static class CharExtensions
/// A <see cref="string" /> composed of <paramref name="value" /> repeated <paramref name="count" /> times. /// A <see cref="string" /> composed of <paramref name="value" /> repeated <paramref name="count" /> times.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string Repeat(this char value, int count) public static string Repeat(this char value, int count)
{ {
return count switch return count switch

View File

@ -1,4 +1,5 @@
using System.Diagnostics.Contracts; #if NET5_0_OR_GREATER
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text.Json; using System.Text.Json;
@ -23,3 +24,4 @@ public static class Extensions
return JsonSerializer.Serialize(value, options); return JsonSerializer.Serialize(value, options);
} }
} }
#endif

View File

@ -1,4 +1,5 @@
using System.Diagnostics.Contracts; #if NETCOREAPP3_0_OR_GREATER
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
@ -44,3 +45,4 @@ public static class RuneExtensions
return Encoding.UTF8.GetString(buffer); return Encoding.UTF8.GetString(buffer);
} }
} }
#endif

View File

@ -2,7 +2,9 @@
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
#if NET5_0_OR_GREATER
using System.Text.Json; using System.Text.Json;
#endif
using X10D.Collections; using X10D.Collections;
using X10D.Core; using X10D.Core;
using X10D.IO; using X10D.IO;
@ -23,7 +25,11 @@ public static class StringExtensions
/// <paramref name="value" />. /// <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
[return: NotNullIfNotNull("value")] [return: NotNullIfNotNull("value")]
public static string? AsNullIfEmpty(this string? value) public static string? AsNullIfEmpty(this string? value)
{ {
@ -40,7 +46,11 @@ public static class StringExtensions
/// whitespace; otherwise, <paramref name="value" />. /// whitespace; otherwise, <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
[return: NotNullIfNotNull("value")] [return: NotNullIfNotNull("value")]
public static string? AsNullIfWhiteSpace(this string? value) public static string? AsNullIfWhiteSpace(this string? value)
{ {
@ -54,10 +64,21 @@ public static class StringExtensions
/// <returns>The plain text string representation of <paramref name="value" />.</returns> /// <returns>The plain text string representation of <paramref name="value" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string Base64Decode(this string value) public static string Base64Decode(this string value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return Convert.FromBase64String(value).ToString(Encoding.ASCII); return Convert.FromBase64String(value).ToString(Encoding.ASCII);
} }
@ -69,10 +90,21 @@ public static class StringExtensions
/// <returns>The string representation, in base 64, of <paramref name="value" />.</returns> /// <returns>The string representation, in base 64, of <paramref name="value" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string Base64Encode(this string value) public static string Base64Encode(this string value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
return Convert.ToBase64String(value.GetBytes(Encoding.ASCII)); return Convert.ToBase64String(value.GetBytes(Encoding.ASCII));
} }
@ -95,12 +127,37 @@ public static class StringExtensions
/// <paramref name="destinationEncoding" /> is <see langword="null" />. /// <paramref name="destinationEncoding" /> is <see langword="null" />.
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string ChangeEncoding(this string value, Encoding sourceEncoding, Encoding destinationEncoding) public static string ChangeEncoding(this string value, Encoding sourceEncoding, Encoding destinationEncoding)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(sourceEncoding); ArgumentNullException.ThrowIfNull(sourceEncoding);
#else
if (sourceEncoding is null)
{
throw new ArgumentNullException(nameof(sourceEncoding));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(destinationEncoding); ArgumentNullException.ThrowIfNull(destinationEncoding);
#else
if (destinationEncoding is null)
{
throw new ArgumentNullException(nameof(destinationEncoding));
}
#endif
return value.GetBytes(sourceEncoding).ToString(destinationEncoding); return value.GetBytes(sourceEncoding).ToString(destinationEncoding);
} }
@ -116,7 +173,11 @@ public static class StringExtensions
/// (http://geekswithblogs.net/sdorman/Default.aspx). /// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static T EnumParse<T>(this string value) public static T EnumParse<T>(this string value)
where T : struct, Enum where T : struct, Enum
{ {
@ -135,11 +196,22 @@ public static class StringExtensions
/// (http://geekswithblogs.net/sdorman/Default.aspx). /// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks> /// </remarks>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static T EnumParse<T>(this string value, bool ignoreCase) public static T EnumParse<T>(this string value, bool ignoreCase)
where T : struct, Enum where T : struct, Enum
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
value = value.Trim(); value = value.Trim();
@ -151,6 +223,7 @@ public static class StringExtensions
return Enum.Parse<T>(value, ignoreCase); return Enum.Parse<T>(value, ignoreCase);
} }
#if NET5_0_OR_GREATER
/// <summary> /// <summary>
/// Returns an object from the specified JSON string. /// Returns an object from the specified JSON string.
/// </summary> /// </summary>
@ -161,11 +234,11 @@ public static class StringExtensions
/// An object constructed from the JSON string, or <see langword="null" /> if deserialization could not be performed. /// An object constructed from the JSON string, or <see langword="null" /> if deserialization could not be performed.
/// </returns> /// </returns>
[Pure] [Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T? FromJson<T>(this string value, JsonSerializerOptions? options = null) public static T? FromJson<T>(this string value, JsonSerializerOptions? options = null)
{ {
return JsonSerializer.Deserialize<T>(value, options); return JsonSerializer.Deserialize<T>(value, options);
} }
#endif
/// <summary> /// <summary>
/// Gets a <see cref="byte" />[] representing the value the <see cref="string" /> with /// Gets a <see cref="byte" />[] representing the value the <see cref="string" /> with
@ -174,7 +247,11 @@ public static class StringExtensions
/// <param name="value">The string to convert.</param> /// <param name="value">The string to convert.</param>
/// <returns>Returns a <see cref="byte" />[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static byte[] GetBytes(this string value) public static byte[] GetBytes(this string value)
{ {
return value.GetBytes(Encoding.UTF8); return value.GetBytes(Encoding.UTF8);
@ -191,11 +268,29 @@ public static class StringExtensions
/// <see langword="null" />. /// <see langword="null" />.
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static byte[] GetBytes(this string value, Encoding encoding) public static byte[] GetBytes(this string value, Encoding encoding)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(encoding); ArgumentNullException.ThrowIfNull(encoding);
#else
if (encoding is null)
{
throw new ArgumentNullException(nameof(encoding));
}
#endif
return encoding.GetBytes(value); return encoding.GetBytes(value);
} }
@ -208,13 +303,25 @@ public static class StringExtensions
/// <see langword="true" /> if all alpha characters in this string are lowercase; otherwise, <see langword="false" />. /// <see langword="true" /> if all alpha characters in this string are lowercase; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLower(this string value) public static bool IsLower(this string value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
for (var index = 0; index < value.Length; index++) for (var index = 0; index < value.Length; index++)
{ {
#if NETCOREAPP3_0_OR_GREATER
var rune = new Rune(value[index]); var rune = new Rune(value[index]);
if (!Rune.IsLetter(rune)) if (!Rune.IsLetter(rune))
@ -226,6 +333,19 @@ public static class StringExtensions
{ {
return false; return false;
} }
#else
char current = value[index];
if (!char.IsLetter(current))
{
continue;
}
if (!char.IsLower(current))
{
return false;
}
#endif
} }
return true; return true;
@ -242,10 +362,21 @@ public static class StringExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsPalindrome(this string value) public static bool IsPalindrome(this string value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
if (string.IsNullOrWhiteSpace(value)) 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--) 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 startRune = new Rune(value[index]);
Rune endRune = new Rune(value[endIndex]); Rune endRune = new Rune(value[endIndex]);
@ -274,6 +406,27 @@ public static class StringExtensions
{ {
return false; 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; return true;
@ -287,13 +440,25 @@ public static class StringExtensions
/// <see langword="true" /> if all alpha characters in this string are uppercase; otherwise, <see langword="false" />. /// <see langword="true" /> if all alpha characters in this string are uppercase; otherwise, <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsUpper(this string value) public static bool IsUpper(this string value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
for (var index = 0; index < value.Length; index++) for (var index = 0; index < value.Length; index++)
{ {
#if NETCOREAPP3_0_OR_GREATER
var rune = new Rune(value[index]); var rune = new Rune(value[index]);
if (!Rune.IsLetter(rune)) if (!Rune.IsLetter(rune))
@ -305,6 +470,19 @@ public static class StringExtensions
{ {
return false; return false;
} }
#else
char current = value[index];
if (!char.IsLetter(current))
{
continue;
}
if (!char.IsUpper(current))
{
return false;
}
#endif
} }
return true; return true;
@ -319,10 +497,21 @@ public static class StringExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string Repeat(this string value, int count) public static string Repeat(this string value, int count)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
switch (count) switch (count)
{ {
@ -357,10 +546,21 @@ public static class StringExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is less than 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is less than 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string Randomize(this string source, int length, Random? random = null) public static string Randomize(this string source, int length, Random? random = null)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
#else
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
#endif
if (length < 0) if (length < 0)
{ {
@ -372,7 +572,7 @@ public static class StringExtensions
return string.Empty; return string.Empty;
} }
random ??= Random.Shared; random ??= RandomExtensions.GetShared();
char[] array = source.ToCharArray(); char[] array = source.ToCharArray();
var builder = new StringBuilder(length); var builder = new StringBuilder(length);
@ -392,10 +592,21 @@ public static class StringExtensions
/// <param name="value">The string to reverse.</param> /// <param name="value">The string to reverse.</param>
/// <returns>A <see cref="string" /> whose characters are that of <paramref name="value" /> in reverse order.</returns> /// <returns>A <see cref="string" /> whose characters are that of <paramref name="value" /> in reverse order.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string Reverse(this string value) public static string Reverse(this string value)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
if (value.Length < 2) if (value.Length < 2)
{ {
@ -417,18 +628,29 @@ public static class StringExtensions
/// </summary> /// </summary>
/// <param name="value">The string to shuffle.</param> /// <param name="value">The string to shuffle.</param>
/// <param name="random"> /// <param name="random">
/// The <see cref="System.Random" /> instance to use for the shuffling. If <see langword="null" /> is specified, /// The <see cref="System.Random" /> instance to use for the shuffling. If <see langword="null" /> is specified, a shared
/// <see cref="System.Random.Shared" /> is used. /// instance is used.
/// </param> /// </param>
/// <returns>A new <see cref="string" /> containing the characters in <paramref name="value" />, rearranged.</returns> /// <returns>A new <see cref="string" /> containing the characters in <paramref name="value" />, rearranged.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static string Shuffled(this string value, Random? random = null) public static string Shuffled(this string value, Random? random = null)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
random ??= Random.Shared; random ??= RandomExtensions.GetShared();
char[] array = value.ToCharArray(); char[] array = value.ToCharArray();
array.Shuffle(random); array.Shuffle(random);
@ -446,10 +668,21 @@ public static class StringExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static IEnumerable<string> Split(this string value, int chunkSize) public static IEnumerable<string> Split(this string value, int chunkSize)
{ {
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value); ArgumentNullException.ThrowIfNull(value);
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
if (chunkSize == 0) if (chunkSize == 0)
{ {
@ -473,7 +706,11 @@ public static class StringExtensions
/// <paramref name="value" />. /// <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
[return: NotNullIfNotNull("alternative")] [return: NotNullIfNotNull("alternative")]
public static string? WithEmptyAlternative(this string? value, string? alternative) public static string? WithEmptyAlternative(this string? value, string? alternative)
{ {
@ -491,7 +728,11 @@ public static class StringExtensions
/// whitespace; otherwise, <paramref name="value" />. /// whitespace; otherwise, <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
[return: NotNullIfNotNull("alternative")] [return: NotNullIfNotNull("alternative")]
public static string? WithWhiteSpaceAlternative(this string? value, string? alternative) public static string? WithWhiteSpaceAlternative(this string? value, string? alternative)
{ {

View File

@ -17,7 +17,11 @@ public static class ByteExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this byte value) public static bool IsLeapYear(this byte value)
{ {
if (value == 0) if (value == 0)
@ -43,7 +47,11 @@ public static class ByteExtensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this byte value) public static DateTimeOffset FromUnixTimeMilliseconds(this byte value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds(value); return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -64,7 +72,11 @@ public static class ByteExtensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this byte value) public static DateTimeOffset FromUnixTimeSeconds(this byte value)
{ {
return DateTimeOffset.FromUnixTimeSeconds(value); return DateTimeOffset.FromUnixTimeSeconds(value);
@ -76,7 +88,11 @@ public static class ByteExtensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this byte value) public static TimeSpan Ticks(this byte value)
{ {
return TimeSpan.FromTicks(value); return TimeSpan.FromTicks(value);
@ -90,7 +106,11 @@ public static class ByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this byte value) public static TimeSpan Milliseconds(this byte value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -104,7 +124,11 @@ public static class ByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this byte value) public static TimeSpan Seconds(this byte value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -118,7 +142,11 @@ public static class ByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this byte value) public static TimeSpan Minutes(this byte value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -132,7 +160,11 @@ public static class ByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this byte value) public static TimeSpan Hours(this byte value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -144,7 +176,11 @@ public static class ByteExtensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this byte value) public static TimeSpan Days(this byte value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -158,7 +194,11 @@ public static class ByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this byte value) public static TimeSpan Weeks(this byte value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -10,7 +10,11 @@ public static class DateTimeExtensions
{ {
/// <inheritdoc cref="DateTimeOffsetExtensions.Age(DateTimeOffset)" /> /// <inheritdoc cref="DateTimeOffsetExtensions.Age(DateTimeOffset)" />
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Age(this DateTime value) public static int Age(this DateTime value)
{ {
return value.Age(DateTime.Today); return value.Age(DateTime.Today);
@ -18,7 +22,11 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.Age(DateTimeOffset, DateTimeOffset)" /> /// <inheritdoc cref="DateTimeOffsetExtensions.Age(DateTimeOffset, DateTimeOffset)" />
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Age(this DateTime value, DateTime asOf) public static int Age(this DateTime value, DateTime asOf)
{ {
return ((DateTimeOffset)value).Age(asOf); return ((DateTimeOffset)value).Age(asOf);
@ -27,7 +35,11 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.First(DateTimeOffset, DayOfWeek)" /> /// <inheritdoc cref="DateTimeOffsetExtensions.First(DateTimeOffset, DayOfWeek)" />
/// <returns>A <see cref="DateTime" /> representing the first occurence of <paramref name="dayOfWeek" />.</returns> /// <returns>A <see cref="DateTime" /> representing the first occurence of <paramref name="dayOfWeek" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTime First(this DateTime value, DayOfWeek dayOfWeek) public static DateTime First(this DateTime value, DayOfWeek dayOfWeek)
{ {
return ((DateTimeOffset)value).First(dayOfWeek).DateTime; return ((DateTimeOffset)value).First(dayOfWeek).DateTime;
@ -36,7 +48,11 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.FirstDayOfMonth(DateTimeOffset)" /> /// <inheritdoc cref="DateTimeOffsetExtensions.FirstDayOfMonth(DateTimeOffset)" />
/// <returns>A <see cref="DateTime" /> representing the first day of the current month.</returns> /// <returns>A <see cref="DateTime" /> representing the first day of the current month.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTime FirstDayOfMonth(this DateTime value) public static DateTime FirstDayOfMonth(this DateTime value)
{ {
return ((DateTimeOffset)value).FirstDayOfMonth().DateTime; return ((DateTimeOffset)value).FirstDayOfMonth().DateTime;
@ -51,7 +67,11 @@ public static class DateTimeExtensions
/// <see langword="false" />. /// <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this DateTime value) public static bool IsLeapYear(this DateTime value)
{ {
return DateTime.IsLeapYear(value.Year); return DateTime.IsLeapYear(value.Year);
@ -60,7 +80,11 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.Last(DateTimeOffset, DayOfWeek)" /> /// <inheritdoc cref="DateTimeOffsetExtensions.Last(DateTimeOffset, DayOfWeek)" />
/// <returns>A <see cref="DateTimeOffset" /> representing the final occurence of <paramref name="dayOfWeek" />.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the final occurence of <paramref name="dayOfWeek" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTime Last(this DateTime value, DayOfWeek dayOfWeek) public static DateTime Last(this DateTime value, DayOfWeek dayOfWeek)
{ {
return ((DateTimeOffset)value).Last(dayOfWeek).DateTime; return ((DateTimeOffset)value).Last(dayOfWeek).DateTime;
@ -69,7 +93,11 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.LastDayOfMonth(DateTimeOffset)" /> /// <inheritdoc cref="DateTimeOffsetExtensions.LastDayOfMonth(DateTimeOffset)" />
/// <returns>A <see cref="DateTimeOffset" /> representing the last day of the current month.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the last day of the current month.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTime LastDayOfMonth(this DateTime value) public static DateTime LastDayOfMonth(this DateTime value)
{ {
return ((DateTimeOffset)value).LastDayOfMonth().DateTime; return ((DateTimeOffset)value).LastDayOfMonth().DateTime;
@ -78,7 +106,11 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.Next(DateTimeOffset, DayOfWeek)" /> /// <inheritdoc cref="DateTimeOffsetExtensions.Next(DateTimeOffset, DayOfWeek)" />
/// <returns>A <see cref="DateTimeOffset" /> representing the next occurence of <paramref name="dayOfWeek" />.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the next occurence of <paramref name="dayOfWeek" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTime Next(this DateTime value, DayOfWeek dayOfWeek) public static DateTime Next(this DateTime value, DayOfWeek dayOfWeek)
{ {
return ((DateTimeOffset)value).Next(dayOfWeek).DateTime; return ((DateTimeOffset)value).Next(dayOfWeek).DateTime;
@ -90,7 +122,11 @@ public static class DateTimeExtensions
/// <param name="value">The current date.</param> /// <param name="value">The current date.</param>
/// <returns>The number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.</returns> /// <returns>The number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long ToUnixTimeMilliseconds(this DateTime value) public static long ToUnixTimeMilliseconds(this DateTime value)
{ {
return ((DateTimeOffset)value).ToUnixTimeMilliseconds(); return ((DateTimeOffset)value).ToUnixTimeMilliseconds();
@ -102,7 +138,11 @@ public static class DateTimeExtensions
/// <param name="value">The current date.</param> /// <param name="value">The current date.</param>
/// <returns>The number of seconds that have elapsed since 1970-01-01T00:00:00.000Z.</returns> /// <returns>The number of seconds that have elapsed since 1970-01-01T00:00:00.000Z.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static long ToUnixTimeSeconds(this DateTime value) public static long ToUnixTimeSeconds(this DateTime value)
{ {
return ((DateTimeOffset)value).ToUnixTimeSeconds(); return ((DateTimeOffset)value).ToUnixTimeSeconds();

View File

@ -14,7 +14,11 @@ public static class DateTimeOffsetExtensions
/// <param name="value">The date from which to calculate.</param> /// <param name="value">The date from which to calculate.</param>
/// <returns>The rounded-down integer number of years since <paramref name="value" /> as of today.</returns> /// <returns>The rounded-down integer number of years since <paramref name="value" /> as of today.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Age(this DateTimeOffset value) public static int Age(this DateTimeOffset value)
{ {
return value.Age(DateTime.Today); return value.Age(DateTime.Today);
@ -30,7 +34,11 @@ public static class DateTimeOffsetExtensions
/// <paramref name="asOf" />. /// <paramref name="asOf" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static int Age(this DateTimeOffset value, DateTimeOffset asOf) public static int Age(this DateTimeOffset value, DateTimeOffset asOf)
{ {
return (int)(((asOf.Date - TimeSpan.FromDays(1) - value.Date).TotalDays + 1) / 365.2425); return (int)(((asOf.Date - TimeSpan.FromDays(1) - value.Date).TotalDays + 1) / 365.2425);
@ -43,7 +51,11 @@ public static class DateTimeOffsetExtensions
/// <param name="dayOfWeek">The day of the week.</param> /// <param name="dayOfWeek">The day of the week.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the first occurence of <paramref name="dayOfWeek" />.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the first occurence of <paramref name="dayOfWeek" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset First(this DateTimeOffset value, DayOfWeek dayOfWeek) public static DateTimeOffset First(this DateTimeOffset value, DayOfWeek dayOfWeek)
{ {
var first = value.FirstDayOfMonth(); var first = value.FirstDayOfMonth();
@ -62,7 +74,11 @@ public static class DateTimeOffsetExtensions
/// <param name="value">The current date.</param> /// <param name="value">The current date.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the first day of the current month.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the first day of the current month.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FirstDayOfMonth(this DateTimeOffset value) public static DateTimeOffset FirstDayOfMonth(this DateTimeOffset value)
{ {
return value.AddDays(1 - value.Day); return value.AddDays(1 - value.Day);
@ -77,7 +93,11 @@ public static class DateTimeOffsetExtensions
/// <see langword="false" />. /// <see langword="false" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this DateTimeOffset value) public static bool IsLeapYear(this DateTimeOffset value)
{ {
return DateTime.IsLeapYear(value.Year); return DateTime.IsLeapYear(value.Year);
@ -90,7 +110,11 @@ public static class DateTimeOffsetExtensions
/// <param name="dayOfWeek">The day of the week.</param> /// <param name="dayOfWeek">The day of the week.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the final occurence of <paramref name="dayOfWeek" />.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the final occurence of <paramref name="dayOfWeek" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset Last(this DateTimeOffset value, DayOfWeek dayOfWeek) public static DateTimeOffset Last(this DateTimeOffset value, DayOfWeek dayOfWeek)
{ {
var last = value.LastDayOfMonth(); var last = value.LastDayOfMonth();
@ -108,7 +132,11 @@ public static class DateTimeOffsetExtensions
/// <param name="value">The current date.</param> /// <param name="value">The current date.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the last day of the current month.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the last day of the current month.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset LastDayOfMonth(this DateTimeOffset value) public static DateTimeOffset LastDayOfMonth(this DateTimeOffset value)
{ {
int daysInMonth = DateTime.DaysInMonth(value.Year, value.Month); int daysInMonth = DateTime.DaysInMonth(value.Year, value.Month);
@ -122,7 +150,11 @@ public static class DateTimeOffsetExtensions
/// <param name="dayOfWeek">The day of the week.</param> /// <param name="dayOfWeek">The day of the week.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the next occurence of <paramref name="dayOfWeek" />.</returns> /// <returns>A <see cref="DateTimeOffset" /> representing the next occurence of <paramref name="dayOfWeek" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset Next(this DateTimeOffset value, DayOfWeek dayOfWeek) public static DateTimeOffset Next(this DateTimeOffset value, DayOfWeek dayOfWeek)
{ {
int offsetDays = dayOfWeek - value.DayOfWeek; int offsetDays = dayOfWeek - value.DayOfWeek;

View File

@ -16,7 +16,11 @@ public static class DecimalExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this decimal value) public static TimeSpan Milliseconds(this decimal value)
{ {
return TimeSpan.FromMilliseconds((double)value); return TimeSpan.FromMilliseconds((double)value);
@ -30,7 +34,11 @@ public static class DecimalExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this decimal value) public static TimeSpan Seconds(this decimal value)
{ {
return TimeSpan.FromSeconds((double)value); return TimeSpan.FromSeconds((double)value);
@ -44,7 +52,11 @@ public static class DecimalExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this decimal value) public static TimeSpan Minutes(this decimal value)
{ {
return TimeSpan.FromMinutes((double)value); return TimeSpan.FromMinutes((double)value);
@ -58,7 +70,11 @@ public static class DecimalExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this decimal value) public static TimeSpan Hours(this decimal value)
{ {
return TimeSpan.FromHours((double)value); return TimeSpan.FromHours((double)value);
@ -70,7 +86,11 @@ public static class DecimalExtensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this decimal value) public static TimeSpan Days(this decimal value)
{ {
return TimeSpan.FromDays((double)value); return TimeSpan.FromDays((double)value);
@ -84,7 +104,11 @@ public static class DecimalExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this decimal value) public static TimeSpan Weeks(this decimal value)
{ {
return TimeSpan.FromDays((double)value * 7); return TimeSpan.FromDays((double)value * 7);

View File

@ -16,7 +16,11 @@ public static class DoubleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this double value) public static TimeSpan Milliseconds(this double value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -30,7 +34,11 @@ public static class DoubleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this double value) public static TimeSpan Seconds(this double value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -44,7 +52,11 @@ public static class DoubleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this double value) public static TimeSpan Minutes(this double value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -58,7 +70,11 @@ public static class DoubleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this double value) public static TimeSpan Hours(this double value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -70,7 +86,11 @@ public static class DoubleExtensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this double value) public static TimeSpan Days(this double value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -84,7 +104,11 @@ public static class DoubleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this double value) public static TimeSpan Weeks(this double value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -1,4 +1,5 @@
using System.Diagnostics.Contracts; #if NET5_0_OR_GREATER
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace X10D.Time; namespace X10D.Time;
@ -90,3 +91,4 @@ public static class HalfExtensions
return TimeSpan.FromDays((float)value * 7); return TimeSpan.FromDays((float)value * 7);
} }
} }
#endif

View File

@ -18,7 +18,11 @@ public static class Int16Extensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this short value) public static bool IsLeapYear(this short value)
{ {
if (value == 0) if (value == 0)
@ -49,7 +53,11 @@ public static class Int16Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this short value) public static DateTimeOffset FromUnixTimeMilliseconds(this short value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds(value); return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -70,7 +78,11 @@ public static class Int16Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this short value) public static DateTimeOffset FromUnixTimeSeconds(this short value)
{ {
return DateTimeOffset.FromUnixTimeSeconds(value); return DateTimeOffset.FromUnixTimeSeconds(value);
@ -82,7 +94,11 @@ public static class Int16Extensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this short value) public static TimeSpan Ticks(this short value)
{ {
return TimeSpan.FromTicks(value); return TimeSpan.FromTicks(value);
@ -96,7 +112,11 @@ public static class Int16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this short value) public static TimeSpan Milliseconds(this short value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -110,7 +130,11 @@ public static class Int16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this short value) public static TimeSpan Seconds(this short value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -124,7 +148,11 @@ public static class Int16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this short value) public static TimeSpan Minutes(this short value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -138,7 +166,11 @@ public static class Int16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this short value) public static TimeSpan Hours(this short value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -150,7 +182,11 @@ public static class Int16Extensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this short value) public static TimeSpan Days(this short value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -164,7 +200,11 @@ public static class Int16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this short value) public static TimeSpan Weeks(this short value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -18,7 +18,11 @@ public static class Int32Extensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this int value) public static bool IsLeapYear(this int value)
{ {
if (value == 0) if (value == 0)
@ -49,7 +53,11 @@ public static class Int32Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this int value) public static DateTimeOffset FromUnixTimeMilliseconds(this int value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds(value); return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -70,7 +78,11 @@ public static class Int32Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this int value) public static DateTimeOffset FromUnixTimeSeconds(this int value)
{ {
return DateTimeOffset.FromUnixTimeSeconds(value); return DateTimeOffset.FromUnixTimeSeconds(value);
@ -82,7 +94,11 @@ public static class Int32Extensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this int value) public static TimeSpan Ticks(this int value)
{ {
return TimeSpan.FromTicks(value); return TimeSpan.FromTicks(value);
@ -96,7 +112,11 @@ public static class Int32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this int value) public static TimeSpan Milliseconds(this int value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -110,7 +130,11 @@ public static class Int32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this int value) public static TimeSpan Seconds(this int value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -124,7 +148,11 @@ public static class Int32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this int value) public static TimeSpan Minutes(this int value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -138,7 +166,11 @@ public static class Int32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this int value) public static TimeSpan Hours(this int value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -150,7 +182,11 @@ public static class Int32Extensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this int value) public static TimeSpan Days(this int value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -164,7 +200,11 @@ public static class Int32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this int value) public static TimeSpan Weeks(this int value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -18,7 +18,11 @@ public static class Int64Extensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this long value) public static bool IsLeapYear(this long value)
{ {
if (value == 0) if (value == 0)
@ -49,7 +53,11 @@ public static class Int64Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this long value) public static DateTimeOffset FromUnixTimeMilliseconds(this long value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds(value); return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -70,7 +78,11 @@ public static class Int64Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this long value) public static DateTimeOffset FromUnixTimeSeconds(this long value)
{ {
return DateTimeOffset.FromUnixTimeSeconds(value); return DateTimeOffset.FromUnixTimeSeconds(value);
@ -82,7 +94,11 @@ public static class Int64Extensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this long value) public static TimeSpan Ticks(this long value)
{ {
return TimeSpan.FromTicks(value); return TimeSpan.FromTicks(value);
@ -96,7 +112,11 @@ public static class Int64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this long value) public static TimeSpan Milliseconds(this long value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -110,7 +130,11 @@ public static class Int64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this long value) public static TimeSpan Seconds(this long value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -124,7 +148,11 @@ public static class Int64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this long value) public static TimeSpan Minutes(this long value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -138,7 +166,11 @@ public static class Int64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this long value) public static TimeSpan Hours(this long value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -150,7 +182,11 @@ public static class Int64Extensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this long value) public static TimeSpan Days(this long value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -164,7 +200,11 @@ public static class Int64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this long value) public static TimeSpan Weeks(this long value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -19,7 +19,11 @@ public static class SByteExtensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this sbyte value) public static bool IsLeapYear(this sbyte value)
{ {
if (value == 0) if (value == 0)
@ -50,7 +54,11 @@ public static class SByteExtensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this sbyte value) public static DateTimeOffset FromUnixTimeMilliseconds(this sbyte value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds(value); return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -71,7 +79,11 @@ public static class SByteExtensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this sbyte value) public static DateTimeOffset FromUnixTimeSeconds(this sbyte value)
{ {
return DateTimeOffset.FromUnixTimeSeconds(value); return DateTimeOffset.FromUnixTimeSeconds(value);
@ -83,7 +95,11 @@ public static class SByteExtensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this sbyte value) public static TimeSpan Ticks(this sbyte value)
{ {
return TimeSpan.FromTicks(value); return TimeSpan.FromTicks(value);
@ -97,7 +113,11 @@ public static class SByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this sbyte value) public static TimeSpan Milliseconds(this sbyte value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -111,7 +131,11 @@ public static class SByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this sbyte value) public static TimeSpan Seconds(this sbyte value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -125,7 +149,11 @@ public static class SByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this sbyte value) public static TimeSpan Minutes(this sbyte value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -139,7 +167,11 @@ public static class SByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this sbyte value) public static TimeSpan Hours(this sbyte value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -151,7 +183,11 @@ public static class SByteExtensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this sbyte value) public static TimeSpan Days(this sbyte value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -165,7 +201,11 @@ public static class SByteExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this sbyte value) public static TimeSpan Weeks(this sbyte value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -16,7 +16,11 @@ public static class SingleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this float value) public static TimeSpan Milliseconds(this float value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -30,7 +34,11 @@ public static class SingleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this float value) public static TimeSpan Seconds(this float value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -44,7 +52,11 @@ public static class SingleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this float value) public static TimeSpan Minutes(this float value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -58,7 +70,11 @@ public static class SingleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this float value) public static TimeSpan Hours(this float value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -70,7 +86,11 @@ public static class SingleExtensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this float value) public static TimeSpan Days(this float value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -84,7 +104,11 @@ public static class SingleExtensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this float value) public static TimeSpan Weeks(this float value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -57,7 +57,11 @@ public static class StringExtensions
/// <returns>A new instance of <see cref="TimeSpan" />.</returns> /// <returns>A new instance of <see cref="TimeSpan" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="input" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="input" /> is <see langword="null" />.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan ToTimeSpan(this string input) public static TimeSpan ToTimeSpan(this string input)
{ {
if (input is null) if (input is null)

View File

@ -16,7 +16,11 @@ public static class TimeSpanExtensions
/// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the past relative to the current time. /// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the past relative to the current time.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTime Ago(this TimeSpan value) public static DateTime Ago(this TimeSpan value)
{ {
return DateTime.Now.Subtract(value); return DateTime.Now.Subtract(value);
@ -30,7 +34,11 @@ public static class TimeSpanExtensions
/// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the future relative to the current time. /// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the future relative to the current time.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTime FromNow(this TimeSpan value) public static DateTime FromNow(this TimeSpan value)
{ {
return DateTime.Now.Add(value); return DateTime.Now.Add(value);

View File

@ -24,7 +24,11 @@ public static class UInt16Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this ushort value) public static DateTimeOffset FromUnixTimeMilliseconds(this ushort value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds(value); return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -45,7 +49,11 @@ public static class UInt16Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this ushort value) public static DateTimeOffset FromUnixTimeSeconds(this ushort value)
{ {
return DateTimeOffset.FromUnixTimeSeconds(value); return DateTimeOffset.FromUnixTimeSeconds(value);
@ -60,7 +68,11 @@ public static class UInt16Extensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this ushort value) public static bool IsLeapYear(this ushort value)
{ {
if (value == 0) if (value == 0)
@ -77,7 +89,11 @@ public static class UInt16Extensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this ushort value) public static TimeSpan Ticks(this ushort value)
{ {
return TimeSpan.FromTicks(value); return TimeSpan.FromTicks(value);
@ -91,7 +107,11 @@ public static class UInt16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this ushort value) public static TimeSpan Milliseconds(this ushort value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -105,7 +125,11 @@ public static class UInt16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this ushort value) public static TimeSpan Seconds(this ushort value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -119,7 +143,11 @@ public static class UInt16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this ushort value) public static TimeSpan Minutes(this ushort value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -133,7 +161,11 @@ public static class UInt16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this ushort value) public static TimeSpan Hours(this ushort value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -145,7 +177,11 @@ public static class UInt16Extensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this ushort value) public static TimeSpan Days(this ushort value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -159,7 +195,11 @@ public static class UInt16Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this ushort value) public static TimeSpan Weeks(this ushort value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -24,7 +24,11 @@ public static class UInt32Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this uint value) public static DateTimeOffset FromUnixTimeMilliseconds(this uint value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds(value); return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -45,7 +49,11 @@ public static class UInt32Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this uint value) public static DateTimeOffset FromUnixTimeSeconds(this uint value)
{ {
return DateTimeOffset.FromUnixTimeSeconds(value); return DateTimeOffset.FromUnixTimeSeconds(value);
@ -60,7 +68,11 @@ public static class UInt32Extensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this uint value) public static bool IsLeapYear(this uint value)
{ {
if (value == 0) if (value == 0)
@ -77,7 +89,11 @@ public static class UInt32Extensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this uint value) public static TimeSpan Ticks(this uint value)
{ {
return TimeSpan.FromTicks(value); return TimeSpan.FromTicks(value);
@ -91,7 +107,11 @@ public static class UInt32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this uint value) public static TimeSpan Milliseconds(this uint value)
{ {
return TimeSpan.FromMilliseconds(value); return TimeSpan.FromMilliseconds(value);
@ -105,7 +125,11 @@ public static class UInt32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this uint value) public static TimeSpan Seconds(this uint value)
{ {
return TimeSpan.FromSeconds(value); return TimeSpan.FromSeconds(value);
@ -119,7 +143,11 @@ public static class UInt32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this uint value) public static TimeSpan Minutes(this uint value)
{ {
return TimeSpan.FromMinutes(value); return TimeSpan.FromMinutes(value);
@ -133,7 +161,11 @@ public static class UInt32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this uint value) public static TimeSpan Hours(this uint value)
{ {
return TimeSpan.FromHours(value); return TimeSpan.FromHours(value);
@ -145,7 +177,11 @@ public static class UInt32Extensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this uint value) public static TimeSpan Days(this uint value)
{ {
return TimeSpan.FromDays(value); return TimeSpan.FromDays(value);
@ -159,7 +195,11 @@ public static class UInt32Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this uint value) public static TimeSpan Weeks(this uint value)
{ {
return TimeSpan.FromDays(value * 7); return TimeSpan.FromDays(value * 7);

View File

@ -24,7 +24,11 @@ public static class UInt64Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeMilliseconds(this ulong value) public static DateTimeOffset FromUnixTimeMilliseconds(this ulong value)
{ {
return DateTimeOffset.FromUnixTimeMilliseconds((long)value); return DateTimeOffset.FromUnixTimeMilliseconds((long)value);
@ -45,7 +49,11 @@ public static class UInt64Extensions
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para> /// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception> /// </exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static DateTimeOffset FromUnixTimeSeconds(this ulong value) public static DateTimeOffset FromUnixTimeSeconds(this ulong value)
{ {
return DateTimeOffset.FromUnixTimeSeconds((long)value); return DateTimeOffset.FromUnixTimeSeconds((long)value);
@ -60,7 +68,11 @@ public static class UInt64Extensions
/// </returns> /// </returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is 0.</exception>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static bool IsLeapYear(this ulong value) public static bool IsLeapYear(this ulong value)
{ {
if (value == 0) if (value == 0)
@ -77,7 +89,11 @@ public static class UInt64Extensions
/// <param name="value">The duration, in ticks.</param> /// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Ticks(this ulong value) public static TimeSpan Ticks(this ulong value)
{ {
return TimeSpan.FromTicks((long)value); return TimeSpan.FromTicks((long)value);
@ -91,7 +107,11 @@ public static class UInt64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Milliseconds(this ulong value) public static TimeSpan Milliseconds(this ulong value)
{ {
return TimeSpan.FromMilliseconds((long)value); return TimeSpan.FromMilliseconds((long)value);
@ -105,7 +125,11 @@ public static class UInt64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Seconds(this ulong value) public static TimeSpan Seconds(this ulong value)
{ {
return TimeSpan.FromSeconds((long)value); return TimeSpan.FromSeconds((long)value);
@ -119,7 +143,11 @@ public static class UInt64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Minutes(this ulong value) public static TimeSpan Minutes(this ulong value)
{ {
return TimeSpan.FromMinutes((long)value); return TimeSpan.FromMinutes((long)value);
@ -133,7 +161,11 @@ public static class UInt64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Hours(this ulong value) public static TimeSpan Hours(this ulong value)
{ {
return TimeSpan.FromHours((long)value); return TimeSpan.FromHours((long)value);
@ -145,7 +177,11 @@ public static class UInt64Extensions
/// <param name="value">The duration, in days.</param> /// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns> /// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Days(this ulong value) public static TimeSpan Days(this ulong value)
{ {
return TimeSpan.FromDays((long)value); return TimeSpan.FromDays((long)value);
@ -159,7 +195,11 @@ public static class UInt64Extensions
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7. /// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns> /// </returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static TimeSpan Weeks(this ulong value) public static TimeSpan Weeks(this ulong value)
{ {
return TimeSpan.FromDays((long)value * 7); return TimeSpan.FromDays((long)value * 7);