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

Decorate Pure functions with PureAttribute

This commit is contained in:
Oliver Booth 2022-04-29 22:14:39 +01:00
parent 06413fd710
commit 2922b628f2
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
62 changed files with 528 additions and 44 deletions

View File

@ -1,4 +1,6 @@
namespace X10D.Collections;
using System.Diagnostics.Contracts;
namespace X10D.Collections;
/// <summary>
/// Extension methods for <see cref="Array" />.
@ -12,6 +14,7 @@ public static class ArrayExtensions
/// <typeparam name="T">The type of the elements in the array.</typeparam>
/// <returns>A <see cref="IReadOnlyCollection{T}" /> wrapper for the specified array.</returns>
/// <exception cref="ArgumentNullException"><paramref name="array" /> is <see langword="null" />.</exception>
[Pure]
public static IReadOnlyCollection<T> AsReadOnly<T>(this T[] array)
{
if (array is null)

View File

@ -1,3 +1,5 @@
using System.Diagnostics.Contracts;
namespace X10D.Collections;
/// <summary>
@ -13,6 +15,7 @@ public static class BoolListExtensions
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 8 elements.</exception>
/// <author>Alpha Anar</author>
[Pure]
public static byte PackByte(this IReadOnlyList<bool> source)
{
if (source is null)
@ -42,6 +45,7 @@ public static class BoolListExtensions
/// <returns>A 16-bit signed integer containing the packed booleans.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 16 elements.</exception>
[Pure]
public static short PackInt16(this IReadOnlyList<bool> source)
{
if (source is null)
@ -71,6 +75,7 @@ public static class BoolListExtensions
/// <returns>A 32-bit signed integer containing the packed booleans.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 32 elements.</exception>
[Pure]
public static int PackInt32(this IReadOnlyList<bool> source)
{
if (source is null)
@ -100,6 +105,7 @@ public static class BoolListExtensions
/// <returns>A 64-bit signed integer containing the packed booleans.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 64 elements.</exception>
[Pure]
public static long PackInt64(this IReadOnlyList<bool> source)
{
if (source is null)

View File

@ -1,4 +1,6 @@
namespace X10D.Collections;
using System.Diagnostics.Contracts;
namespace X10D.Collections;
/// <summary>
/// Collection-related extension methods for <see cref="byte" />.
@ -12,6 +14,7 @@ public static class ByteExtensions
/// </summary>
/// <param name="value">The value to unpack.</param>
/// <returns>An array of <see cref="bool" /> with length 8.</returns>
[Pure]
public static bool[] Unpack(this byte value)
{
Span<bool> buffer = stackalloc bool[Size];
@ -25,7 +28,6 @@ public static class ByteExtensions
/// <param name="value">The value to unpack.</param>
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
/// <author>Alpha Anar</author>
public static void Unpack(this byte value, Span<bool> destination)
{
if (destination.Length < Size)

View File

@ -1,4 +1,5 @@
using System.Web;
using System.Diagnostics.Contracts;
using System.Web;
namespace X10D.Collections;
@ -179,6 +180,7 @@ public static class DictionaryExtensions
/// <typeparam name="TValue">The type of the value element of the key/value pair.</typeparam>
/// <param name="source">The source dictionary.</param>
/// <returns>A <see cref="string" /> representing the dictionary as a key=value set, concatenated with <c>;</c>.</returns>
[Pure]
public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
{
if (source is null)
@ -215,6 +217,7 @@ public static class DictionaryExtensions
/// A transform function to apply to the <see cref="KeyValuePair{TKey,TValue}.Value" /> of each element.
/// </param>
/// <returns>A <see cref="string" /> representing the dictionary as a key=value set, concatenated with <c>;</c>.</returns>
[Pure]
public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source,
Func<TValue, string?> selector)
{
@ -255,6 +258,7 @@ public static class DictionaryExtensions
/// A transform function to apply to the <see cref="KeyValuePair{TKey,TValue}.Value" /> of each element.
/// </param>
/// <returns>A <see cref="string" /> representing the dictionary as a key=value set, concatenated with <c>;</c>.</returns>
[Pure]
public static string ToConnectionString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source,
Func<TKey, string> keySelector, Func<TValue, string?> valueSelector)
where TKey : notnull
@ -289,6 +293,7 @@ public static class DictionaryExtensions
/// <typeparam name="TValue">The type of the value element of the key/value pair.</typeparam>
/// <param name="source">The source dictionary.</param>
/// <returns>A <see cref="string" /> representing the dictionary as a key=value set, concatenated with <c>&amp;</c>.</returns>
[Pure]
public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
where TKey : notnull
{
@ -317,6 +322,7 @@ public static class DictionaryExtensions
/// A transform function to apply to the <see cref="KeyValuePair{TKey,TValue}.Value" /> of each element.
/// </param>
/// <returns>A <see cref="string" /> representing the dictionary as a key=value set, concatenated with <c>&amp;</c>.</returns>
[Pure]
public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source,
Func<TValue, string?> selector)
where TKey : notnull
@ -355,6 +361,7 @@ public static class DictionaryExtensions
/// A transform function to apply to the <see cref="KeyValuePair{TKey,TValue}.Value" /> of each element.
/// </param>
/// <returns>A <see cref="string" /> representing the dictionary as a key=value set, concatenated with <c>&amp;</c>.</returns>
[Pure]
public static string ToGetParameters<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source,
Func<TKey, string> keySelector, Func<TValue, string?> valueSelector)
where TKey : notnull

View File

@ -1,4 +1,6 @@
namespace X10D.Collections;
using System.Diagnostics.Contracts;
namespace X10D.Collections;
/// <summary>
/// Extension methods for <see cref="IEnumerable{T}" />.
@ -11,6 +13,7 @@ public static class EnumerableExtensions
/// <typeparam name="T">The element type.</typeparam>
/// <param name="source">The <see cref="IEnumerable{T}" /> to shuffle.</param>
/// <param name="random">Optional. The <see cref="System.Random" /> instance to use for the shuffling.</param>
[Pure]
public static IReadOnlyCollection<T> Shuffled<T>(this IEnumerable<T> source, Random? random = null)
{
var list = new List<T>(source);

View File

@ -1,4 +1,6 @@
namespace X10D.Collections;
using System.Diagnostics.Contracts;
namespace X10D.Collections;
/// <summary>
/// Collection-related extension methods for <see cref="short" />.
@ -12,6 +14,7 @@ public static class Int16Extensions
/// </summary>
/// <param name="value">The value to unpack.</param>
/// <returns>An array of <see cref="bool" /> with length 16.</returns>
[Pure]
public static bool[] Unpack(this short value)
{
Span<bool> buffer = stackalloc bool[Size];

View File

@ -1,4 +1,6 @@
namespace X10D.Collections;
using System.Diagnostics.Contracts;
namespace X10D.Collections;
/// <summary>
/// Collection-related extension methods for <see cref="int" />.
@ -12,6 +14,7 @@ public static class Int32Extensions
/// </summary>
/// <param name="value">The value to unpack.</param>
/// <returns>An array of <see cref="bool" /> with length 32.</returns>
[Pure]
public static bool[] Unpack(this int value)
{
Span<bool> buffer = stackalloc bool[Size];

View File

@ -1,4 +1,6 @@
namespace X10D.Collections;
using System.Diagnostics.Contracts;
namespace X10D.Collections;
/// <summary>
/// Collection-related extension methods for <see cref="long" />.
@ -12,6 +14,7 @@ public static class Int64Extensions
/// </summary>
/// <param name="value">The value to unpack.</param>
/// <returns>An array of <see cref="bool" /> with length 64.</returns>
[Pure]
public static bool[] Unpack(this long value)
{
Span<bool> buffer = stackalloc bool[Size];

View File

@ -1,4 +1,5 @@
using X10D.Core;
using System.Diagnostics.Contracts;
using X10D.Core;
namespace X10D.Collections;
@ -94,6 +95,7 @@ public static class ListExtensions
/// var number = list.Random();
/// </code>
/// </example>
[Pure]
public static T Random<T>(this IReadOnlyList<T> source, Random? random = null)
{
if (source is null)

View File

@ -1,4 +1,6 @@
namespace X10D.Core;
using System.Diagnostics.Contracts;
namespace X10D.Core;
/// <summary>
/// Extension methods for <see langword="enum" /> types.
@ -14,6 +16,7 @@ public static class EnumExtensions
/// A value of <typeparamref name="T" /> that is considered to be the next value defined after <paramref name="value" />,
/// or the first value if <paramref name="value" /> is the final field of the enumeration.
/// </returns>
[Pure]
public static T Next<T>(this T value)
where T : struct, Enum
{
@ -33,6 +36,7 @@ public static class EnumExtensions
/// <paramref name="value" />.
/// </returns>
/// <exception cref="IndexOutOfRangeException"><paramref name="value" /> is the final field of the enumeration.</exception>
[Pure]
public static T NextUnchecked<T>(this T value)
where T : struct, Enum
{
@ -50,6 +54,7 @@ public static class EnumExtensions
/// A value of <typeparamref name="T" /> that is considered to be the previous value defined after
/// <paramref name="value" />, or the last value if <paramref name="value" /> is the first field of the enumeration.
/// </returns>
[Pure]
public static T Previous<T>(this T value)
where T : struct, Enum
{
@ -73,6 +78,7 @@ public static class EnumExtensions
/// <paramref name="value" />, or the last value if <paramref name="value" /> is the first field of the enumeration.
/// </returns>
/// <exception cref="IndexOutOfRangeException"><paramref name="value" /> is the first field of the enumeration.</exception>
[Pure]
public static T PreviousUnchecked<T>(this T value)
where T : struct, Enum
{

View File

@ -1,4 +1,6 @@
namespace X10D.Core;
using System.Diagnostics.Contracts;
namespace X10D.Core;
/// <summary>
/// Extension methods which apply to all types.
@ -13,6 +15,7 @@ public static class Extensions
/// <returns>
/// An array of type <typeparamref name="T" /> with length 1, whose only element is <paramref name="value" />.
/// </returns>
[Pure]
public static T?[] AsArrayValue<T>(this T? value)
{
return new[] {value};
@ -26,6 +29,7 @@ public static class Extensions
/// <returns>
/// An enumerable collection of type <typeparamref name="T" />, whose only element is <paramref name="value" />.
/// </returns>
[Pure]
public static IEnumerable<T?> AsEnumerableValue<T>(this T? value)
{
yield return value;
@ -39,6 +43,7 @@ public static class Extensions
/// <typeparam name="T">The type of <paramref name="value"/>.</typeparam>
/// <returns>An enumerable collection containing <paramref name="value" /> repeated <paramref name="count" /> times.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count" /> is less than 0.</exception>
[Pure]
public static IEnumerable<T> RepeatValue<T>(this T value, int count)
{
if (count < 0)

View File

@ -1,4 +1,6 @@
namespace X10D.IO;
using System.Diagnostics.Contracts;
namespace X10D.IO;
/// <summary>
/// Extension methods for <see cref="bool" />.
@ -10,6 +12,7 @@ public static class BooleanExtensions
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>An array of bytes with length 1.</returns>
[Pure]
public static byte[] GetBytes(this bool value)
{
return BitConverter.GetBytes(value);

View File

@ -1,4 +1,5 @@
using X10D.Core;
using System.Diagnostics.Contracts;
using X10D.Core;
namespace X10D.IO;
@ -12,6 +13,7 @@ public static class ByteExtensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 1.</returns>
[Pure]
public static byte[] GetBytes(this byte value)
{
return value.AsArrayValue();

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -12,6 +13,7 @@ public static class DoubleExtensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
[Pure]
public static byte[] GetBytes(this double value)
{
Span<byte> buffer = stackalloc byte[8];
@ -25,6 +27,7 @@ public static class DoubleExtensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 8.</returns>
[Pure]
public static byte[] GetBytes(this double value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[8];

View File

@ -1,4 +1,5 @@
using System.Security.Cryptography;
using System.Diagnostics.Contracts;
using System.Security.Cryptography;
namespace X10D.IO;
@ -24,6 +25,7 @@ public static class FileInfoExtensions
/// <c>Create</c> method returns a type that is not assignable to <typeparamref name="T" />.
/// </exception>
/// <exception cref="ObjectDisposedException">The stream has already been disposed.</exception>
[Pure]
public static byte[] GetHash<T>(this FileInfo value)
where T : HashAlgorithm
{

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -12,6 +13,7 @@ public static class Int16Extensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
[Pure]
public static byte[] GetBytes(this short value)
{
Span<byte> buffer = stackalloc byte[2];
@ -25,6 +27,7 @@ public static class Int16Extensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 2.</returns>
[Pure]
public static byte[] GetBytes(this short value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[2];

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -12,6 +13,7 @@ public static class Int32Extensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
[Pure]
public static byte[] GetBytes(this int value)
{
Span<byte> buffer = stackalloc byte[4];
@ -25,6 +27,7 @@ public static class Int32Extensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 4.</returns>
[Pure]
public static byte[] GetBytes(this int value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[4];

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -12,6 +13,7 @@ public static class Int64Extensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
[Pure]
public static byte[] GetBytes(this long value)
{
Span<byte> buffer = stackalloc byte[8];
@ -25,6 +27,7 @@ public static class Int64Extensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 8.</returns>
[Pure]
public static byte[] GetBytes(this long value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[8];

View File

@ -1,4 +1,6 @@
namespace X10D.IO;
using System.Diagnostics.Contracts;
namespace X10D.IO;
/// <summary>
/// IO-related extension methods for <see cref="sbyte" />.
@ -11,6 +13,7 @@ public static class SByteExtensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 1.</returns>
[Pure]
public static byte[] GetBytes(this sbyte value)
{
Span<byte> buffer = stackalloc byte[1];

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -12,6 +13,7 @@ public static class SingleExtensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
[Pure]
public static byte[] GetBytes(this float value)
{
Span<byte> buffer = stackalloc byte[4];
@ -25,6 +27,7 @@ public static class SingleExtensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 4.</returns>
[Pure]
public static byte[] GetBytes(this float value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[4];

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -13,6 +14,7 @@ public static class UInt16Extensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
[Pure]
public static byte[] GetBytes(this ushort value)
{
Span<byte> buffer = stackalloc byte[2];
@ -26,6 +28,7 @@ public static class UInt16Extensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 2.</returns>
[Pure]
public static byte[] GetBytes(this ushort value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[2];

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -13,6 +14,7 @@ public static class UInt32Extensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
[Pure]
public static byte[] GetBytes(this uint value)
{
Span<byte> buffer = stackalloc byte[4];
@ -26,6 +28,7 @@ public static class UInt32Extensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 4.</returns>
[Pure]
public static byte[] GetBytes(this uint value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[4];

View File

@ -1,4 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics.Contracts;
namespace X10D.IO;
@ -13,6 +14,7 @@ public static class UInt64Extensions
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
[Pure]
public static byte[] GetBytes(this ulong value)
{
Span<byte> buffer = stackalloc byte[8];
@ -26,6 +28,7 @@ public static class UInt64Extensions
/// <param name="value">The number to convert.</param>
/// <param name="endianness">The endianness with which to write the bytes.</param>
/// <returns>An array of bytes with length 8.</returns>
[Pure]
public static byte[] GetBytes(this ulong value, Endianness endianness)
{
Span<byte> buffer = stackalloc byte[8];

View File

@ -1,4 +1,6 @@
namespace X10D.Linq;
using System.Diagnostics.Contracts;
namespace X10D.Linq;
/// <summary>
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="byte" />.
@ -61,6 +63,7 @@ public static class ByteExtensions
/// <returns>
/// An enumerable collection of 8-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<byte> RangeTo(this byte value, byte end)
{
byte start = System.Math.Min(value, end);
@ -80,6 +83,7 @@ public static class ByteExtensions
/// <returns>
/// An enumerable collection of 16-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<short> RangeTo(this byte value, short end)
{
short start = System.Math.Min(value, end);
@ -99,6 +103,7 @@ public static class ByteExtensions
/// <returns>
/// An enumerable collection of 32-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<int> RangeTo(this byte value, int end)
{
int start = System.Math.Min(value, end);
@ -118,6 +123,7 @@ public static class ByteExtensions
/// <returns>
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<long> RangeTo(this byte value, long end)
{
long start = System.Math.Min(value, end);

View File

@ -1,4 +1,6 @@
namespace X10D.Linq;
using System.Diagnostics.Contracts;
namespace X10D.Linq;
/// <summary>
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="long" />.
@ -61,6 +63,7 @@ public static class Int16Extensions
/// <returns>
/// An enumerable collection of 16-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<short> RangeTo(this short value, short end)
{
short start = System.Math.Min(value, end);
@ -80,6 +83,7 @@ public static class Int16Extensions
/// <returns>
/// An enumerable collection of 32-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<int> RangeTo(this short value, int end)
{
int start = System.Math.Min(value, end);
@ -99,6 +103,7 @@ public static class Int16Extensions
/// <returns>
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<long> RangeTo(this short value, long end)
{
long start = System.Math.Min(value, end);

View File

@ -1,4 +1,6 @@
namespace X10D.Linq;
using System.Diagnostics.Contracts;
namespace X10D.Linq;
/// <summary>
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="int" />.
@ -61,6 +63,7 @@ public static class Int32Extensions
/// <returns>
/// An enumerable collection of 32-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<int> RangeTo(this int value, int end)
{
int start = System.Math.Min(value, end);
@ -80,6 +83,7 @@ public static class Int32Extensions
/// <returns>
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<long> RangeTo(this int value, long end)
{
long start = System.Math.Min(value, end);

View File

@ -1,4 +1,6 @@
namespace X10D.Linq;
using System.Diagnostics.Contracts;
namespace X10D.Linq;
/// <summary>
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="long" />.
@ -61,6 +63,7 @@ public static class Int64Extensions
/// <returns>
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
/// </returns>
[Pure]
public static IEnumerable<long> RangeTo(this long value, long end)
{
long start = System.Math.Min(value, end);

View File

@ -1,4 +1,6 @@
namespace X10D.Linq;
using System.Diagnostics.Contracts;
namespace X10D.Linq;
/// <summary>
/// Extension methods for <see cref="ReadOnlySpan{T}" />.
@ -16,6 +18,7 @@ public static class ReadOnlySpanExtensions
/// span is empty; otherwise, <see langword="false" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="predicate" /> is <see langword="null" />.</exception>
[Pure]
public static bool All<TSource>(this ReadOnlySpan<TSource> source, Predicate<TSource> predicate)
{
if (predicate is null)
@ -50,6 +53,7 @@ public static class ReadOnlySpanExtensions
/// specified predicate; otherwise, <see langword="false" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="predicate" /> is <see langword="null" />.</exception>
[Pure]
public static bool Any<TSource>(this ReadOnlySpan<TSource> source, Predicate<TSource> predicate)
{
if (predicate is null)

View File

@ -1,4 +1,6 @@
namespace X10D.Linq;
using System.Diagnostics.Contracts;
namespace X10D.Linq;
/// <summary>
/// Extension methods for <see cref="Span{T}" />.
@ -16,6 +18,7 @@ public static class SpanExtensions
/// span is empty; otherwise, <see langword="false" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="predicate" /> is <see langword="null" />.</exception>
[Pure]
public static bool All<TSource>(this Span<TSource> source, Predicate<TSource> predicate)
{
if (predicate is null)
@ -50,6 +53,7 @@ public static class SpanExtensions
/// specified predicate; otherwise, <see langword="false" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="predicate" /> is <see langword="null" />.</exception>
[Pure]
public static bool Any<TSource>(this Span<TSource> source, Predicate<TSource> predicate)
{
if (predicate is null)

View File

@ -31,6 +31,8 @@ public static class ByteExtensions
/// </summary>
/// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static long Factorial(this byte value)
{
if (value == 0)
@ -55,6 +57,8 @@ public static class ByteExtensions
/// <see langword="true" /> if <paramref name="value" /> is evenly divisible by 2, or <see langword="false" />
/// otherwise.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsEven(this byte value)
{
return value % 2 == 0;
@ -68,6 +72,8 @@ public static class ByteExtensions
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
/// otherwise.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsOdd(this byte value)
{
return !value.IsEven();
@ -80,6 +86,7 @@ public static class ByteExtensions
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns>
[Pure]
public static bool IsPrime(this byte value)
{
return ((long)value).IsPrime();

View File

@ -1,4 +1,6 @@
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace X10D.Math;
@ -44,6 +46,8 @@ public static class ComparableExtensions
/// // True
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool Between<T1, T2, T3>(this T1 value, T2 lower, T3 upper,
InclusiveOptions inclusiveOptions = InclusiveOptions.None)
where T1 : IComparable<T2>, IComparable<T3>
@ -98,6 +102,8 @@ public static class ComparableExtensions
/// // clamped will be 20
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T Clamp<T>(this T value, T lower, T upper)
where T : IComparable<T>
{
@ -132,6 +138,8 @@ public static class ComparableExtensions
/// // result will be False
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool GreaterThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
{
@ -164,6 +172,8 @@ public static class ComparableExtensions
/// // result will be False
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool GreaterThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
{
@ -196,6 +206,8 @@ public static class ComparableExtensions
/// // result will be True
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool LessThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
{
@ -228,6 +240,8 @@ public static class ComparableExtensions
/// // result will be True
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool LessThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
{
@ -259,6 +273,8 @@ public static class ComparableExtensions
/// // max will be 10
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T Max<T>(this T value, T other)
where T : IComparable<T>
{
@ -290,6 +306,8 @@ public static class ComparableExtensions
/// // min will be 5
/// </code>
/// </example>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T Min<T>(this T value, T other)
where T : IComparable<T>
{

View File

@ -1,4 +1,7 @@
namespace X10D.Math;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Math;
/// <summary>
/// Provides static helpers methods for mathematical functions not found in the .NET <see cref="System.Math" /> class.
@ -14,6 +17,8 @@ public static class MathUtility
/// <returns>
/// The interpolation result as determined by <c>(1 - alpha) * value + alpha * target</c>.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static float Lerp(float value, float target, float alpha)
{
// rookie mistake: a + t * (b - a)
@ -30,6 +35,8 @@ public static class MathUtility
/// <returns>
/// The interpolation result as determined by <c>(1 - alpha) * value + alpha * target</c>.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static double Lerp(double value, double target, double alpha)
{
// rookie mistake: a + t * (b - a)

View File

@ -1,4 +1,4 @@
using System.Diagnostics.Contracts;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Math;
@ -31,6 +31,8 @@ public static class UInt16Extensions
/// </summary>
/// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static ulong Factorial(this ushort value)
{
if (value == 0)

View File

@ -1,4 +1,4 @@
using System.Diagnostics.Contracts;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Math;
@ -31,6 +31,8 @@ public static class UInt32Extensions
/// </summary>
/// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static ulong Factorial(this uint value)
{
if (value == 0)

View File

@ -1,4 +1,4 @@
using System.Diagnostics.Contracts;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Math;
@ -31,6 +31,8 @@ public static class UInt64Extensions
/// </summary>
/// <param name="value">The value whose factorial to compute.</param>
/// <returns>The factorial of <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static ulong Factorial(this ulong value)
{
if (value == 0)

View File

@ -1,4 +1,5 @@
using System.Net;
using System.Diagnostics.Contracts;
using System.Net;
using System.Runtime.CompilerServices;
namespace X10D.Net;
@ -20,7 +21,8 @@ public static class EndPointExtensions
/// <para><see cref="string.Empty" /> otherwise.</para>
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="endPoint" /> is <see langword="null" />.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string GetHost(this EndPoint endPoint)
{
if (endPoint is null)
@ -48,7 +50,8 @@ public static class EndPointExtensions
/// <para><c>0</c> otherwise.</para>
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="endPoint" /> is <see langword="null" />.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int GetPort(this EndPoint endPoint)
{
if (endPoint is null)

View File

@ -1,5 +1,7 @@
using System.Net;
using System.Diagnostics.Contracts;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
namespace X10D.Net;
@ -15,6 +17,8 @@ public static class IPAddressExtensions
/// <returns>
/// <see langword="true" /> if the specified IP address is a valid IPv4 address; otherwise, <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsIPv4(this IPAddress address)
{
return address.AddressFamily == AddressFamily.InterNetwork;
@ -27,6 +31,8 @@ public static class IPAddressExtensions
/// <returns>
/// <see langword="true" /> if the specified IP address is a valid IPv6 address; otherwise, <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsIPv6(this IPAddress address)
{
return address.AddressFamily == AddressFamily.InterNetworkV6;

View File

@ -1,4 +1,6 @@
using System.Net;
using System.Diagnostics.Contracts;
using System.Net;
using System.Runtime.CompilerServices;
namespace X10D.Net;
@ -12,6 +14,8 @@ public static class Int16Extensions
/// </summary>
/// <param name="value">The value to convert, expressed in host byte order.</param>
/// <returns>An integer value, expressed in network byte order.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static short HostToNetworkOrder(this short value)
{
return IPAddress.HostToNetworkOrder(value);
@ -22,6 +26,8 @@ public static class Int16Extensions
/// </summary>
/// <param name="value">The value to convert, expressed in network byte order.</param>
/// <returns>An integer value, expressed in host byte order.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static short NetworkToHostOrder(this short value)
{
return IPAddress.NetworkToHostOrder(value);

View File

@ -1,4 +1,6 @@
using System.Net;
using System.Diagnostics.Contracts;
using System.Net;
using System.Runtime.CompilerServices;
namespace X10D.Net;
@ -12,6 +14,8 @@ public static class Int32Extensions
/// </summary>
/// <param name="value">The value to convert, expressed in host byte order.</param>
/// <returns>An integer value, expressed in network byte order.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int HostToNetworkOrder(this int value)
{
return IPAddress.HostToNetworkOrder(value);
@ -22,6 +26,8 @@ public static class Int32Extensions
/// </summary>
/// <param name="value">The value to convert, expressed in network byte order.</param>
/// <returns>An integer value, expressed in host byte order.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int NetworkToHostOrder(this int value)
{
return IPAddress.NetworkToHostOrder(value);

View File

@ -1,4 +1,6 @@
using System.Net;
using System.Diagnostics.Contracts;
using System.Net;
using System.Runtime.CompilerServices;
namespace X10D.Net;
@ -12,6 +14,8 @@ public static class Int64Extensions
/// </summary>
/// <param name="value">The value to convert, expressed in host byte order.</param>
/// <returns>An integer value, expressed in network byte order.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static long HostToNetworkOrder(this long value)
{
return IPAddress.HostToNetworkOrder(value);
@ -22,6 +26,8 @@ public static class Int64Extensions
/// </summary>
/// <param name="value">The value to convert, expressed in network byte order.</param>
/// <returns>An integer value, expressed in host byte order.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static long NetworkToHostOrder(this long value)
{
return IPAddress.NetworkToHostOrder(value);

View File

@ -1,5 +1,7 @@
using System.Globalization;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace X10D.Reflection;
@ -18,6 +20,8 @@ public static class MemberInfoExtensions
/// <see langword="false" /> otherwise.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool HasCustomAttribute<T>(this MemberInfo member)
where T : Attribute
{
@ -39,6 +43,8 @@ public static class MemberInfoExtensions
/// <see langword="false" /> otherwise.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool HasCustomAttribute(this MemberInfo member, Type attribute)
{
if (member is null)

View File

@ -1,4 +1,6 @@
using System.Globalization;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace X10D.Reflection;
@ -13,6 +15,8 @@ public static class TypeExtensions
/// <param name="value">The type whose interface list to check.</param>
/// <typeparam name="T">The interface type.</typeparam>
/// <returns><see langword="true" /> if the current exists on the type; otherwise, <see langword="false" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool Implements<T>(this Type value)
{
return value.Implements(typeof(T));
@ -24,6 +28,8 @@ public static class TypeExtensions
/// <param name="value">The type whose interface list to check.</param>
/// <param name="interfaceType">The interface type.</param>
/// <returns><see langword="true" /> if the current exists on the type; otherwise, <see langword="false" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool Implements(this Type value, Type interfaceType)
{
if (value is null)
@ -56,6 +62,8 @@ public static class TypeExtensions
/// <see langword="true" /> if the current type inherits <typeparamref name="T" />, or <see langword="false" />
/// otherwise.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool Inherits<T>(this Type value)
where T : class
{
@ -71,6 +79,8 @@ public static class TypeExtensions
/// <see langword="true" /> if the current type inherits <paramref name="type" />, or <see langword="false" />
/// otherwise.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool Inherits(this Type value, Type type)
{
if (value is null)

View File

@ -1,3 +1,5 @@
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Text;
using X10D.Core;
@ -14,6 +16,8 @@ public static class StringExtensions
/// <param name="value">The base-64 string to convert.</param>
/// <returns>The plain text string representation of <paramref name="value" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Base64Decode(this string value)
{
if (value is null)
@ -30,6 +34,8 @@ public static class StringExtensions
/// <param name="value">The plain text string to convert.</param>
/// <returns>The string representation, in base 64, of <paramref name="value" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Base64Encode(this string value)
{
if (value is null)
@ -57,6 +63,8 @@ public static class StringExtensions
/// -or
/// <paramref name="destinationEncoding" /> is <see langword="null" />.
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string ChangeEncoding(this string value, Encoding sourceEncoding, Encoding destinationEncoding)
{
if (value is null)
@ -87,6 +95,8 @@ public static class StringExtensions
/// Credit for this method goes to Scott Dorman:
/// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T EnumParse<T>(this string value)
where T : struct, Enum
{
@ -104,6 +114,8 @@ public static class StringExtensions
/// Credit for this method goes to Scott Dorman:
/// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T EnumParse<T>(this string value, bool ignoreCase)
where T : struct, Enum
{
@ -128,6 +140,8 @@ public static class StringExtensions
/// </summary>
/// <param name="value">The string to convert.</param>
/// <returns>Returns a <see cref="byte" />[].</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static byte[] GetBytes(this string value)
{
return value.GetBytes(Encoding.UTF8);
@ -143,6 +157,8 @@ public static class StringExtensions
/// <paramref name="value" /> or <paramref name="encoding" /> or both are
/// <see langword="null" />.
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static byte[] GetBytes(this string value, Encoding encoding)
{
if (value is null)
@ -170,6 +186,8 @@ public static class StringExtensions
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is less than 0.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Randomize(this string source, int length, Random? random = null)
{
if (source is null)
@ -211,6 +229,8 @@ public static class StringExtensions
/// greater than <paramref name="chunkSize" /> in length.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static IEnumerable<string> Split(this string value, int chunkSize)
{
if (value is null)
@ -230,6 +250,8 @@ public static class StringExtensions
/// <param name="input">The input string.</param>
/// <returns>Returns an instance of <see cref="TimeSpan" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="input" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan ToTimeSpan(this string input)
{
if (input is null)

View File

@ -1,4 +1,7 @@
namespace X10D.Text;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Text;
/// <summary>
/// Text-related extension methods for <see cref="char" />.
@ -13,6 +16,8 @@ public static class CharExtensions
/// <returns>
/// A <see cref="string" /> composed of <paramref name="value" /> repeated <paramref name="count" /> times.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Repeat(this char value, int count)
{
return count switch

View File

@ -1,4 +1,6 @@
using System.Text.Json;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Text.Json;
namespace X10D.Text;
@ -14,6 +16,8 @@ public static class Extensions
/// <param name="options">The JSON serialization options.</param>
/// <typeparam name="T">The type of the value to convert.</typeparam>
/// <returns>A JSON string representing the object.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string ToJson<T>(this T value, JsonSerializerOptions? options = null)
{
return JsonSerializer.Serialize(value, options);

View File

@ -1,4 +1,6 @@
using System.Text;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Text;
namespace X10D.Text;
@ -15,6 +17,8 @@ public static class RuneExtensions
/// <returns>
/// A <see cref="string" /> composed of <paramref name="value" /> repeated <paramref name="count" /> times.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Repeat(this Rune value, int count)
{
switch (count)

View File

@ -1,4 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using X10D.Collections;
@ -18,6 +20,8 @@ public static class StringExtensions
/// <see langword="null" /> if <paramref name="value" /> is <see langword="null" /> or empty; otherwise,
/// <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[return: NotNullIfNotNull("value")]
public static string? AsNullIfEmpty(this string? value)
{
@ -33,6 +37,8 @@ public static class StringExtensions
/// <see langword="null" /> if <paramref name="value" /> is <see langword="null" />, empty, or consists of only
/// whitespace; otherwise, <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[return: NotNullIfNotNull("value")]
public static string? AsNullIfWhiteSpace(this string? value)
{
@ -48,6 +54,8 @@ public static class StringExtensions
/// <returns>
/// An object constructed from the JSON string, or <see langword="null" /> if deserialization could not be performed.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T? FromJson<T>(this string value, JsonSerializerOptions? options = null)
{
return JsonSerializer.Deserialize<T>(value, options);
@ -60,6 +68,8 @@ public static class StringExtensions
/// <returns>
/// <see langword="true" /> if all alpha characters in this string are lowercase; otherwise, <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsLower(this string value)
{
if (value is null)
@ -95,6 +105,8 @@ public static class StringExtensions
/// <see langword="false" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsPalindrome(this string value)
{
if (value is null)
@ -141,6 +153,8 @@ public static class StringExtensions
/// <returns>
/// <see langword="true" /> if all alpha characters in this string are uppercase; otherwise, <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsUpper(this string value)
{
if (value is null)
@ -174,6 +188,8 @@ public static class StringExtensions
/// <returns>A string containing <paramref name="value" /> repeated <paramref name="count" /> times.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Repeat(this string value, int count)
{
if (value is null)
@ -206,6 +222,8 @@ public static class StringExtensions
/// </summary>
/// <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>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Reverse(this string value)
{
if (value is null)
@ -238,6 +256,8 @@ public static class StringExtensions
/// </param>
/// <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>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static string Shuffled(this string value, Random? random = null)
{
if (value is null)
@ -261,6 +281,8 @@ public static class StringExtensions
/// <paramref name="alternative" /> if <paramref name="value" /> is <see langword="null" /> or empty; otherwise,
/// <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[return: NotNullIfNotNull("alternative")]
public static string? WithEmptyAlternative(this string? value, string? alternative)
{
@ -277,6 +299,8 @@ public static class StringExtensions
/// <paramref name="alternative" /> if <paramref name="value" /> is <see langword="null" />, empty, or consists of only
/// whitespace; otherwise, <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[return: NotNullIfNotNull("alternative")]
public static string? WithWhiteSpaceAlternative(this string? value, string? alternative)
{

View File

@ -42,6 +42,8 @@ public static class ByteExtensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeMilliseconds(this byte value)
{
return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -61,6 +63,8 @@ public static class ByteExtensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeSeconds(this byte value)
{
return DateTimeOffset.FromUnixTimeSeconds(value);
@ -71,6 +75,8 @@ public static class ByteExtensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this byte value)
{
return TimeSpan.FromTicks(value);
@ -83,6 +89,8 @@ public static class ByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this byte value)
{
return TimeSpan.FromMilliseconds(value);
@ -95,6 +103,8 @@ public static class ByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this byte value)
{
return TimeSpan.FromSeconds(value);
@ -107,6 +117,8 @@ public static class ByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this byte value)
{
return TimeSpan.FromMinutes(value);
@ -119,6 +131,8 @@ public static class ByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this byte value)
{
return TimeSpan.FromHours(value);
@ -129,6 +143,8 @@ public static class ByteExtensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this byte value)
{
return TimeSpan.FromDays(value);
@ -141,6 +157,8 @@ public static class ByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this byte value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -1,4 +1,7 @@
namespace X10D.Time;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Time;
/// <summary>
/// Extension methods for <see cref="DateTime" />.
@ -6,12 +9,16 @@
public static class DateTimeExtensions
{
/// <inheritdoc cref="DateTimeOffsetExtensions.Age(DateTimeOffset)" />
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int Age(this DateTime value)
{
return value.Age(DateTime.Today);
}
/// <inheritdoc cref="DateTimeOffsetExtensions.Age(DateTimeOffset, DateTimeOffset)" />
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int Age(this DateTime value, DateTime asOf)
{
return ((DateTimeOffset)value).Age(asOf);
@ -19,6 +26,8 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.First(DateTimeOffset, DayOfWeek)" />
/// <returns>A <see cref="DateTime" /> representing the first occurence of <paramref name="dayOfWeek" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTime First(this DateTime value, DayOfWeek dayOfWeek)
{
return ((DateTimeOffset)value).First(dayOfWeek).DateTime;
@ -26,6 +35,8 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.FirstDayOfMonth(DateTimeOffset)" />
/// <returns>A <see cref="DateTime" /> representing the first day of the current month.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTime FirstDayOfMonth(this DateTime value)
{
return ((DateTimeOffset)value).FirstDayOfMonth().DateTime;
@ -39,6 +50,8 @@ public static class DateTimeExtensions
/// <see langword="true" /> if the year represented by <paramref name="value" /> is a leap year; otherwise,
/// <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsLeapYear(this DateTime value)
{
return DateTime.IsLeapYear(value.Year);
@ -46,6 +59,8 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.Last(DateTimeOffset, DayOfWeek)" />
/// <returns>A <see cref="DateTimeOffset" /> representing the final occurence of <paramref name="dayOfWeek" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTime Last(this DateTime value, DayOfWeek dayOfWeek)
{
return ((DateTimeOffset)value).Last(dayOfWeek).DateTime;
@ -53,6 +68,8 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.LastDayOfMonth(DateTimeOffset)" />
/// <returns>A <see cref="DateTimeOffset" /> representing the last day of the current month.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTime LastDayOfMonth(this DateTime value)
{
return ((DateTimeOffset)value).LastDayOfMonth().DateTime;
@ -60,6 +77,8 @@ public static class DateTimeExtensions
/// <inheritdoc cref="DateTimeOffsetExtensions.Next(DateTimeOffset, DayOfWeek)" />
/// <returns>A <see cref="DateTimeOffset" /> representing the next occurence of <paramref name="dayOfWeek" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTime Next(this DateTime value, DayOfWeek dayOfWeek)
{
return ((DateTimeOffset)value).Next(dayOfWeek).DateTime;
@ -70,6 +89,8 @@ public static class DateTimeExtensions
/// </summary>
/// <param name="value">The current date.</param>
/// <returns>The number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static long ToUnixTimeMilliseconds(this DateTime value)
{
return ((DateTimeOffset)value).ToUnixTimeMilliseconds();
@ -80,6 +101,8 @@ public static class DateTimeExtensions
/// </summary>
/// <param name="value">The current date.</param>
/// <returns>The number of seconds that have elapsed since 1970-01-01T00:00:00.000Z.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static long ToUnixTimeSeconds(this DateTime value)
{
return ((DateTimeOffset)value).ToUnixTimeSeconds();

View File

@ -1,4 +1,7 @@
namespace X10D.Time;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Time;
/// <summary>
/// Extension methods for <see cref="DateTimeOffset" />.
@ -10,6 +13,8 @@ public static class DateTimeOffsetExtensions
/// </summary>
/// <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>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int Age(this DateTimeOffset value)
{
return value.Age(DateTime.Today);
@ -24,6 +29,8 @@ public static class DateTimeOffsetExtensions
/// The rounded-down integer number of years since <paramref name="value" /> as of the date specified by
/// <paramref name="asOf" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int Age(this DateTimeOffset value, DateTimeOffset asOf)
{
return (int)(((asOf.Date - TimeSpan.FromDays(1) - value.Date).TotalDays + 1) / 365.2425);
@ -35,6 +42,8 @@ public static class DateTimeOffsetExtensions
/// <param name="value">The current date.</param>
/// <param name="dayOfWeek">The day of the week.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the first occurence of <paramref name="dayOfWeek" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset First(this DateTimeOffset value, DayOfWeek dayOfWeek)
{
var first = value.FirstDayOfMonth();
@ -52,6 +61,8 @@ public static class DateTimeOffsetExtensions
/// </summary>
/// <param name="value">The current date.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the first day of the current month.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FirstDayOfMonth(this DateTimeOffset value)
{
return value.AddDays(1 - value.Day);
@ -65,6 +76,8 @@ public static class DateTimeOffsetExtensions
/// <see langword="true" /> if the year represented by <paramref name="value" /> is a leap year; otherwise,
/// <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsLeapYear(this DateTimeOffset value)
{
return DateTime.IsLeapYear(value.Year);
@ -76,6 +89,8 @@ public static class DateTimeOffsetExtensions
/// <param name="value">The current date.</param>
/// <param name="dayOfWeek">The day of the week.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the final occurence of <paramref name="dayOfWeek" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset Last(this DateTimeOffset value, DayOfWeek dayOfWeek)
{
var last = value.LastDayOfMonth();
@ -92,6 +107,8 @@ public static class DateTimeOffsetExtensions
/// </summary>
/// <param name="value">The current date.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the last day of the current month.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset LastDayOfMonth(this DateTimeOffset value)
{
int daysInMonth = DateTime.DaysInMonth(value.Year, value.Month);
@ -104,6 +121,8 @@ public static class DateTimeOffsetExtensions
/// <param name="value">The current date.</param>
/// <param name="dayOfWeek">The day of the week.</param>
/// <returns>A <see cref="DateTimeOffset" /> representing the next occurence of <paramref name="dayOfWeek" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset Next(this DateTimeOffset value, DayOfWeek dayOfWeek)
{
int offsetDays = dayOfWeek - value.DayOfWeek;

View File

@ -1,4 +1,7 @@
namespace X10D.Time;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="decimal" />.
@ -12,6 +15,8 @@ public static class DecimalExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this decimal value)
{
return TimeSpan.FromMilliseconds((double)value);
@ -24,6 +29,8 @@ public static class DecimalExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this decimal value)
{
return TimeSpan.FromSeconds((double)value);
@ -36,6 +43,8 @@ public static class DecimalExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this decimal value)
{
return TimeSpan.FromMinutes((double)value);
@ -48,6 +57,8 @@ public static class DecimalExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this decimal value)
{
return TimeSpan.FromHours((double)value);
@ -58,6 +69,8 @@ public static class DecimalExtensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this decimal value)
{
return TimeSpan.FromDays((double)value);
@ -70,6 +83,8 @@ public static class DecimalExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this decimal value)
{
return TimeSpan.FromDays((double)value * 7);

View File

@ -1,4 +1,7 @@
namespace X10D.Time;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="double" />.
@ -12,6 +15,8 @@ public static class DoubleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this double value)
{
return TimeSpan.FromMilliseconds(value);
@ -24,6 +29,8 @@ public static class DoubleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this double value)
{
return TimeSpan.FromSeconds(value);
@ -36,6 +43,8 @@ public static class DoubleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this double value)
{
return TimeSpan.FromMinutes(value);
@ -48,6 +57,8 @@ public static class DoubleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this double value)
{
return TimeSpan.FromHours(value);
@ -58,6 +69,8 @@ public static class DoubleExtensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this double value)
{
return TimeSpan.FromDays(value);
@ -70,6 +83,8 @@ public static class DoubleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this double value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -1,4 +1,7 @@
namespace X10D.Time;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="Half" />.
@ -12,6 +15,8 @@ public static class HalfExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this Half value)
{
return TimeSpan.FromMilliseconds((float)value);
@ -24,6 +29,8 @@ public static class HalfExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this Half value)
{
return TimeSpan.FromSeconds((float)value);
@ -36,6 +43,8 @@ public static class HalfExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this Half value)
{
return TimeSpan.FromMinutes((float)value);
@ -48,6 +57,8 @@ public static class HalfExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this Half value)
{
return TimeSpan.FromHours((float)value);
@ -58,6 +69,8 @@ public static class HalfExtensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this Half value)
{
return TimeSpan.FromDays((float)value);
@ -70,6 +83,8 @@ public static class HalfExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this Half value)
{
return TimeSpan.FromDays((float)value * 7);

View File

@ -48,6 +48,8 @@ public static class Int16Extensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeMilliseconds(this short value)
{
return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -67,6 +69,8 @@ public static class Int16Extensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeSeconds(this short value)
{
return DateTimeOffset.FromUnixTimeSeconds(value);
@ -77,6 +81,8 @@ public static class Int16Extensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this short value)
{
return TimeSpan.FromTicks(value);
@ -89,6 +95,8 @@ public static class Int16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this short value)
{
return TimeSpan.FromMilliseconds(value);
@ -101,6 +109,8 @@ public static class Int16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this short value)
{
return TimeSpan.FromSeconds(value);
@ -113,6 +123,8 @@ public static class Int16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this short value)
{
return TimeSpan.FromMinutes(value);
@ -125,6 +137,8 @@ public static class Int16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this short value)
{
return TimeSpan.FromHours(value);
@ -135,6 +149,8 @@ public static class Int16Extensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this short value)
{
return TimeSpan.FromDays(value);
@ -147,6 +163,8 @@ public static class Int16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this short value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -48,6 +48,8 @@ public static class Int32Extensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeMilliseconds(this int value)
{
return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -67,6 +69,8 @@ public static class Int32Extensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeSeconds(this int value)
{
return DateTimeOffset.FromUnixTimeSeconds(value);
@ -77,6 +81,8 @@ public static class Int32Extensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this int value)
{
return TimeSpan.FromTicks(value);
@ -89,6 +95,8 @@ public static class Int32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this int value)
{
return TimeSpan.FromMilliseconds(value);
@ -101,6 +109,8 @@ public static class Int32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this int value)
{
return TimeSpan.FromSeconds(value);
@ -113,6 +123,8 @@ public static class Int32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this int value)
{
return TimeSpan.FromMinutes(value);
@ -125,6 +137,8 @@ public static class Int32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this int value)
{
return TimeSpan.FromHours(value);
@ -135,6 +149,8 @@ public static class Int32Extensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this int value)
{
return TimeSpan.FromDays(value);
@ -147,6 +163,8 @@ public static class Int32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this int value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -48,6 +48,8 @@ public static class Int64Extensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeMilliseconds(this long value)
{
return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -67,6 +69,8 @@ public static class Int64Extensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeSeconds(this long value)
{
return DateTimeOffset.FromUnixTimeSeconds(value);
@ -77,6 +81,8 @@ public static class Int64Extensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this long value)
{
return TimeSpan.FromTicks(value);
@ -89,6 +95,8 @@ public static class Int64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this long value)
{
return TimeSpan.FromMilliseconds(value);
@ -101,6 +109,8 @@ public static class Int64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this long value)
{
return TimeSpan.FromSeconds(value);
@ -113,6 +123,8 @@ public static class Int64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this long value)
{
return TimeSpan.FromMinutes(value);
@ -125,6 +137,8 @@ public static class Int64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this long value)
{
return TimeSpan.FromHours(value);
@ -135,6 +149,8 @@ public static class Int64Extensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this long value)
{
return TimeSpan.FromDays(value);
@ -147,6 +163,8 @@ public static class Int64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this long value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -49,6 +49,8 @@ public static class SByteExtensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeMilliseconds(this sbyte value)
{
return DateTimeOffset.FromUnixTimeMilliseconds(value);
@ -68,6 +70,8 @@ public static class SByteExtensions
/// -or-
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTimeOffset FromUnixTimeSeconds(this sbyte value)
{
return DateTimeOffset.FromUnixTimeSeconds(value);
@ -78,6 +82,8 @@ public static class SByteExtensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this sbyte value)
{
return TimeSpan.FromTicks(value);
@ -90,6 +96,8 @@ public static class SByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this sbyte value)
{
return TimeSpan.FromMilliseconds(value);
@ -102,6 +110,8 @@ public static class SByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this sbyte value)
{
return TimeSpan.FromSeconds(value);
@ -114,6 +124,8 @@ public static class SByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this sbyte value)
{
return TimeSpan.FromMinutes(value);
@ -126,6 +138,8 @@ public static class SByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this sbyte value)
{
return TimeSpan.FromHours(value);
@ -136,6 +150,8 @@ public static class SByteExtensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this sbyte value)
{
return TimeSpan.FromDays(value);
@ -148,6 +164,8 @@ public static class SByteExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this sbyte value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -1,4 +1,7 @@
namespace X10D.Time;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Time;
/// <summary>
/// Time-related extension methods for <see cref="float" />.
@ -12,6 +15,8 @@ public static class SingleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this float value)
{
return TimeSpan.FromMilliseconds(value);
@ -24,6 +29,8 @@ public static class SingleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this float value)
{
return TimeSpan.FromSeconds(value);
@ -36,6 +43,8 @@ public static class SingleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this float value)
{
return TimeSpan.FromMinutes(value);
@ -48,6 +57,8 @@ public static class SingleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this float value)
{
return TimeSpan.FromHours(value);
@ -58,6 +69,8 @@ public static class SingleExtensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this float value)
{
return TimeSpan.FromDays(value);
@ -70,6 +83,8 @@ public static class SingleExtensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this float value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -1,4 +1,7 @@
namespace X10D.Time;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace X10D.Time;
/// <summary>
/// Extension methods for <see cref="TimeSpan" />.
@ -12,6 +15,8 @@ public static class TimeSpanExtensions
/// <returns>
/// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the past relative to the current time.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTime Ago(this TimeSpan value)
{
return DateTime.Now.Subtract(value);
@ -24,6 +29,8 @@ public static class TimeSpanExtensions
/// <returns>
/// A <see cref="DateTime" /> that is a duration of <paramref name="value" /> in the future relative to the current time.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static DateTime FromNow(this TimeSpan value)
{
return DateTime.Now.Add(value);

View File

@ -34,6 +34,8 @@ public static class UInt16Extensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this ushort value)
{
return TimeSpan.FromTicks(value);
@ -46,6 +48,8 @@ public static class UInt16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this ushort value)
{
return TimeSpan.FromMilliseconds(value);
@ -58,6 +62,8 @@ public static class UInt16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this ushort value)
{
return TimeSpan.FromSeconds(value);
@ -70,6 +76,8 @@ public static class UInt16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this ushort value)
{
return TimeSpan.FromMinutes(value);
@ -82,6 +90,8 @@ public static class UInt16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this ushort value)
{
return TimeSpan.FromHours(value);
@ -92,6 +102,8 @@ public static class UInt16Extensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this ushort value)
{
return TimeSpan.FromDays(value);
@ -104,6 +116,8 @@ public static class UInt16Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this ushort value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -34,6 +34,8 @@ public static class UInt32Extensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this uint value)
{
return TimeSpan.FromTicks(value);
@ -46,6 +48,8 @@ public static class UInt32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this uint value)
{
return TimeSpan.FromMilliseconds(value);
@ -58,6 +62,8 @@ public static class UInt32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this uint value)
{
return TimeSpan.FromSeconds(value);
@ -70,6 +76,8 @@ public static class UInt32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this uint value)
{
return TimeSpan.FromMinutes(value);
@ -82,6 +90,8 @@ public static class UInt32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this uint value)
{
return TimeSpan.FromHours(value);
@ -92,6 +102,8 @@ public static class UInt32Extensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this uint value)
{
return TimeSpan.FromDays(value);
@ -104,6 +116,8 @@ public static class UInt32Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this uint value)
{
return TimeSpan.FromDays(value * 7);

View File

@ -34,6 +34,8 @@ public static class UInt64Extensions
/// </summary>
/// <param name="value">The duration, in ticks.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.Ticks" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Ticks(this ulong value)
{
return TimeSpan.FromTicks((long)value);
@ -46,6 +48,8 @@ public static class UInt64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMilliseconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Milliseconds(this ulong value)
{
return TimeSpan.FromMilliseconds((long)value);
@ -58,6 +62,8 @@ public static class UInt64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalSeconds" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Seconds(this ulong value)
{
return TimeSpan.FromSeconds((long)value);
@ -70,6 +76,8 @@ public static class UInt64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalMinutes" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Minutes(this ulong value)
{
return TimeSpan.FromMinutes((long)value);
@ -82,6 +90,8 @@ public static class UInt64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalHours" /> will equal <paramref name="value" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Hours(this ulong value)
{
return TimeSpan.FromHours((long)value);
@ -92,6 +102,8 @@ public static class UInt64Extensions
/// </summary>
/// <param name="value">The duration, in days.</param>
/// <returns>A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" />.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Days(this ulong value)
{
return TimeSpan.FromDays((long)value);
@ -104,6 +116,8 @@ public static class UInt64Extensions
/// <returns>
/// A <see cref="TimeSpan" /> whose <see cref="TimeSpan.TotalDays" /> will equal <paramref name="value" /> × 7.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static TimeSpan Weeks(this ulong value)
{
return TimeSpan.FromDays((long)value * 7);