diff --git a/OnixLabs.Core.UnitTests/Linq/IEnumerableExtensionTests.cs b/OnixLabs.Core.UnitTests/Linq/IEnumerableExtensionTests.cs index f8ba155..41e27ea 100644 --- a/OnixLabs.Core.UnitTests/Linq/IEnumerableExtensionTests.cs +++ b/OnixLabs.Core.UnitTests/Linq/IEnumerableExtensionTests.cs @@ -15,7 +15,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Numerics; using OnixLabs.Core.Linq; using OnixLabs.Core.UnitTests.Data; @@ -107,6 +106,62 @@ public void CountNotShouldProduceExpectedResult() Assert.Equal(expected, actual); } + [Fact(DisplayName = "IEnumerable.FirstOrNone should return none when the enumerable is empty.")] + public void FirstOrNoneShouldReturnNoneWhenEnumerableIsEmpty() + { + // Given + IEnumerable elements = []; + Optional expected = Optional.None; + + // When + Optional actual = elements.FirstOrNone(); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.FirstOrNone should return the first element when the collection is not empty.")] + public void FirstOrNoneShouldReturnFirstElementWhenCollectionIsNotEmpty() + { + // Given + IEnumerable elements = [1, 2, 3]; + Optional expected = 1; + + // When + Optional actual = elements.FirstOrNone(); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.FirstOrNone should return the first element matching the predicate when the collection is not empty.")] + public void FirstOrNoneShouldReturnFirstElementMatchingPredicateWhenCollectionIsNotEmpty() + { + // Given + IEnumerable elements = [1, 2, 3]; + Optional expected = 2; + + // When + Optional actual = elements.FirstOrNone(number => number > 1); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.FirstOrNone should return none when no element matches the predicate and the collection is not empty.")] + public void FirstOrNoneShouldReturnNoneWhenNoElementMatchesPredicateAndCollectionIsNotEmpty() + { + // Given + IEnumerable elements = [1, 2, 3]; + Optional expected = Optional.None; + + // When + Optional actual = elements.FirstOrNone(number => number > 3); + + // Then + Assert.Equal(expected, actual); + } + [Fact(DisplayName = "IEnumerable.ForEach should iterate over every element in the enumerable")] public void ForEachShouldProduceExpectedResult() { @@ -321,6 +376,62 @@ public void JoinToStringShouldProduceExpectedResultWithCustomSeparator() Assert.Equal(expected, actual); } + [Fact(DisplayName = "IEnumerable.LastOrNone should return none when the enumerable is empty.")] + public void LastOrNoneShouldReturnNoneWhenEnumerableIsEmpty() + { + // Given + IEnumerable elements = []; + Optional expected = Optional.None; + + // When + Optional actual = elements.LastOrNone(); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.LastOrNone should return the last element when the collection is not empty.")] + public void LastOrNoneShouldReturnLastElementWhenCollectionIsNotEmpty() + { + // Given + IEnumerable elements = [1, 2, 3]; + Optional expected = 3; + + // When + Optional actual = elements.LastOrNone(); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.LastOrNone should return the last element matching the predicate when the collection is not empty.")] + public void LastOrNoneShouldReturnFirstElementMatchingPredicateWhenCollectionIsNotEmpty() + { + // Given + IEnumerable elements = [1, 2, 3]; + Optional expected = 3; + + // When + Optional actual = elements.LastOrNone(number => number > 1); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.LastOrNone should return none when no element matches the predicate and the collection is not empty.")] + public void LastOrNoneShouldReturnNoneWhenNoElementMatchesPredicateAndCollectionIsNotEmpty() + { + // Given + IEnumerable elements = [1, 2, 3]; + Optional expected = Optional.None; + + // When + Optional actual = elements.LastOrNone(number => number > 3); + + // Then + Assert.Equal(expected, actual); + } + [Fact(DisplayName = "IEnumerable.None should return true when none of the elements satisfy the specified predicate condition")] public void NoneShouldProduceExpectedResultTrue() { @@ -369,6 +480,96 @@ public void NoneShouldProduceExpectedResultFalseAll() Assert.False(result); } + [Fact(DisplayName = "IEnumerable.SingleOrNone should return success none when the enumerable contains no elements.")] + public void SingleOrNoneShouldReturnSuccessNoneWhenEnumerableContainsNoElements() + { + // Given + IEnumerable elements = []; + Result> expected = Optional.None.ToResult(); + + // When + Result> actual = elements.SingleOrNone(); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.SingleOrNone should return success some when the enumerable contains a single element.")] + public void SingleOrNoneShouldReturnSuccessSomeWhenEnumerableContainsSingleElement() + { + // Given + IEnumerable elements = [1]; + Result> expected = Optional.Some(1).ToResult(); + + // When + Result> actual = elements.SingleOrNone(); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.SingleOrNone should return failure when the enumerable contains more than one element.")] + public void SingleOrNoneShouldReturnFailureSomeWhenEnumerableContainsMoreThanOneElement() + { + // Given + IEnumerable elements = [1, 2, 3]; + Failure> expected = Result>.Failure(new InvalidOperationException("Sequence contains more than one matching element")); + + // When + Result> actual = elements.SingleOrNone(); + Exception actualException = Assert.Throws(actual.Throw); + + // Then + Assert.True(actual is Failure>); + Assert.Equal(expected.Exception.GetType(), actualException.GetType()); + Assert.Equal(expected.Exception.Message, actualException.Message); + } + + [Fact(DisplayName = "IEnumerable.SingleOrNone should return success none when the enumerable contains no elements matching the predicate.")] + public void SingleOrNoneShouldReturnSuccessNoneWhenEnumerableContainsNoElementsMatchingPredicate() + { + // Given + IEnumerable elements = [1, 2, 3]; + Result> expected = Optional.None.ToResult(); + + // When + Result> actual = elements.SingleOrNone(number => number > 3); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.SingleOrNone should return success some when the enumerable contains a single element matching the predicate.")] + public void SingleOrNoneShouldReturnSuccessSomeWhenEnumerableContainsSingleElementMatchingPredicate() + { + // Given + IEnumerable elements = [1, 2, 3]; + Result> expected = Optional.Some(1).ToResult(); + + // When + Result> actual = elements.SingleOrNone(number => number < 2); + + // Then + Assert.Equal(expected, actual); + } + + [Fact(DisplayName = "IEnumerable.SingleOrNone should return failure when the enumerable contains more than one element matching the predicate.")] + public void SingleOrNoneShouldReturnFailureSomeWhenEnumerableContainsMoreThanOneElementMatchingPredidate() + { + // Given + IEnumerable elements = [1, 2, 3]; + Failure> expected = Result>.Failure(new InvalidOperationException("Sequence contains more than one matching element")); + + // When + Result> actual = elements.SingleOrNone(number => number > 1); + Exception actualException = Assert.Throws(actual.Throw); + + // Then + Assert.True(actual is Failure>); + Assert.Equal(expected.Exception.GetType(), actualException.GetType()); + Assert.Equal(expected.Exception.Message, actualException.Message); + } + [Fact(DisplayName = "IEnumerable.Sum should produce the expected result")] public void SumShouldProduceExpectedResult() { diff --git a/OnixLabs.Core/Enumeration.Comparable.cs b/OnixLabs.Core/Enumeration.Comparable.cs index 8275d76..ed87b07 100644 --- a/OnixLabs.Core/Enumeration.Comparable.cs +++ b/OnixLabs.Core/Enumeration.Comparable.cs @@ -23,10 +23,7 @@ public abstract partial class Enumeration /// /// An object to compare with the current instance. /// Returns a value that indicates the relative order of the objects being compared. - public int CompareTo(T? other) - { - return Value.CompareTo(other?.Value); - } + public int CompareTo(T? other) => Value.CompareTo(other?.Value); /// /// Compares the current instance with another object of the same type and returns an integer that indicates @@ -35,8 +32,5 @@ public int CompareTo(T? other) /// /// An object to compare with the current instance. /// Returns a value that indicates the relative order of the objects being compared. - public int CompareTo(object? obj) - { - return this.CompareToObject(obj); - } + public int CompareTo(object? obj) => this.CompareToObject(obj); } diff --git a/OnixLabs.Core/Enumeration.Equatable.cs b/OnixLabs.Core/Enumeration.Equatable.cs index 0cb68f1..0579d5f 100644 --- a/OnixLabs.Core/Enumeration.Equatable.cs +++ b/OnixLabs.Core/Enumeration.Equatable.cs @@ -37,19 +37,13 @@ public bool Equals(T? other) /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return Equals(obj as T); - } + public override bool Equals(object? obj) => Equals(obj as T); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return HashCode.Combine(GetType(), Name, Value); - } + public override int GetHashCode() => HashCode.Combine(GetType(), Name, Value); /// /// Performs an equality comparison between two object instances. @@ -57,10 +51,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(Enumeration left, Enumeration right) - { - return Equals(left, right); - } + public static bool operator ==(Enumeration left, Enumeration right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -68,8 +59,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(Enumeration left, Enumeration right) - { - return !Equals(left, right); - } + public static bool operator !=(Enumeration left, Enumeration right) => !Equals(left, right); } diff --git a/OnixLabs.Core/Enumeration.Get.cs b/OnixLabs.Core/Enumeration.Get.cs index 8acee6d..b9b526a 100644 --- a/OnixLabs.Core/Enumeration.Get.cs +++ b/OnixLabs.Core/Enumeration.Get.cs @@ -38,26 +38,17 @@ public static IReadOnlySet GetAll() /// Gets all of the enumeration entries for the current type. /// /// Returns all of the enumeration entries for the current type. - public static IReadOnlySet<(int Value, string Name)> GetEntries() - { - return GetAll().Select(entry => entry.ToEntry()).ToFrozenSet(); - } + public static IReadOnlySet<(int Value, string Name)> GetEntries() => GetAll().Select(entry => entry.ToEntry()).ToFrozenSet(); /// /// Gets all of the enumeration names for the current type. /// /// Returns all of the enumeration names for the current type. - public static IReadOnlySet GetNames() - { - return GetAll().Select(entry => entry.Name).ToFrozenSet(); - } + public static IReadOnlySet GetNames() => GetAll().Select(entry => entry.Name).ToFrozenSet(); /// /// Gets all of the enumeration values for the current type. /// /// Returns all of the enumeration values for the current type. - public static IReadOnlySet GetValues() - { - return GetAll().Select(entry => entry.Value).ToFrozenSet(); - } + public static IReadOnlySet GetValues() => GetAll().Select(entry => entry.Value).ToFrozenSet(); } diff --git a/OnixLabs.Core/Enumeration.To.cs b/OnixLabs.Core/Enumeration.To.cs index 800f49d..2c28b52 100644 --- a/OnixLabs.Core/Enumeration.To.cs +++ b/OnixLabs.Core/Enumeration.To.cs @@ -22,17 +22,11 @@ public abstract partial class Enumeration /// Returns a that represents the current object. /// /// Returns a tuple that represents the current object. - public (int Value, string Name) ToEntry() - { - return (Value, Name); - } + public (int Value, string Name) ToEntry() => (Value, Name); /// /// Returns a that represents the current object. /// /// Returns a that represents the current object. - public override string ToString() - { - return Name; - } + public override string ToString() => Name; } diff --git a/OnixLabs.Core/Extensions.Array.cs b/OnixLabs.Core/Extensions.Array.cs index 643c00b..af41459 100644 --- a/OnixLabs.Core/Extensions.Array.cs +++ b/OnixLabs.Core/Extensions.Array.cs @@ -28,10 +28,7 @@ public static class ArrayExtensions /// The current to copy. /// The underlying type of the array. /// Returns an exact copy of the current . - public static T[] Copy(this T[] array) - { - return [..array]; - } + public static T[] Copy(this T[] array) => [..array]; /// /// Creates a copy of the current . @@ -41,10 +38,7 @@ public static T[] Copy(this T[] array) /// The number of elements of the array to copy. /// The underlying type of the array. /// Returns an exact copy of the current . - public static T[] Copy(this T[] array, int index, int count) - { - return [..array[index..(index + count)]]; - } + public static T[] Copy(this T[] array, int index, int count) => [..array[index..(index + count)]]; /// /// Concatenates the current with another . @@ -53,8 +47,5 @@ public static T[] Copy(this T[] array, int index, int count) /// The other to concatenate with the source . /// The underlying type of the . /// Returns the current concatenated with the other . - public static T[] ConcatenateWith(this T[] array, T[] other) - { - return [..array, ..other]; - } + public static T[] ConcatenateWith(this T[] array, T[] other) => [..array, ..other]; } diff --git a/OnixLabs.Core/Extensions.Object.cs b/OnixLabs.Core/Extensions.Object.cs index 8005057..87c9ef8 100644 --- a/OnixLabs.Core/Extensions.Object.cs +++ b/OnixLabs.Core/Extensions.Object.cs @@ -35,12 +35,12 @@ public static class ObjectExtensions /// The underlying type of the current . /// Returns a signed integer that indicates the relative order of the objects being compared. /// If the specified object is not , or of the specified type. - public static int CompareToObject(this IComparable comparable, object? obj) + public static int CompareToObject(this IComparable comparable, object? obj) => obj switch { - if (obj is null) return 1; - if (obj is T other) return comparable.CompareTo(other); - throw new ArgumentException($"Object must be of type {typeof(T).Name}", nameof(obj)); - } + null => 1, + T other => comparable.CompareTo(other), + _ => throw new ArgumentException($"Object must be of type {typeof(T).Name}", nameof(obj)) + }; /// /// Gets a record-like representation of the current instance. diff --git a/OnixLabs.Core/Extensions.String.cs b/OnixLabs.Core/Extensions.String.cs index 4a92b91..8fede8b 100644 --- a/OnixLabs.Core/Extensions.String.cs +++ b/OnixLabs.Core/Extensions.String.cs @@ -52,10 +52,7 @@ public static class StringExtensions /// The instance to repeat. /// The number of repetitions of the current instance. /// Returns a new instance representing the repetition of the current instance. - public static string Repeat(this string value, int count) - { - return count > 0 ? string.Join(string.Empty, Enumerable.Repeat(value, count)) : string.Empty; - } + public static string Repeat(this string value, int count) => count > 0 ? string.Join(string.Empty, Enumerable.Repeat(value, count)) : string.Empty; /// /// Obtains a sub-string before the specified index within the current instance. @@ -70,10 +67,8 @@ public static string Repeat(this string value, int count) /// Returns a sub-string before the specified index. If the index is less than zero, then the default value will be returned. /// If the default value is , then the current instance will be returned. /// - private static string SubstringBeforeIndex(this string value, int index, string? defaultValue = null) - { - return index <= NotFound ? defaultValue ?? value : value[..index]; - } + private static string SubstringBeforeIndex(this string value, int index, string? defaultValue = null) => + index <= NotFound ? defaultValue ?? value : value[..index]; /// /// Obtains a sub-string after the specified index within the current instance. @@ -89,10 +84,8 @@ private static string SubstringBeforeIndex(this string value, int index, string? /// Returns a sub-string after the specified index. If the index is less than zero, then the default value will be returned. /// If the default value is , then the current instance will be returned. /// - private static string SubstringAfterIndex(this string value, int index, int offset, string? defaultValue = null) - { - return index <= NotFound ? defaultValue ?? value : value[(index + offset)..value.Length]; - } + private static string SubstringAfterIndex(this string value, int index, int offset, string? defaultValue = null) => + index <= NotFound ? defaultValue ?? value : value[(index + offset)..value.Length]; /// /// Obtains a sub-string before the first occurrence of the specified delimiter within the current instance. @@ -108,10 +101,8 @@ private static string SubstringAfterIndex(this string value, int index, int offs /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringBeforeFirst(this string value, char delimiter, string? defaultValue = null) - { - return value.SubstringBeforeIndex(value.IndexOf(delimiter), defaultValue); - } + public static string SubstringBeforeFirst(this string value, char delimiter, string? defaultValue = null) => + value.SubstringBeforeIndex(value.IndexOf(delimiter), defaultValue); /// /// Obtains a sub-string before the first occurrence of the specified delimiter within the current instance. @@ -131,10 +122,8 @@ public static string SubstringBeforeFirst(this string value, char delimiter, str /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringBeforeFirst(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) - { - return value.SubstringBeforeIndex(value.IndexOf(delimiter, comparison), defaultValue); - } + public static string SubstringBeforeFirst(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) => + value.SubstringBeforeIndex(value.IndexOf(delimiter, comparison), defaultValue); /// /// Obtains a sub-string before the last occurrence of the specified delimiter within the current instance. @@ -150,10 +139,8 @@ public static string SubstringBeforeFirst(this string value, string delimiter, s /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringBeforeLast(this string value, char delimiter, string? defaultValue = null) - { - return value.SubstringBeforeIndex(value.LastIndexOf(delimiter), defaultValue); - } + public static string SubstringBeforeLast(this string value, char delimiter, string? defaultValue = null) => + value.SubstringBeforeIndex(value.LastIndexOf(delimiter), defaultValue); /// /// Obtains a sub-string before the last occurrence of the specified delimiter within the current instance. @@ -173,10 +160,8 @@ public static string SubstringBeforeLast(this string value, char delimiter, stri /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringBeforeLast(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) - { - return value.SubstringBeforeIndex(value.LastIndexOf(delimiter, comparison), defaultValue); - } + public static string SubstringBeforeLast(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) => + value.SubstringBeforeIndex(value.LastIndexOf(delimiter, comparison), defaultValue); /// /// Obtains a sub-string after the first occurrence of the specified delimiter within the current instance. @@ -192,10 +177,8 @@ public static string SubstringBeforeLast(this string value, string delimiter, st /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringAfterFirst(this string value, char delimiter, string? defaultValue = null) - { - return value.SubstringAfterIndex(value.IndexOf(delimiter), 1, defaultValue); - } + public static string SubstringAfterFirst(this string value, char delimiter, string? defaultValue = null) => + value.SubstringAfterIndex(value.IndexOf(delimiter), 1, defaultValue); /// /// Obtains a sub-string after the first occurrence of the specified delimiter within the current instance. @@ -215,10 +198,8 @@ public static string SubstringAfterFirst(this string value, char delimiter, stri /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringAfterFirst(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) - { - return value.SubstringAfterIndex(value.IndexOf(delimiter, comparison), delimiter.Length, defaultValue); - } + public static string SubstringAfterFirst(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) => + value.SubstringAfterIndex(value.IndexOf(delimiter, comparison), delimiter.Length, defaultValue); /// /// Obtains a sub-string after the last occurrence of the specified delimiter within the current instance. @@ -234,10 +215,8 @@ public static string SubstringAfterFirst(this string value, string delimiter, st /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringAfterLast(this string value, char delimiter, string? defaultValue = null) - { - return value.SubstringAfterIndex(value.LastIndexOf(delimiter), 1, defaultValue); - } + public static string SubstringAfterLast(this string value, char delimiter, string? defaultValue = null) => + value.SubstringAfterIndex(value.LastIndexOf(delimiter), 1, defaultValue); /// /// Obtains a sub-string after the last occurrence of the specified delimiter within the current instance. @@ -257,10 +236,8 @@ public static string SubstringAfterLast(this string value, char delimiter, strin /// If the delimiter is not found, then the default value will be returned. /// If the default value is , then the current instance is returned. /// - public static string SubstringAfterLast(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) - { - return value.SubstringAfterIndex(value.LastIndexOf(delimiter, comparison), 1, defaultValue); - } + public static string SubstringAfterLast(this string value, string delimiter, string? defaultValue = null, StringComparison comparison = DefaultComparison) => + value.SubstringAfterIndex(value.LastIndexOf(delimiter, comparison), 1, defaultValue); /// /// Converts the current instance into a new instance. @@ -268,10 +245,7 @@ public static string SubstringAfterLast(this string value, string delimiter, str /// The current from which to obtain a . /// The encoding that will be used to convert the current into a . /// Returns a new representation of the current instance. - public static byte[] ToByteArray(this string value, Encoding? encoding = null) - { - return (encoding ?? DefaultEncoding).GetBytes(value); - } + public static byte[] ToByteArray(this string value, Encoding? encoding = null) => (encoding ?? DefaultEncoding).GetBytes(value); /// /// Converts the current instance into a new instance. @@ -280,10 +254,8 @@ public static byte[] ToByteArray(this string value, Encoding? encoding = null) /// An object that provides culture-specific formatting information. /// A bit-wise combination of enumeration values that indicate the style elements that can be present. /// Returns a new instance parsed from the current instance. - public static DateTime ToDateTime(this string value, IFormatProvider? provider = null, DateTimeStyles styles = DefaultStyles) - { - return DateTime.Parse(value, provider, styles); - } + public static DateTime ToDateTime(this string value, IFormatProvider? provider = null, DateTimeStyles styles = DefaultStyles) => + DateTime.Parse(value, provider, styles); /// /// Converts the current instance into a new instance. @@ -292,10 +264,8 @@ public static DateTime ToDateTime(this string value, IFormatProvider? provider = /// An object that provides culture-specific formatting information. /// A bit-wise combination of enumeration values that indicate the style elements that can be present. /// Returns a new instance parsed from the current instance. - public static DateOnly ToDateOnly(this string value, IFormatProvider? provider = null, DateTimeStyles styles = DefaultStyles) - { - return DateOnly.Parse(value, provider, styles); - } + public static DateOnly ToDateOnly(this string value, IFormatProvider? provider = null, DateTimeStyles styles = DefaultStyles) => + DateOnly.Parse(value, provider, styles); /// /// Converts the current instance into a new instance. @@ -304,10 +274,8 @@ public static DateOnly ToDateOnly(this string value, IFormatProvider? provider = /// An object that provides culture-specific formatting information. /// A bit-wise combination of enumeration values that indicate the style elements that can be present. /// Returns a new instance parsed from the current instance. - public static TimeOnly ToTimeOnly(this string value, IFormatProvider? provider = null, DateTimeStyles styles = DefaultStyles) - { - return TimeOnly.Parse(value, provider, styles); - } + public static TimeOnly ToTimeOnly(this string value, IFormatProvider? provider = null, DateTimeStyles styles = DefaultStyles) => + TimeOnly.Parse(value, provider, styles); /// /// Tries to copy the current instance into the destination . @@ -330,10 +298,7 @@ public static bool TryCopyTo(this string value, Span destination, out int /// The that should precede the current instance. /// The that should succeed the current instance. /// Returns a new instance representing the current instance, wrapped between the specified before and after instances. - public static string Wrap(this string value, char before, char after) - { - return $"{before}{value}{after}"; - } + public static string Wrap(this string value, char before, char after) => $"{before}{value}{after}"; /// /// Wraps the current instance between the specified before and after instances. @@ -342,8 +307,5 @@ public static string Wrap(this string value, char before, char after) /// The that should precede the current instance. /// The that should succeed the current instance. /// Returns a new instance representing the current instance, wrapped between the specified before and after instances. - public static string Wrap(this string value, string before, string after) - { - return $"{before}{value}{after}"; - } + public static string Wrap(this string value, string before, string after) => $"{before}{value}{after}"; } diff --git a/OnixLabs.Core/Linq/Extensions.IEnumerable.cs b/OnixLabs.Core/Linq/Extensions.IEnumerable.cs index 41b7ace..19922da 100644 --- a/OnixLabs.Core/Linq/Extensions.IEnumerable.cs +++ b/OnixLabs.Core/Linq/Extensions.IEnumerable.cs @@ -35,10 +35,8 @@ public static class IEnumerableExtensions /// The underlying type of the . /// The underlying type of each selected element. /// Returns if all selected element properties are equal; otherwise . - public static bool AllEqualBy(this IEnumerable enumerable, Func selector) - { - return enumerable.Select(selector).Distinct().IsSingle(); - } + public static bool AllEqualBy(this IEnumerable enumerable, Func selector) => + enumerable.Select(selector).Distinct().IsSingle(); /// /// Determines whether any elements of the current are equal by a specified property. @@ -48,10 +46,8 @@ public static bool AllEqualBy(this IEnumerable enumerable, Func /// The underlying type of the . /// The underlying type of each selected element. /// Returns if any selected element properties are equal; otherwise . - public static bool AnyEqualBy(this IEnumerable enumerable, Func selector) - { - return enumerable.GroupBy(selector).Any(group => group.Count() > 1); - } + public static bool AnyEqualBy(this IEnumerable enumerable, Func selector) => + enumerable.GroupBy(selector).Any(group => group.Count() > 1); /// /// Obtains a number that represents how many elements in the current do not satisfy the specified predicate condition. @@ -60,10 +56,22 @@ public static bool AnyEqualBy(this IEnumerable enumerable, Func /// The function to test each element for a condition. /// The underlying type of the . /// Returns a number that represents how many elements in the current do not satisfy the specified predicate condition. - public static int CountNot(this IEnumerable enumerable, Func predicate) - { - return enumerable.Count(element => !predicate(element)); - } + public static int CountNot(this IEnumerable enumerable, Func predicate) => + enumerable.Count(element => !predicate(element)); + + /// + /// Obtains the first element of the current that satisfies the specified predicate; + /// otherwise if no such element is found. + /// + /// The current from which to return the first satisfactory element. + /// The function to test each element for a condition. + /// The underlying type of the . + /// + /// Returns the first element of the current that satisfies the specified predicate; + /// otherwise if no such element is found. + /// + public static Optional FirstOrNone(this IEnumerable enumerable, Func? predicate = null) where T : notnull => + Optional.Of(enumerable.FirstOrDefault(predicate ?? (_ => true))); /// /// Performs the specified for each element of the current . @@ -95,10 +103,7 @@ public static int GetContentHashCode(this IEnumerable enumerable) /// The current on which to perform the operation. /// The underlying type of the . /// Returns if the is empty; otherwise, . - public static bool IsEmpty(this IEnumerable enumerable) - { - return !enumerable.Any(); - } + public static bool IsEmpty(this IEnumerable enumerable) => !enumerable.Any(); /// /// Determines whether the current is not empty. @@ -106,10 +111,7 @@ public static bool IsEmpty(this IEnumerable enumerable) /// The current on which to perform the operation. /// The underlying type of the . /// Returns if the is not empty; otherwise, . - public static bool IsNotEmpty(this IEnumerable enumerable) - { - return enumerable.Any(); - } + public static bool IsNotEmpty(this IEnumerable enumerable) => enumerable.Any(); /// /// Determines whether the current contains a single element. @@ -117,10 +119,7 @@ public static bool IsNotEmpty(this IEnumerable enumerable) /// The current on which to perform the operation. /// The underlying type of the . /// Returns if the contains a single element; otherwise, . - public static bool IsSingle(this IEnumerable enumerable) - { - return enumerable.LongCount() == 1; - } + public static bool IsSingle(this IEnumerable enumerable) => enumerable.LongCount() == 1; /// /// Determines whether the current contains an even number of elements. @@ -129,10 +128,8 @@ public static bool IsSingle(this IEnumerable enumerable) /// The function to test each element for a condition. /// The underlying type of the . /// Returns if the contains an even number of elements; otherwise, . - public static bool IsCountEven(this IEnumerable enumerable, Func? predicate = null) - { - return enumerable.LongCount(element => predicate?.Invoke(element) ?? true) % 2 == 0; - } + public static bool IsCountEven(this IEnumerable enumerable, Func? predicate = null) => + enumerable.LongCount(element => predicate?.Invoke(element) ?? true) % 2 == 0; /// /// Determines whether the current contains an odd number of elements. @@ -141,10 +138,8 @@ public static bool IsCountEven(this IEnumerable enumerable, Func? /// The function to test each element for a condition. /// The underlying type of the . /// Returns if the contains an odd number of elements; otherwise, . - public static bool IsCountOdd(this IEnumerable enumerable, Func? predicate = null) - { - return enumerable.LongCount(element => predicate?.Invoke(element) ?? true) % 2 != 0; - } + public static bool IsCountOdd(this IEnumerable enumerable, Func? predicate = null) => + enumerable.LongCount(element => predicate?.Invoke(element) ?? true) % 2 != 0; /// /// Joins the elements of the current into a instance. @@ -152,11 +147,22 @@ public static bool IsCountOdd(this IEnumerable enumerable, Func? /// The current to join. /// The separator which will appear between joined elements. /// The underlying type of the . - /// Returns the elements of the current , joined into a instance. - public static string JoinToString(this IEnumerable enumerable, string separator = ", ") - { - return string.Join(separator, enumerable); - } + /// Returns the elements of the current , joined into a new instance. + public static string JoinToString(this IEnumerable enumerable, string separator = ", ") => string.Join(separator, enumerable); + + /// + /// Obtains the last element of the current that satisfies the specified predicate; + /// otherwise if no such element is found. + /// + /// The current from which to return the last satisfactory element. + /// The function to test each element for a condition. + /// The underlying type of the . + /// + /// Returns the last element of the current that satisfies the specified predicate; + /// otherwise if no such element is found. + /// + public static Optional LastOrNone(this IEnumerable enumerable, Func? predicate = null) where T : notnull => + Optional.Of(enumerable.LastOrDefault(predicate ?? (_ => true))); /// /// Determines whether none of the elements of the current satisfy the specified predicate condition. @@ -165,10 +171,23 @@ public static string JoinToString(this IEnumerable enumerable, string sepa /// The function to test each element for a condition. /// The underlying type of the . /// Returns if none of the elements of the current satisfy the specified predicate condition; otherwise, . - public static bool None(this IEnumerable enumerable, Func predicate) - { - return !enumerable.Any(predicate); - } + public static bool None(this IEnumerable enumerable, Func predicate) => !enumerable.Any(predicate); + + /// + /// Obtains a single element of the current that satisfies the specified predicate; + /// otherwise if no such element is found, + /// or if the current contains more than one matching element. + /// + /// The current from which to return a single satisfactory element. + /// The function to test each element for a condition. + /// The underlying type of the . + /// + /// Returns a single element of the current that satisfies the specified predicate; + /// otherwise if no such element is found, + /// or if the current contains more than one matching element. + /// + public static Result> SingleOrNone(this IEnumerable enumerable, Func? predicate = null) where T : notnull => + Result>.Of(() => Optional.Of(enumerable.SingleOrDefault(predicate ?? (_ => true)))); /// /// Calculates the sum of the elements of the current . @@ -190,10 +209,8 @@ public static T Sum(this IEnumerable enumerable) where T : INumberBase /// The underlying type of the . /// The underlying type of each element to sum. /// Returns the sum of the elements of the current . - public static TResult SumBy(this IEnumerable enumerable, Func selector) where TResult : INumberBase - { - return enumerable.Select(selector).Sum(); - } + public static TResult SumBy(this IEnumerable enumerable, Func selector) where TResult : INumberBase => + enumerable.Select(selector).Sum(); /// /// Filters the current elements that do not satisfy the specified predicate condition. @@ -202,10 +219,8 @@ public static TResult SumBy(this IEnumerable enumerable, FuncThe function to test each element for a condition. /// The underlying type of the . /// Returns a new that contains elements that do not satisfy the condition. - public static IEnumerable WhereNot(this IEnumerable enumerable, Func predicate) - { - return enumerable.Where(element => !predicate(element)); - } + public static IEnumerable WhereNot(this IEnumerable enumerable, Func predicate) => + enumerable.Where(element => !predicate(element)); /// /// Filters the current elements that are not . @@ -213,10 +228,7 @@ public static IEnumerable WhereNot(this IEnumerable enumerable, FuncThe current on which to perform the operation. /// The underlying type of the . /// Returns a new that contains elements that are not . - public static IEnumerable WhereNotNull(this IEnumerable enumerable) where T : notnull - { - return enumerable.Where(element => element is not null)!; - } + public static IEnumerable WhereNotNull(this IEnumerable enumerable) where T : notnull => enumerable.Where(element => element is not null)!; /// /// Formats the current as a collection string. @@ -224,10 +236,7 @@ public static IEnumerable WhereNotNull(this IEnumerable enumerable) wh /// The current to format. /// The underlying type of the . /// Returns a new instance representing the current . - public static string ToCollectionString(this IEnumerable enumerable) - { - return enumerable.JoinToString().Wrap('[', ']'); - } + public static string ToCollectionString(this IEnumerable enumerable) => enumerable.JoinToString().Wrap('[', ']'); /// /// Formats the current as a collection string. @@ -237,8 +246,6 @@ public static string ToCollectionString(this IEnumerable enumerable) /// An object that provides culture-specific formatting information. /// The underlying type of the . /// Returns a new instance representing the current . - public static string ToCollectionString(this IEnumerable enumerable, string format, IFormatProvider? provider = null) where T : IFormattable - { - return enumerable.Select(element => element.ToString(format, provider)).ToCollectionString(); - } + public static string ToCollectionString(this IEnumerable enumerable, string format, IFormatProvider? provider = null) where T : IFormattable => + enumerable.Select(element => element.ToString(format, provider)).ToCollectionString(); } diff --git a/OnixLabs.Core/Optional.cs b/OnixLabs.Core/Optional.cs index 428ff10..b9b1e9c 100644 --- a/OnixLabs.Core/Optional.cs +++ b/OnixLabs.Core/Optional.cs @@ -64,7 +64,7 @@ internal Optional() /// Returns a new instance of the class, where the underlying value is present if /// the specified value is not ; otherwise, the underlying value is . /// - public static Optional Some(T value) => new Some(value); + public static Some Some(T value) => new(value); /// /// Creates a new instance of the class, where the underlying value is present if diff --git a/OnixLabs.Core/Preconditions.cs b/OnixLabs.Core/Preconditions.cs index 6be4c44..fb9b666 100644 --- a/OnixLabs.Core/Preconditions.cs +++ b/OnixLabs.Core/Preconditions.cs @@ -41,10 +41,7 @@ public static void Check(bool condition, string message = "Check failed.") /// The underlying type of the value. /// Returns a non-null value of the specified type. /// If the specified value is . - public static T CheckNotNull(T? value, string message = "Argument must not be null.") - { - return value ?? throw new InvalidOperationException(message); - } + public static T CheckNotNull(T? value, string message = "Argument must not be null.") => value ?? throw new InvalidOperationException(message); /// /// Performs a general pre-condition requirement that fails when the specified condition is . @@ -79,10 +76,8 @@ public static void RequireWithinRange(bool condition, string message = "Argument /// The underlying type of the value. /// Returns a non-null value of the specified type. /// If the specified value is . - public static T RequireNotNull(T? value, string message = "Argument must not be null.", string? parameterName = null) - { - return value ?? throw new ArgumentNullException(parameterName, message); - } + public static T RequireNotNull(T? value, string message = "Argument must not be null.", string? parameterName = null) => + value ?? throw new ArgumentNullException(parameterName, message); /// /// Performs a general pre-condition requirement that the specified value is defined by the specified type. diff --git a/OnixLabs.Core/Reflection/Extensions.Type.cs b/OnixLabs.Core/Reflection/Extensions.Type.cs index 7ca3965..377acc0 100644 --- a/OnixLabs.Core/Reflection/Extensions.Type.cs +++ b/OnixLabs.Core/Reflection/Extensions.Type.cs @@ -33,8 +33,5 @@ public static class TypeExtensions /// /// The current instance from which to obtain the simple name. /// Returns the simple type name from the current instance. - public static string GetName(this Type type) - { - return type.Name.SubstringBeforeFirst(GenericTypeIdentifierMarker); - } + public static string GetName(this Type type) => type.Name.SubstringBeforeFirst(GenericTypeIdentifierMarker); } diff --git a/OnixLabs.Core/Result.Failure.cs b/OnixLabs.Core/Result.Failure.cs index 82d550e..1face1c 100644 --- a/OnixLabs.Core/Result.Failure.cs +++ b/OnixLabs.Core/Result.Failure.cs @@ -141,6 +141,11 @@ public sealed class Failure : Result, IValueEquatable> /// public override Result SelectMany(Func> selector) => Result.Failure(Exception); + /// + /// Throws the underlying exception if the current is in a failure state. + /// + public override void Throw() => throw Exception; + /// /// Returns a that represents the current object. /// diff --git a/OnixLabs.Core/Result.Success.cs b/OnixLabs.Core/Result.Success.cs index f7d2ca7..73b7e80 100644 --- a/OnixLabs.Core/Result.Success.cs +++ b/OnixLabs.Core/Result.Success.cs @@ -141,6 +141,13 @@ public sealed class Success : Result, IValueEquatable> /// public override Result SelectMany(Func> selector) => selector(Value); + /// + /// Throws the underlying exception if the current is in a failure state. + /// + public override void Throw() + { + } + /// /// Returns a that represents the current object. /// diff --git a/OnixLabs.Core/Result.cs b/OnixLabs.Core/Result.cs index 0d61fc1..2625194 100644 --- a/OnixLabs.Core/Result.cs +++ b/OnixLabs.Core/Result.cs @@ -60,7 +60,7 @@ public static Result Of(Func func) /// /// Returns a new instance of the class, where the underlying value represents a successful result. /// - public static Result Success(T value) => new Success(value); + public static Success Success(T value) => new(value); /// /// Creates a new instance of the class, where the underlying exception represents a failed result. @@ -69,7 +69,7 @@ public static Result Of(Func func) /// /// Returns a new instance of the class, where the underlying exception represents a failed result. /// - public static Result Failure(Exception exception) => new Failure(exception); + public static Failure Failure(Exception exception) => new(exception); /// /// Creates a new instance of the class, where the underlying value represents a successful result. @@ -204,6 +204,11 @@ public static Result Of(Func func) /// public abstract Result SelectMany(Func> selector) where TResult : notnull; + /// + /// Throws the underlying exception if the current is in a failure state. + /// + public abstract void Throw(); + /// /// Returns a that represents the current object. /// diff --git a/OnixLabs.Core/Text/Base16.Equatable.cs b/OnixLabs.Core/Text/Base16.Equatable.cs index dee52b2..2b9bc5d 100644 --- a/OnixLabs.Core/Text/Base16.Equatable.cs +++ b/OnixLabs.Core/Text/Base16.Equatable.cs @@ -24,29 +24,20 @@ public readonly partial struct Base16 /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(Base16 other) - { - return other.value.SequenceEqual(value); - } + public bool Equals(Base16 other) => other.value.SequenceEqual(value); /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is Base16 other && Equals(other); - } + public override bool Equals(object? obj) => obj is Base16 other && Equals(other); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return value.GetContentHashCode(); - } + public override int GetHashCode() => value.GetContentHashCode(); /// /// Performs an equality comparison between two object instances. @@ -54,10 +45,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(Base16 left, Base16 right) - { - return Equals(left, right); - } + public static bool operator ==(Base16 left, Base16 right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -65,8 +53,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(Base16 left, Base16 right) - { - return !Equals(left, right); - } + public static bool operator !=(Base16 left, Base16 right) => !Equals(left, right); } diff --git a/OnixLabs.Core/Text/Base16.Parse.cs b/OnixLabs.Core/Text/Base16.Parse.cs index 880eae8..0cd44e0 100644 --- a/OnixLabs.Core/Text/Base16.Parse.cs +++ b/OnixLabs.Core/Text/Base16.Parse.cs @@ -24,10 +24,7 @@ public readonly partial struct Base16 /// The Base-16 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-16 encoded value. - public static Base16 Parse(string value, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), provider); - } + public static Base16 Parse(string value, IFormatProvider? provider = null) => Parse(value.AsSpan(), provider); /// /// Parses the specified Base-16 encoded value into a value. @@ -35,11 +32,7 @@ public static Base16 Parse(string value, IFormatProvider? provider = null) /// The Base-16 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-16 encoded value. - public static Base16 Parse(ReadOnlySpan value, IFormatProvider? provider = null) - { - byte[] bytes = IBaseCodec.Base16.Decode(value, provider); - return new Base16(bytes); - } + public static Base16 Parse(ReadOnlySpan value, IFormatProvider? provider = null) => new(IBaseCodec.Base16.Decode(value, provider)); /// /// Tries to parse the specified Base-16 encoded value into a value. @@ -51,10 +44,7 @@ public static Base16 Parse(ReadOnlySpan value, IFormatProvider? provider = /// or the default value if the specified Base-16 encoded could not be parsed. /// /// Returns if the specified Base-16 value was decoded successfully; otherwise, . - public static bool TryParse(string? value, IFormatProvider? provider, out Base16 result) - { - return TryParse(value.AsSpan(), provider, out result); - } + public static bool TryParse(string? value, IFormatProvider? provider, out Base16 result) => TryParse(value.AsSpan(), provider, out result); /// /// Tries to parse the specified Base-16 encoded value into a value. diff --git a/OnixLabs.Core/Text/Base16.To.cs b/OnixLabs.Core/Text/Base16.To.cs index 1cc48cd..75c1e10 100644 --- a/OnixLabs.Core/Text/Base16.To.cs +++ b/OnixLabs.Core/Text/Base16.To.cs @@ -22,29 +22,20 @@ public readonly partial struct Base16 /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return value.Copy(); - } + public byte[] ToByteArray() => value.Copy(); /// /// Returns a that represents the current object. /// /// Returns a that represents the current object. - public override string ToString() - { - return ToString(Base16FormatProvider.Invariant); - } + public override string ToString() => ToString(Base16FormatProvider.Invariant); /// /// Formats the value of the current instance using the specified format. /// /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(IFormatProvider? formatProvider) - { - return ToString(null, formatProvider); - } + public string ToString(IFormatProvider? formatProvider) => ToString(null, formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -52,10 +43,7 @@ public string ToString(IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(string? format, IFormatProvider? formatProvider) - { - return ToString(format.AsSpan(), formatProvider); - } + public string ToString(string? format, IFormatProvider? formatProvider) => ToString(format.AsSpan(), formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -63,8 +51,5 @@ public string ToString(string? format, IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) - { - return IBaseCodec.Base16.Encode(value, formatProvider); - } + public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) => IBaseCodec.Base16.Encode(value, formatProvider); } diff --git a/OnixLabs.Core/Text/Base16.cs b/OnixLabs.Core/Text/Base16.cs index eeba0e6..8375c09 100644 --- a/OnixLabs.Core/Text/Base16.cs +++ b/OnixLabs.Core/Text/Base16.cs @@ -23,11 +23,4 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base16(ReadOnlySpan value) : IBaseValue { private readonly byte[] value = value.ToArray(); - - /// - /// Initializes a new default value. - /// - public Base16() : this([]) - { - } } diff --git a/OnixLabs.Core/Text/Base16FormatProvider.cs b/OnixLabs.Core/Text/Base16FormatProvider.cs index 82541cf..e259c1d 100644 --- a/OnixLabs.Core/Text/Base16FormatProvider.cs +++ b/OnixLabs.Core/Text/Base16FormatProvider.cs @@ -44,10 +44,7 @@ public sealed class Base16FormatProvider : Enumeration, IF /// The value of the enumeration entry. /// The name of the enumeration entry. /// The alphabet of the format provider. - private Base16FormatProvider(int value, string name, string alphabet) : base(value, name) - { - Alphabet = alphabet; - } + private Base16FormatProvider(int value, string name, string alphabet) : base(value, name) => Alphabet = alphabet; /// /// Gets the alphabet of the current instance. @@ -60,8 +57,5 @@ private Base16FormatProvider(int value, string name, string alphabet) : base(val /// Returns an instance of the object specified by , /// if the implementation can supply that type of object; otherwise, . /// - public object? GetFormat(Type? formatType) - { - return formatType == typeof(Base16FormatProvider) ? this : null; - } + public object? GetFormat(Type? formatType) => formatType == typeof(Base16FormatProvider) ? this : null; } diff --git a/OnixLabs.Core/Text/Base32.Equatable.cs b/OnixLabs.Core/Text/Base32.Equatable.cs index e9f993e..9e766e6 100644 --- a/OnixLabs.Core/Text/Base32.Equatable.cs +++ b/OnixLabs.Core/Text/Base32.Equatable.cs @@ -24,29 +24,20 @@ public readonly partial struct Base32 /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(Base32 other) - { - return other.value.SequenceEqual(value); - } + public bool Equals(Base32 other) => other.value.SequenceEqual(value); /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is Base32 other && Equals(other); - } + public override bool Equals(object? obj) => obj is Base32 other && Equals(other); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return value.GetContentHashCode(); - } + public override int GetHashCode() => value.GetContentHashCode(); /// /// Performs an equality comparison between two object instances. @@ -54,10 +45,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(Base32 left, Base32 right) - { - return Equals(left, right); - } + public static bool operator ==(Base32 left, Base32 right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -65,8 +53,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(Base32 left, Base32 right) - { - return !Equals(left, right); - } + public static bool operator !=(Base32 left, Base32 right) => !Equals(left, right); } diff --git a/OnixLabs.Core/Text/Base32.Parse.cs b/OnixLabs.Core/Text/Base32.Parse.cs index a41403c..59f7d6b 100644 --- a/OnixLabs.Core/Text/Base32.Parse.cs +++ b/OnixLabs.Core/Text/Base32.Parse.cs @@ -24,10 +24,7 @@ public readonly partial struct Base32 /// The Base-32 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-32 encoded value. - public static Base32 Parse(string value, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), provider); - } + public static Base32 Parse(string value, IFormatProvider? provider = null) => Parse(value.AsSpan(), provider); /// /// Parses the specified Base-32 encoded value into a value. @@ -35,11 +32,7 @@ public static Base32 Parse(string value, IFormatProvider? provider = null) /// The Base-32 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-32 encoded value. - public static Base32 Parse(ReadOnlySpan value, IFormatProvider? provider = null) - { - byte[] bytes = IBaseCodec.Base32.Decode(value, provider); - return new Base32(bytes); - } + public static Base32 Parse(ReadOnlySpan value, IFormatProvider? provider = null) => new(IBaseCodec.Base32.Decode(value, provider)); /// /// Tries to parse the specified Base-32 encoded value into a value. @@ -51,10 +44,7 @@ public static Base32 Parse(ReadOnlySpan value, IFormatProvider? provider = /// or the default value if the specified Base-32 encoded could not be parsed. /// /// Returns if the specified Base-32 value was decoded successfully; otherwise, . - public static bool TryParse(string? value, IFormatProvider? provider, out Base32 result) - { - return TryParse(value.AsSpan(), provider, out result); - } + public static bool TryParse(string? value, IFormatProvider? provider, out Base32 result) => TryParse(value.AsSpan(), provider, out result); /// /// Tries to parse the specified Base-32 encoded value into a value. diff --git a/OnixLabs.Core/Text/Base32.To.cs b/OnixLabs.Core/Text/Base32.To.cs index 0b38cc9..fc21b64 100644 --- a/OnixLabs.Core/Text/Base32.To.cs +++ b/OnixLabs.Core/Text/Base32.To.cs @@ -22,29 +22,20 @@ public readonly partial struct Base32 /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return value.Copy(); - } + public byte[] ToByteArray() => value.Copy(); /// /// Returns a that represents the current object. /// /// Returns a that represents the current object. - public override string ToString() - { - return ToString(Base32FormatProvider.Rfc4648); - } + public override string ToString() => ToString(Base32FormatProvider.Rfc4648); /// /// Formats the value of the current instance using the specified format. /// /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(IFormatProvider? formatProvider) - { - return ToString(null, formatProvider); - } + public string ToString(IFormatProvider? formatProvider) => ToString(null, formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -52,10 +43,7 @@ public string ToString(IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(string? format, IFormatProvider? formatProvider) - { - return ToString(format.AsSpan(), formatProvider); - } + public string ToString(string? format, IFormatProvider? formatProvider) => ToString(format.AsSpan(), formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -63,8 +51,5 @@ public string ToString(string? format, IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) - { - return IBaseCodec.Base32.Encode(value, formatProvider); - } + public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) => IBaseCodec.Base32.Encode(value, formatProvider); } diff --git a/OnixLabs.Core/Text/Base32.cs b/OnixLabs.Core/Text/Base32.cs index d19042d..64074d5 100644 --- a/OnixLabs.Core/Text/Base32.cs +++ b/OnixLabs.Core/Text/Base32.cs @@ -23,11 +23,4 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base32(ReadOnlySpan value) : IBaseValue { private readonly byte[] value = value.ToArray(); - - /// - /// Initializes a new default value. - /// - public Base32() : this([]) - { - } } diff --git a/OnixLabs.Core/Text/Base32FormatProvider.cs b/OnixLabs.Core/Text/Base32FormatProvider.cs index 28c0d72..a0e0d02 100644 --- a/OnixLabs.Core/Text/Base32FormatProvider.cs +++ b/OnixLabs.Core/Text/Base32FormatProvider.cs @@ -78,11 +78,7 @@ public sealed class Base32FormatProvider : Enumeration, IF /// The name of the enumeration entry. /// The alphabet of the format provider. /// A value indicating whether the format provider uses padding. - private Base32FormatProvider(int value, string name, string alphabet, bool isPadded) : base(value, name) - { - Alphabet = alphabet; - IsPadded = isPadded; - } + private Base32FormatProvider(int value, string name, string alphabet, bool isPadded) : base(value, name) => (Alphabet, IsPadded) = (alphabet, isPadded); /// /// Gets the alphabet of the current instance. @@ -100,8 +96,5 @@ private Base32FormatProvider(int value, string name, string alphabet, bool isPad /// Returns an instance of the object specified by , /// if the implementation can supply that type of object; otherwise, . /// - public object? GetFormat(Type? formatType) - { - return formatType == typeof(Base32FormatProvider) ? this : null; - } + public object? GetFormat(Type? formatType) => formatType == typeof(Base32FormatProvider) ? this : null; } diff --git a/OnixLabs.Core/Text/Base58.Equatable.cs b/OnixLabs.Core/Text/Base58.Equatable.cs index 40020c3..3ead169 100644 --- a/OnixLabs.Core/Text/Base58.Equatable.cs +++ b/OnixLabs.Core/Text/Base58.Equatable.cs @@ -24,29 +24,20 @@ public readonly partial struct Base58 /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(Base58 other) - { - return other.value.SequenceEqual(value); - } + public bool Equals(Base58 other) => other.value.SequenceEqual(value); /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is Base58 other && Equals(other); - } + public override bool Equals(object? obj) => obj is Base58 other && Equals(other); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return value.GetContentHashCode(); - } + public override int GetHashCode() => value.GetContentHashCode(); /// /// Performs an equality comparison between two object instances. @@ -54,10 +45,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(Base58 left, Base58 right) - { - return Equals(left, right); - } + public static bool operator ==(Base58 left, Base58 right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -65,8 +53,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(Base58 left, Base58 right) - { - return !Equals(left, right); - } + public static bool operator !=(Base58 left, Base58 right) => !Equals(left, right); } diff --git a/OnixLabs.Core/Text/Base58.Parse.cs b/OnixLabs.Core/Text/Base58.Parse.cs index a09da23..584ed7e 100644 --- a/OnixLabs.Core/Text/Base58.Parse.cs +++ b/OnixLabs.Core/Text/Base58.Parse.cs @@ -24,10 +24,7 @@ public readonly partial struct Base58 /// The Base-58 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-58 encoded value. - public static Base58 Parse(string value, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), provider); - } + public static Base58 Parse(string value, IFormatProvider? provider = null) => Parse(value.AsSpan(), provider); /// /// Parses the specified Base-58 encoded value into a value. @@ -35,11 +32,7 @@ public static Base58 Parse(string value, IFormatProvider? provider = null) /// The Base-58 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-58 encoded value. - public static Base58 Parse(ReadOnlySpan value, IFormatProvider? provider = null) - { - byte[] bytes = IBaseCodec.Base58.Decode(value, provider); - return new Base58(bytes); - } + public static Base58 Parse(ReadOnlySpan value, IFormatProvider? provider = null) => new(IBaseCodec.Base58.Decode(value, provider)); /// /// Tries to parse the specified Base-58 encoded value into a value. @@ -51,10 +44,7 @@ public static Base58 Parse(ReadOnlySpan value, IFormatProvider? provider = /// or the default value if the specified Base-58 encoded could not be parsed. /// /// Returns if the specified Base-58 value was decoded successfully; otherwise, . - public static bool TryParse(string? value, IFormatProvider? provider, out Base58 result) - { - return TryParse(value.AsSpan(), provider, out result); - } + public static bool TryParse(string? value, IFormatProvider? provider, out Base58 result) => TryParse(value.AsSpan(), provider, out result); /// /// Tries to parse the specified Base-58 encoded value into a value. diff --git a/OnixLabs.Core/Text/Base58.To.cs b/OnixLabs.Core/Text/Base58.To.cs index d3f2ae9..aac8ee7 100644 --- a/OnixLabs.Core/Text/Base58.To.cs +++ b/OnixLabs.Core/Text/Base58.To.cs @@ -22,29 +22,20 @@ public readonly partial struct Base58 /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return value.Copy(); - } + public byte[] ToByteArray() => value.Copy(); /// /// Returns a that represents the current object. /// /// Returns a that represents the current object. - public override string ToString() - { - return ToString(Base58FormatProvider.Bitcoin); - } + public override string ToString() => ToString(Base58FormatProvider.Bitcoin); /// /// Formats the value of the current instance using the specified format. /// /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(IFormatProvider? formatProvider) - { - return ToString(null, formatProvider); - } + public string ToString(IFormatProvider? formatProvider) => ToString(null, formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -52,10 +43,7 @@ public string ToString(IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(string? format, IFormatProvider? formatProvider) - { - return ToString(format.AsSpan(), formatProvider); - } + public string ToString(string? format, IFormatProvider? formatProvider) => ToString(format.AsSpan(), formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -63,8 +51,5 @@ public string ToString(string? format, IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) - { - return IBaseCodec.Base58.Encode(value, formatProvider); - } + public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) => IBaseCodec.Base58.Encode(value, formatProvider); } diff --git a/OnixLabs.Core/Text/Base58.cs b/OnixLabs.Core/Text/Base58.cs index 3bbfc8a..11efd02 100644 --- a/OnixLabs.Core/Text/Base58.cs +++ b/OnixLabs.Core/Text/Base58.cs @@ -23,11 +23,4 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base58(ReadOnlySpan value) : IBaseValue { private readonly byte[] value = value.ToArray(); - - /// - /// Initializes a new default value. - /// - public Base58() : this([]) - { - } } diff --git a/OnixLabs.Core/Text/Base58FormatProvider.cs b/OnixLabs.Core/Text/Base58FormatProvider.cs index 360e9d2..7e97486 100644 --- a/OnixLabs.Core/Text/Base58FormatProvider.cs +++ b/OnixLabs.Core/Text/Base58FormatProvider.cs @@ -43,10 +43,7 @@ public sealed class Base58FormatProvider : Enumeration, IF /// The value of the enumeration entry. /// The name of the enumeration entry. /// The alphabet of the format provider. - private Base58FormatProvider(int value, string name, string alphabet) : base(value, name) - { - Alphabet = alphabet; - } + private Base58FormatProvider(int value, string name, string alphabet) : base(value, name) => Alphabet = alphabet; /// /// Gets the alphabet of the current instance. @@ -59,8 +56,5 @@ private Base58FormatProvider(int value, string name, string alphabet) : base(val /// Returns an instance of the object specified by , /// if the implementation can supply that type of object; otherwise, . /// - public object? GetFormat(Type? formatType) - { - return formatType == typeof(Base58FormatProvider) ? this : null; - } + public object? GetFormat(Type? formatType) => formatType == typeof(Base58FormatProvider) ? this : null; } diff --git a/OnixLabs.Core/Text/Base64.Equatable.cs b/OnixLabs.Core/Text/Base64.Equatable.cs index 709c1af..ddcf92d 100644 --- a/OnixLabs.Core/Text/Base64.Equatable.cs +++ b/OnixLabs.Core/Text/Base64.Equatable.cs @@ -24,29 +24,20 @@ public readonly partial struct Base64 /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(Base64 other) - { - return other.value.SequenceEqual(value); - } + public bool Equals(Base64 other) => other.value.SequenceEqual(value); /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is Base64 other && Equals(other); - } + public override bool Equals(object? obj) => obj is Base64 other && Equals(other); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return value.GetContentHashCode(); - } + public override int GetHashCode() => value.GetContentHashCode(); /// /// Performs an equality comparison between two object instances. @@ -54,10 +45,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(Base64 left, Base64 right) - { - return Equals(left, right); - } + public static bool operator ==(Base64 left, Base64 right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -65,8 +53,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(Base64 left, Base64 right) - { - return !Equals(left, right); - } + public static bool operator !=(Base64 left, Base64 right) => !Equals(left, right); } diff --git a/OnixLabs.Core/Text/Base64.Parse.cs b/OnixLabs.Core/Text/Base64.Parse.cs index 89a0bb5..83fd5ea 100644 --- a/OnixLabs.Core/Text/Base64.Parse.cs +++ b/OnixLabs.Core/Text/Base64.Parse.cs @@ -24,10 +24,7 @@ public readonly partial struct Base64 /// The Base-64 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-64 encoded value. - public static Base64 Parse(string value, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), provider); - } + public static Base64 Parse(string value, IFormatProvider? provider = null) => Parse(value.AsSpan(), provider); /// /// Parses the specified Base-64 encoded value into a value. @@ -35,11 +32,7 @@ public static Base64 Parse(string value, IFormatProvider? provider = null) /// The Base-64 encoded value to parse. /// The format provider that will be used to decode the specified value. /// Returns a new instance, parsed from the specified Base-64 encoded value. - public static Base64 Parse(ReadOnlySpan value, IFormatProvider? provider = null) - { - byte[] bytes = IBaseCodec.Base64.Decode(value, provider); - return new Base64(bytes); - } + public static Base64 Parse(ReadOnlySpan value, IFormatProvider? provider = null) => new(IBaseCodec.Base64.Decode(value, provider)); /// /// Tries to parse the specified Base-64 encoded value into a value. @@ -51,10 +44,7 @@ public static Base64 Parse(ReadOnlySpan value, IFormatProvider? provider = /// or the default value if the specified Base-64 encoded could not be parsed. /// /// Returns if the specified Base-64 value was decoded successfully; otherwise, . - public static bool TryParse(string? value, IFormatProvider? provider, out Base64 result) - { - return TryParse(value.AsSpan(), provider, out result); - } + public static bool TryParse(string? value, IFormatProvider? provider, out Base64 result) => TryParse(value.AsSpan(), provider, out result); /// /// Tries to parse the specified Base-64 encoded value into a value. diff --git a/OnixLabs.Core/Text/Base64.To.cs b/OnixLabs.Core/Text/Base64.To.cs index 4ba8048..fa67955 100644 --- a/OnixLabs.Core/Text/Base64.To.cs +++ b/OnixLabs.Core/Text/Base64.To.cs @@ -22,29 +22,20 @@ public readonly partial struct Base64 /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return value.Copy(); - } + public byte[] ToByteArray() => value.Copy(); /// /// Returns a that represents the current object. /// /// Returns a that represents the current object. - public override string ToString() - { - return ToString(null); - } + public override string ToString() => ToString(null); /// /// Formats the value of the current instance using the specified format. /// /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(IFormatProvider? formatProvider) - { - return ToString(null, formatProvider); - } + public string ToString(IFormatProvider? formatProvider) => ToString(null, formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -52,10 +43,7 @@ public string ToString(IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(string? format, IFormatProvider? formatProvider) - { - return ToString(format.AsSpan(), formatProvider); - } + public string ToString(string? format, IFormatProvider? formatProvider) => ToString(format.AsSpan(), formatProvider); /// /// Formats the value of the current instance using the specified format. @@ -63,8 +51,5 @@ public string ToString(string? format, IFormatProvider? formatProvider) /// The format to use. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) - { - return IBaseCodec.Base64.Encode(value, formatProvider); - } + public string ToString(ReadOnlySpan format, IFormatProvider? formatProvider) => IBaseCodec.Base64.Encode(value, formatProvider); } diff --git a/OnixLabs.Core/Text/Base64.cs b/OnixLabs.Core/Text/Base64.cs index 09d103f..854ddc3 100644 --- a/OnixLabs.Core/Text/Base64.cs +++ b/OnixLabs.Core/Text/Base64.cs @@ -23,11 +23,4 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base64(ReadOnlySpan value) : IBaseValue { private readonly byte[] value = value.ToArray(); - - /// - /// Initializes a new default value. - /// - public Base64() : this([]) - { - } } diff --git a/OnixLabs.Core/Text/Extensions.StringBuilder.cs b/OnixLabs.Core/Text/Extensions.StringBuilder.cs index 0131c9a..c142e4d 100644 --- a/OnixLabs.Core/Text/Extensions.StringBuilder.cs +++ b/OnixLabs.Core/Text/Extensions.StringBuilder.cs @@ -31,10 +31,7 @@ public static class StringBuilderExtensions /// The to append to. /// The values to append. /// Returns the current with the specified items appended. - public static StringBuilder Append(this StringBuilder builder, params object[] values) - { - return builder.Append(values.JoinToString(string.Empty)); - } + public static StringBuilder Append(this StringBuilder builder, params object[] values) => builder.Append(values.JoinToString(string.Empty)); /// /// Prepends the specified values to the current . @@ -42,10 +39,7 @@ public static StringBuilder Append(this StringBuilder builder, params object[] v /// The to prepend to. /// The values to prepend. /// Returns the current with the specified items prepended. - public static StringBuilder Prepend(this StringBuilder builder, params object[] values) - { - return builder.Insert(0, values.JoinToString(string.Empty)); - } + public static StringBuilder Prepend(this StringBuilder builder, params object[] values) => builder.Insert(0, values.JoinToString(string.Empty)); /// /// Trims the specified value from the start and end of the current . @@ -53,10 +47,7 @@ public static StringBuilder Prepend(this StringBuilder builder, params object[] /// The to trim. /// The value to trim. /// Returns the current with the specified value trimmed from the start and end. - public static StringBuilder Trim(this StringBuilder builder, char value) - { - return builder.TrimStart(value).TrimEnd(value); - } + public static StringBuilder Trim(this StringBuilder builder, char value) => builder.TrimStart(value).TrimEnd(value); /// /// Trims the specified value from the end of the current . @@ -92,10 +83,7 @@ public static StringBuilder TrimStart(this StringBuilder builder, char value) /// The to trim. /// The value to trim. /// Returns the current with the specified value trimmed from the start and end. - public static StringBuilder Trim(this StringBuilder builder, string value) - { - return builder.TrimStart(value).TrimEnd(value); - } + public static StringBuilder Trim(this StringBuilder builder, string value) => builder.TrimStart(value).TrimEnd(value); /// /// Trims the specified value from the end of the current . @@ -132,10 +120,7 @@ public static StringBuilder TrimStart(this StringBuilder builder, string value) /// The value to prepend. /// The value to append. /// Returns the current wrapped between the specified start and end values. - public static StringBuilder Wrap(this StringBuilder builder, char start, char end) - { - return builder.Prepend(start).Append(end); - } + public static StringBuilder Wrap(this StringBuilder builder, char start, char end) => builder.Prepend(start).Append(end); /// /// Wraps the current between the specified start and end values. @@ -144,8 +129,5 @@ public static StringBuilder Wrap(this StringBuilder builder, char start, char en /// The value to prepend. /// The value to append. /// Returns the current wrapped between the specified start and end values. - public static StringBuilder Wrap(this StringBuilder builder, string start, string end) - { - return builder.Prepend(start).Append(end); - } + public static StringBuilder Wrap(this StringBuilder builder, string start, string end) => builder.Prepend(start).Append(end); } diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTrimTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTrimTests.cs index 30007ca..4c342e6 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTrimTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTrimTests.cs @@ -24,7 +24,7 @@ public sealed class BigDecimalArithmeticTrimTests public void BigDecimalTrimTrailingZerosShouldProduceExpectedResult(decimal value, decimal expected) { // When - BigDecimal actual = BigDecimal.TrimTrailingZeros(value); + BigDecimal actual = value.ToBigDecimal().TrimTrailingZeros(); // Then Assert.Equal(expected, actual); diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalComparableTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalComparableTests.cs new file mode 100644 index 0000000..6d6e362 --- /dev/null +++ b/OnixLabs.Numerics.UnitTests/BigDecimalComparableTests.cs @@ -0,0 +1,40 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Xunit; + +namespace OnixLabs.Numerics.UnitTests; + +public sealed class BigDecimalComparableTests +{ + [Theory(DisplayName = "BigDecimal.CompareTo should produce the expected result")] + [InlineData(0, 0, 0)] + [InlineData(0, 1, -1)] + [InlineData(1, 0, 1)] + [InlineData(0, -1, 1)] + [InlineData(-1, 0, -1)] + [InlineData(-1, -1, 0)] + [InlineData(1.1, 0.1, 1)] + [InlineData(1.1, 1.2, -1)] + [InlineData(0.01, 0.02, -1)] + [InlineData(-0.01, -0.02, 1)] + public void BigDecimalCompareToShouldProduceExpectedResult(double left, double right, double expected) + { + // When + int actual = BigDecimal.Compare(left, right); + + // Then + Assert.Equal(expected, actual); + } +} diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalEquatableTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalEquatableTests.cs new file mode 100644 index 0000000..8e4770b --- /dev/null +++ b/OnixLabs.Numerics.UnitTests/BigDecimalEquatableTests.cs @@ -0,0 +1,36 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Xunit; + +namespace OnixLabs.Numerics.UnitTests; + +public sealed class BigDecimalEquatableTests +{ + [Theory(DisplayName = "BigDecimal.Equals should produce the expected result")] + [InlineData(0, 0, true)] + [InlineData(0, 1, false)] + [InlineData(1, 0, false)] + [InlineData(1.1, 0.1, false)] + public void BigDecimalEqualsShouldProduceExpectedResult(double left, double right, bool expected) + { + // When + bool actual = BigDecimal.Equals(left, right); + + // Then + Assert.Equal(expected, actual); + Assert.True(left.ToBigDecimal() == right.ToBigDecimal() == expected); + Assert.True(left.ToBigDecimal() != right.ToBigDecimal() != expected); + } +} diff --git a/OnixLabs.Numerics.UnitTests/NumberInfoComparableTests.cs b/OnixLabs.Numerics.UnitTests/NumberInfoComparableTests.cs new file mode 100644 index 0000000..ac0d7d2 --- /dev/null +++ b/OnixLabs.Numerics.UnitTests/NumberInfoComparableTests.cs @@ -0,0 +1,40 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Xunit; + +namespace OnixLabs.Numerics.UnitTests; + +public sealed class NumberInfoComparableTests +{ + [Theory(DisplayName = "NumberInfo.CompareTo should produce the expected result")] + [InlineData(0, 0, 0)] + [InlineData(0, 1, -1)] + [InlineData(1, 0, 1)] + [InlineData(0, -1, 1)] + [InlineData(-1, 0, -1)] + [InlineData(-1, -1, 0)] + [InlineData(1.1, 0.1, 1)] + [InlineData(1.1, 1.2, -1)] + [InlineData(0.01, 0.02, -1)] + [InlineData(-0.01, -0.02, 1)] + public void NumberInfoCompareToShouldProduceExpectedResult(double left, double right, double expected) + { + // When + int actual = NumberInfo.Compare(left.ToNumberInfo(), right.ToNumberInfo()); + + // Then + Assert.Equal(expected, actual); + } +} diff --git a/OnixLabs.Numerics.UnitTests/NumberInfoEquatableTests.cs b/OnixLabs.Numerics.UnitTests/NumberInfoEquatableTests.cs new file mode 100644 index 0000000..cf83cb8 --- /dev/null +++ b/OnixLabs.Numerics.UnitTests/NumberInfoEquatableTests.cs @@ -0,0 +1,36 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Xunit; + +namespace OnixLabs.Numerics.UnitTests; + +public sealed class NumberInfoEquatableTests +{ + [Theory(DisplayName = "NumberInfo.Equals should produce the expected result")] + [InlineData(0, 0, true)] + [InlineData(0, 1, false)] + [InlineData(1, 0, false)] + [InlineData(1.1, 0.1, false)] + public void NumberInfoEqualsShouldProduceExpectedResult(double left, double right, bool expected) + { + // When + bool actual = NumberInfo.Equals(left.ToNumberInfo(), right.ToNumberInfo()); + + // Then + Assert.Equal(expected, actual); + Assert.True(left.ToNumberInfo() == right.ToNumberInfo() == expected); + Assert.True(left.ToNumberInfo() != right.ToNumberInfo() != expected); + } +} diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Abs.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Abs.cs index a591696..97459b6 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Abs.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Abs.cs @@ -23,8 +23,5 @@ public readonly partial struct BigDecimal /// /// The from which to obtain an absolute value. /// Returns the absolute value of the specified value. - public static BigDecimal Abs(BigDecimal value) - { - return new BigDecimal(BigInteger.Abs(value.UnscaledValue), value.Scale); - } + public static BigDecimal Abs(BigDecimal value) => new(BigInteger.Abs(value.UnscaledValue), value.Scale); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Addition.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Addition.cs index 57c1159..80db953 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Addition.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Addition.cs @@ -43,8 +43,5 @@ public static BigDecimal Add(BigDecimal left, BigDecimal right) /// The left-hand value to add to. /// The right-hand value to add. /// Returns the sum of the specified values. - public static BigDecimal operator +(BigDecimal left, BigDecimal right) - { - return Add(left, right); - } + public static BigDecimal operator +(BigDecimal left, BigDecimal right) => Add(left, right); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Decrement.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Decrement.cs index c0d9592..c11905a 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Decrement.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Decrement.cs @@ -23,28 +23,19 @@ public readonly partial struct BigDecimal /// /// The value to decrement. /// Returns a new value decremented by one integral unit. - public static BigDecimal Decrement(BigDecimal value) - { - return new BigDecimal(value.UnscaledValue - value.number.ScaleFactor, value.Scale); - } + public static BigDecimal Decrement(BigDecimal value) => new(value.UnscaledValue - value.number.ScaleFactor, value.Scale); /// /// Decrements the fractional component of the specified value by one. /// /// The value to decrement. /// Returns a new value decremented by one fractional unit. - public static BigDecimal DecrementFraction(BigDecimal value) - { - return new BigDecimal(value.UnscaledValue - BigInteger.One, value.Scale); - } + public static BigDecimal DecrementFraction(BigDecimal value) => new(value.UnscaledValue - BigInteger.One, value.Scale); /// /// Decrements the integral component of the specified value by one. /// /// The value to decrement. /// Returns a new value decremented by one integral unit. - public static BigDecimal operator --(BigDecimal value) - { - return Decrement(value); - } + public static BigDecimal operator --(BigDecimal value) => Decrement(value); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Division.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Division.cs index 7601563..e83938b 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Division.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Division.cs @@ -46,10 +46,7 @@ public static BigDecimal Divide(BigDecimal left, BigDecimal right, MidpointRound /// The left-hand value to divide. /// The right-hand value to divide by. /// Returns the quotient of the specified values. - public static BigDecimal operator /(BigDecimal left, BigDecimal right) - { - return Divide(left, right); - } + public static BigDecimal operator /(BigDecimal left, BigDecimal right) => Divide(left, right); /// /// Divides the specified dividend by the specified divisor and rounds the remainder using the specified rounding mode. diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Increment.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Increment.cs index e07be52..699f6c0 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Increment.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Increment.cs @@ -36,18 +36,12 @@ public static BigDecimal Increment(BigDecimal value) /// /// The value to increment. /// Returns a new value incremented by one fractional unit. - public static BigDecimal IncrementFraction(BigDecimal value) - { - return new BigDecimal(value.UnscaledValue + 1, value.Scale); - } + public static BigDecimal IncrementFraction(BigDecimal value) => new(value.UnscaledValue + 1, value.Scale); /// /// Increments the integral component of the specified value by one. /// /// The value to increment. /// Returns a new value incremented by one integral unit. - public static BigDecimal operator ++(BigDecimal value) - { - return Increment(value); - } + public static BigDecimal operator ++(BigDecimal value) => Increment(value); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Modulus.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Modulus.cs index 35d0d0b..df9c7da 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Modulus.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Modulus.cs @@ -40,8 +40,5 @@ public static BigDecimal Mod(BigDecimal left, BigDecimal right) /// The left-hand value to divide. /// The right-hand value to divide by. /// Returns the modulus of the specified values by dividing the left-hand value by the right-hand value. - public static BigDecimal operator %(BigDecimal left, BigDecimal right) - { - return Mod(left, right); - } + public static BigDecimal operator %(BigDecimal left, BigDecimal right) => Mod(left, right); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Multiplication.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Multiplication.cs index 4055dae..b40bab9 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Multiplication.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Multiplication.cs @@ -40,8 +40,5 @@ public static BigDecimal Multiply(BigDecimal left, BigDecimal right) /// The left-hand value to multiply by. /// The right-hand value to multiply. /// Returns the product of the specified values. - public static BigDecimal operator *(BigDecimal left, BigDecimal right) - { - return Multiply(left, right); - } + public static BigDecimal operator *(BigDecimal left, BigDecimal right) => Multiply(left, right); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Round.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Round.cs index 99de06b..bf6523c 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Round.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Round.cs @@ -47,10 +47,7 @@ public static BigDecimal Round(BigDecimal value, int scale = default, MidpointRo /// /// The value to be rounded up towards positive infinity. /// Returns the smallest integral value that is greater than or equal to the specified value. - public static BigDecimal Ceiling(BigDecimal value) - { - return Round(value, 0, MidpointRounding.ToPositiveInfinity); - } + public static BigDecimal Ceiling(BigDecimal value) => Round(value, 0, MidpointRounding.ToPositiveInfinity); /// /// Rounds the specified value down to the largest integral value less than or equal to the specified number. @@ -58,10 +55,7 @@ public static BigDecimal Ceiling(BigDecimal value) /// /// The value to be rounded down towards positive infinity. /// Returns the largest integral value that is less than or equal to the specified value. - public static BigDecimal Floor(BigDecimal value) - { - return Round(value, 0, MidpointRounding.ToNegativeInfinity); - } + public static BigDecimal Floor(BigDecimal value) => Round(value, 0, MidpointRounding.ToNegativeInfinity); /// /// Rounds the current value. @@ -71,28 +65,19 @@ public static BigDecimal Floor(BigDecimal value) /// Returns a value rounded to the specified number of fractional digits. /// If the specified scale is non-negative. /// If the specified rounding mode is invalid. - public BigDecimal Round(int scale = default, MidpointRounding mode = default) - { - return Round(this, scale, mode); - } + public BigDecimal Round(int scale = default, MidpointRounding mode = default) => Round(this, scale, mode); /// /// Rounds the current value up to the smallest integral value greater than or equal to the current number. /// This kind of rounding is sometimes called rounding towards positive infinity, following IEEE Standard 754, section 4. /// /// Returns the smallest integral value that is greater than or equal to the current value. - public BigDecimal Ceiling() - { - return Ceiling(this); - } + public BigDecimal Ceiling() => Ceiling(this); /// /// Rounds the current value down to the largest integral value less than or equal to the current number. /// This kind of rounding is sometimes called rounding towards negative infinity, following IEEE Standard 754, section 4. /// /// Returns the largest integral value that is less than or equal to the current value. - public BigDecimal Floor() - { - return Floor(this); - } + public BigDecimal Floor() => Floor(this); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Scale.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Scale.cs index 890e447..c9373c7 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Scale.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Scale.cs @@ -44,10 +44,7 @@ public static BigDecimal SetScale(BigDecimal value, int scale, MidpointRounding /// The scale to apply to the value. /// The mode to be used when the specified scale is less than the current scale. /// Returns a new value with the specified scale. - public BigDecimal SetScale(int scale, MidpointRounding mode = default) - { - return SetScale(this, scale, mode); - } + public BigDecimal SetScale(int scale, MidpointRounding mode = default) => SetScale(this, scale, mode); /// /// Normalizes the unscaled values of the specified values. diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Subtraction.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Subtraction.cs index 248ddab..029909b 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Subtraction.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Subtraction.cs @@ -43,8 +43,5 @@ public static BigDecimal Subtract(BigDecimal left, BigDecimal right) /// The left-hand value to subtract from. /// The right-hand value to subtract. /// Returns the difference between the specified values. - public static BigDecimal operator -(BigDecimal left, BigDecimal right) - { - return Subtract(left, right); - } + public static BigDecimal operator -(BigDecimal left, BigDecimal right) => Subtract(left, right); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Trim.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Trim.cs index dd8b681..eb005ab 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Trim.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Trim.cs @@ -36,8 +36,5 @@ public static BigDecimal TrimTrailingZeros(BigDecimal value) /// Trims any trailing zeros from the fractional part of the current value. /// /// Returns a new excluding any trailing zeros. - public BigDecimal TrimTrailingZeros() - { - return TrimTrailingZeros(this); - } + public BigDecimal TrimTrailingZeros() => TrimTrailingZeros(this); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.Truncate.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.Truncate.cs index 1b2bb23..8e2ee47 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.Truncate.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.Truncate.cs @@ -20,8 +20,5 @@ public readonly partial struct BigDecimal /// Truncates the fractional part of the specified value, leaving only the integral component. /// /// Returns the fractional part of the specified value, leaving only the integral component. - public static BigDecimal Truncate(BigDecimal value) - { - return value.number.Integer; - } + public static BigDecimal Truncate(BigDecimal value) => value.number.Integer; } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.UnaryAddition.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.UnaryAddition.cs index aa96e0d..43c1143 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.UnaryAddition.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.UnaryAddition.cs @@ -21,18 +21,12 @@ public readonly partial struct BigDecimal /// /// The value for which to perform unary addition. /// Returns the unary addition of the specified value. - public static BigDecimal UnaryAdd(BigDecimal value) - { - return value; - } + public static BigDecimal UnaryAdd(BigDecimal value) => value; /// /// Computes the unary addition of the specified value. /// /// The value for which to perform unary addition. /// Returns the unary addition of the specified value. - public static BigDecimal operator +(BigDecimal value) - { - return UnaryAdd(value); - } + public static BigDecimal operator +(BigDecimal value) => UnaryAdd(value); } diff --git a/OnixLabs.Numerics/BigDecimal.Arithmetic.UnarySubtraction.cs b/OnixLabs.Numerics/BigDecimal.Arithmetic.UnarySubtraction.cs index 6f31f2c..f5ff40a 100644 --- a/OnixLabs.Numerics/BigDecimal.Arithmetic.UnarySubtraction.cs +++ b/OnixLabs.Numerics/BigDecimal.Arithmetic.UnarySubtraction.cs @@ -21,18 +21,12 @@ public readonly partial struct BigDecimal /// /// The value for which to perform unary subtraction. /// Returns the unary subtraction of the specified value. - public static BigDecimal UnarySubtract(BigDecimal value) - { - return new BigDecimal(-value.UnscaledValue, value.Scale); - } + public static BigDecimal UnarySubtract(BigDecimal value) => new(-value.UnscaledValue, value.Scale); /// /// Computes the unary subtraction of the specified value. /// /// The value for which to perform unary subtraction. /// Returns the unary subtraction of the specified value. - public static BigDecimal operator -(BigDecimal value) - { - return UnarySubtract(value); - } + public static BigDecimal operator -(BigDecimal value) => UnarySubtract(value); } diff --git a/OnixLabs.Numerics/BigDecimal.Comparable.MinMax.cs b/OnixLabs.Numerics/BigDecimal.Comparable.MinMax.cs index b9c9238..c56df9d 100644 --- a/OnixLabs.Numerics/BigDecimal.Comparable.MinMax.cs +++ b/OnixLabs.Numerics/BigDecimal.Comparable.MinMax.cs @@ -24,10 +24,7 @@ public readonly partial struct BigDecimal /// The left value to compare. /// The right value to compare. /// Returns the lesser of the specified values. - public static BigDecimal Min(BigDecimal left, BigDecimal right) - { - return left < right ? left : right; - } + public static BigDecimal Min(BigDecimal left, BigDecimal right) => left < right ? left : right; /// /// Gets the greater of the specified values. @@ -35,10 +32,7 @@ public static BigDecimal Min(BigDecimal left, BigDecimal right) /// The left value to compare. /// The right value to compare. /// Returns the greater of the specified values. - public static BigDecimal Max(BigDecimal left, BigDecimal right) - { - return left > right ? left : right; - } + public static BigDecimal Max(BigDecimal left, BigDecimal right) => left > right ? left : right; /// /// Gets the lesser and the greater of the specified values. @@ -102,10 +96,7 @@ public static (BigDecimal MinMagnitude, BigDecimal MaxMagnitude) MinMaxMagnitude /// The left-hand value from which to obtain the minimum scale value. /// The left-hand value from which to obtain the minimum scale value. /// Returns the minimum scale of the specified left-hand and right-hand values. - public static int MinScale(BigDecimal left, BigDecimal right) - { - return int.Min(left.Scale, right.Scale); - } + public static int MinScale(BigDecimal left, BigDecimal right) => int.Min(left.Scale, right.Scale); /// /// Obtains the maximum scale of the specified left-hand and right-hand values. @@ -113,10 +104,7 @@ public static int MinScale(BigDecimal left, BigDecimal right) /// The left-hand value from which to obtain the maximum scale value. /// The left-hand value from which to obtain the maximum scale value. /// Returns the maximum scale of the specified left-hand and right-hand values. - public static int MaxScale(BigDecimal left, BigDecimal right) - { - return int.Max(left.Scale, right.Scale); - } + public static int MaxScale(BigDecimal left, BigDecimal right) => int.Max(left.Scale, right.Scale); /// /// Obtains the minimum and maximum scale of the specified left-hand and right-hand values. @@ -138,10 +126,7 @@ public static (int Min, int Max) MinMaxScale(BigDecimal left, BigDecimal right) /// The left value to compare. /// The right value to compare. /// Returns the lesser of the specified values. - static BigDecimal INumberBase.MinMagnitudeNumber(BigDecimal x, BigDecimal y) - { - return MinMagnitude(x, y); - } + static BigDecimal INumberBase.MinMagnitudeNumber(BigDecimal x, BigDecimal y) => MinMagnitude(x, y); /// /// Gets the greater of the specified values. @@ -149,8 +134,5 @@ static BigDecimal INumberBase.MinMagnitudeNumber(BigDecimal x, BigDe /// The left value to compare. /// The right value to compare. /// Returns the greater of the specified values. - static BigDecimal INumberBase.MaxMagnitudeNumber(BigDecimal x, BigDecimal y) - { - return MaxMagnitude(x, y); - } + static BigDecimal INumberBase.MaxMagnitudeNumber(BigDecimal x, BigDecimal y) => MaxMagnitude(x, y); } diff --git a/OnixLabs.Numerics/BigDecimal.Comparable.cs b/OnixLabs.Numerics/BigDecimal.Comparable.cs index c566ca8..81ec318 100644 --- a/OnixLabs.Numerics/BigDecimal.Comparable.cs +++ b/OnixLabs.Numerics/BigDecimal.Comparable.cs @@ -23,10 +23,7 @@ public readonly partial struct BigDecimal /// The left-hand value to compare. /// The right-hand value to compare. /// Returns a value that indicates the relative order of the objects being compared. - public static int Compare(BigDecimal left, BigDecimal right) - { - return BigDecimalOrdinalityComparer.Default.Compare(left, right); - } + public static int Compare(BigDecimal left, BigDecimal right) => BigDecimalOrdinalityComparer.Default.Compare(left, right); /// /// Compares the current instance with another object of the same type and returns an integer that indicates @@ -35,10 +32,7 @@ public static int Compare(BigDecimal left, BigDecimal right) /// /// An object to compare with this instance. /// Returns a value that indicates the relative order of the objects being compared. - public int CompareTo(object? obj) - { - return BigDecimalOrdinalityComparer.Default.Compare(this, obj); - } + public int CompareTo(object? obj) => BigDecimalOrdinalityComparer.Default.Compare(this, obj); /// /// Compares the current instance with another object of the same type and returns an integer that indicates @@ -47,10 +41,7 @@ public int CompareTo(object? obj) /// /// An object to compare with this instance. /// Returns a value that indicates the relative order of the objects being compared. - public int CompareTo(BigDecimal other) - { - return Compare(this, other); - } + public int CompareTo(BigDecimal other) => Compare(this, other); /// /// Determines whether the left-hand value is greater than the right-hand value. @@ -58,10 +49,7 @@ public int CompareTo(BigDecimal other) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is greater than right-hand operand; otherwise, . - public static bool operator >(BigDecimal left, BigDecimal right) - { - return BigDecimalOrdinalityComparer.Default.IsGreaterThan(left, right); - } + public static bool operator >(BigDecimal left, BigDecimal right) => BigDecimalOrdinalityComparer.Default.IsGreaterThan(left, right); /// /// Determines whether the left-hand value is greater than or equal to the right-hand value. @@ -69,10 +57,7 @@ public int CompareTo(BigDecimal other) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is greater than or equal to the right-hand operand; otherwise, . - public static bool operator >=(BigDecimal left, BigDecimal right) - { - return BigDecimalOrdinalityComparer.Default.IsGreaterThanOrEqual(left, right); - } + public static bool operator >=(BigDecimal left, BigDecimal right) => BigDecimalOrdinalityComparer.Default.IsGreaterThanOrEqual(left, right); /// /// Determines whether the left-hand value is less than right-hand value. @@ -80,10 +65,7 @@ public int CompareTo(BigDecimal other) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is less than the right-hand operand; otherwise, . - public static bool operator <(BigDecimal left, BigDecimal right) - { - return BigDecimalOrdinalityComparer.Default.IsLessThan(left, right); - } + public static bool operator <(BigDecimal left, BigDecimal right) => BigDecimalOrdinalityComparer.Default.IsLessThan(left, right); /// /// Determines whether the left-hand value is less than or equal to the right-hand value. @@ -91,8 +73,5 @@ public int CompareTo(BigDecimal other) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is less than or equal to the right-hand operand; otherwise, . - public static bool operator <=(BigDecimal left, BigDecimal right) - { - return BigDecimalOrdinalityComparer.Default.IsLessThanOrEqual(left, right); - } + public static bool operator <=(BigDecimal left, BigDecimal right) => BigDecimalOrdinalityComparer.Default.IsLessThanOrEqual(left, right); } diff --git a/OnixLabs.Numerics/BigDecimal.Convert.cs b/OnixLabs.Numerics/BigDecimal.Convert.cs index 88b5046..16d2e22 100644 --- a/OnixLabs.Numerics/BigDecimal.Convert.cs +++ b/OnixLabs.Numerics/BigDecimal.Convert.cs @@ -20,35 +20,12 @@ namespace OnixLabs.Numerics; public readonly partial struct BigDecimal { - static bool INumberBase.TryConvertFromChecked(TOther value, out BigDecimal result) - { - return TryConvertFrom(value, out result); - } - - static bool INumberBase.TryConvertFromSaturating(TOther value, out BigDecimal result) - { - return TryConvertFrom(value, out result); - } - - static bool INumberBase.TryConvertFromTruncating(TOther value, out BigDecimal result) - { - return TryConvertFrom(value, out result); - } - - static bool INumberBase.TryConvertToChecked(BigDecimal value, [MaybeNullWhen(false)] out TOther result) - { - return TryConvertTo(value, out result); - } - - static bool INumberBase.TryConvertToSaturating(BigDecimal value, [MaybeNullWhen(false)] out TOther result) - { - return TryConvertTo(value, out result); - } - - static bool INumberBase.TryConvertToTruncating(BigDecimal value, [MaybeNullWhen(false)] out TOther result) - { - return TryConvertTo(value, out result); - } + static bool INumberBase.TryConvertFromChecked(TOther value, out BigDecimal result) => TryConvertFrom(value, out result); + static bool INumberBase.TryConvertFromSaturating(TOther value, out BigDecimal result) => TryConvertFrom(value, out result); + static bool INumberBase.TryConvertFromTruncating(TOther value, out BigDecimal result) => TryConvertFrom(value, out result); + static bool INumberBase.TryConvertToChecked(BigDecimal value, [MaybeNullWhen(false)] out TOther result) => TryConvertTo(value, out result); + static bool INumberBase.TryConvertToSaturating(BigDecimal value, [MaybeNullWhen(false)] out TOther result) => TryConvertTo(value, out result); + static bool INumberBase.TryConvertToTruncating(BigDecimal value, [MaybeNullWhen(false)] out TOther result) => TryConvertTo(value, out result); private static bool TryConvertFrom(TOther value, out BigDecimal result) where TOther : INumberBase { diff --git a/OnixLabs.Numerics/BigDecimal.Convertible.Explicit.cs b/OnixLabs.Numerics/BigDecimal.Convertible.Explicit.cs index 8ff95cd..fbd7fe3 100644 --- a/OnixLabs.Numerics/BigDecimal.Convertible.Explicit.cs +++ b/OnixLabs.Numerics/BigDecimal.Convertible.Explicit.cs @@ -24,10 +24,7 @@ public readonly partial struct BigDecimal /// /// The value to convert. /// Returns a value representing the integral value of the specified value. - public static explicit operator BigInteger(BigDecimal value) - { - return value.number.Integer; - } + public static explicit operator BigInteger(BigDecimal value) => value.number.Integer; /// /// Converts the integral value of the specified value to a value. diff --git a/OnixLabs.Numerics/BigDecimal.Convertible.Implicit.cs b/OnixLabs.Numerics/BigDecimal.Convertible.Implicit.cs index b9d0857..52b3c01 100644 --- a/OnixLabs.Numerics/BigDecimal.Convertible.Implicit.cs +++ b/OnixLabs.Numerics/BigDecimal.Convertible.Implicit.cs @@ -24,138 +24,96 @@ public readonly partial struct BigDecimal /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(BigInteger value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(BigInteger value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(sbyte value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(sbyte value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(byte value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(byte value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(short value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(short value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(ushort value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(ushort value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(int value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(int value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(uint value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(uint value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(long value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(long value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(ulong value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(ulong value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(Int128 value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(Int128 value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(UInt128 value) - { - return new BigDecimal(value, default, ScaleMode.Integral); - } + public static implicit operator BigDecimal(UInt128 value) => new(value, default, ScaleMode.Integral); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(float value) - { - return new BigDecimal(value); - } + public static implicit operator BigDecimal(float value) => new(value); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(double value) - { - return new BigDecimal(value); - } + public static implicit operator BigDecimal(double value) => new(value); /// /// Converts the specified value to a value. /// /// The value to convert. /// Returns a value representing the specified value. - public static implicit operator BigDecimal(decimal value) - { - return new BigDecimal(value); - } + public static implicit operator BigDecimal(decimal value) => new(value); } diff --git a/OnixLabs.Numerics/BigDecimal.Convertible.cs b/OnixLabs.Numerics/BigDecimal.Convertible.cs index c7bef84..a79a537 100644 --- a/OnixLabs.Numerics/BigDecimal.Convertible.cs +++ b/OnixLabs.Numerics/BigDecimal.Convertible.cs @@ -22,160 +22,112 @@ public readonly partial struct BigDecimal /// Gets the for the current instance. /// /// Returns the enumerated constant that is the of the class or value type that implements this interface. - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } + TypeCode IConvertible.GetTypeCode() => TypeCode.Object; /// /// Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns an 8-bit signed integer equivalent to the value of this instance. - sbyte IConvertible.ToSByte(IFormatProvider? provider) - { - return (sbyte)this; - } + sbyte IConvertible.ToSByte(IFormatProvider? provider) => (sbyte)this; /// /// Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns an 8-bit unsigned integer equivalent to the value of this instance. - byte IConvertible.ToByte(IFormatProvider? provider) - { - return (byte)this; - } + byte IConvertible.ToByte(IFormatProvider? provider) => (byte)this; /// /// Converts the value of this instance to an equivalent 16-bit signed integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a 16-bit signed integer equivalent to the value of this instance. - short IConvertible.ToInt16(IFormatProvider? provider) - { - return (short)this; - } + short IConvertible.ToInt16(IFormatProvider? provider) => (short)this; /// /// Converts the value of this instance to an equivalent 32-bit signed integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a 32-bit signed integer equivalent to the value of this instance. - int IConvertible.ToInt32(IFormatProvider? provider) - { - return (int)this; - } + int IConvertible.ToInt32(IFormatProvider? provider) => (int)this; /// /// Converts the value of this instance to an equivalent 64-bit signed integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a 64-bit signed integer equivalent to the value of this instance. - long IConvertible.ToInt64(IFormatProvider? provider) - { - return (long)this; - } + long IConvertible.ToInt64(IFormatProvider? provider) => (long)this; /// /// Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a 16-bit unsigned integer equivalent to the value of this instance. - ushort IConvertible.ToUInt16(IFormatProvider? provider) - { - return (ushort)this; - } + ushort IConvertible.ToUInt16(IFormatProvider? provider) => (ushort)this; /// /// Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a 32-bit unsigned integer equivalent to the value of this instance. - uint IConvertible.ToUInt32(IFormatProvider? provider) - { - return (uint)this; - } + uint IConvertible.ToUInt32(IFormatProvider? provider) => (uint)this; /// /// Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a 64-bit unsigned integer equivalent to the value of this instance. - ulong IConvertible.ToUInt64(IFormatProvider? provider) - { - return (ulong)this; - } + ulong IConvertible.ToUInt64(IFormatProvider? provider) => (ulong)this; /// /// Converts the value of this instance to an equivalent single-precision floating-point number using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a single-precision floating-point number equivalent to the value of this instance. - float IConvertible.ToSingle(IFormatProvider? provider) - { - return (float)this; - } + float IConvertible.ToSingle(IFormatProvider? provider) => (float)this; /// /// Converts the value of this instance to an equivalent double-precision floating-point number using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a double-precision floating-point number equivalent to the value of this instance. - double IConvertible.ToDouble(IFormatProvider? provider) - { - return (double)this; - } + double IConvertible.ToDouble(IFormatProvider? provider) => (double)this; /// /// Converts the value of this instance to an equivalent number using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a number equivalent to the value of this instance. - decimal IConvertible.ToDecimal(IFormatProvider? provider) - { - return (decimal)this; - } + decimal IConvertible.ToDecimal(IFormatProvider? provider) => (decimal)this; /// /// Converts the value of this instance to an equivalent using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a instance equivalent to the value of this instance. - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - return DateTime.FromBinary((long)UnscaledValue); - } + DateTime IConvertible.ToDateTime(IFormatProvider? provider) => DateTime.FromBinary((long)UnscaledValue); /// /// Converts the value of this instance to an equivalent value using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a value equivalent to the value of this instance. - bool IConvertible.ToBoolean(IFormatProvider? provider) - { - return !IsZero(this); - } + bool IConvertible.ToBoolean(IFormatProvider? provider) => !IsZero(this); /// /// Converts the value of this instance to an equivalent Unicode character using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a Unicode character equivalent to the value of this instance. - char IConvertible.ToChar(IFormatProvider? provider) - { - return (char)this; - } + char IConvertible.ToChar(IFormatProvider? provider) => (char)this; /// /// Converts the value of this instance to an equivalent using the specified culture-specific formatting information. /// /// An interface implementation that supplies culture-specific formatting information. /// Returns a instance equivalent to the value of this instance. - string IConvertible.ToString(IFormatProvider? provider) - { - return ToString(DefaultNumberFormat, provider); - } + string IConvertible.ToString(IFormatProvider? provider) => ToString(DefaultNumberFormat, provider); /// /// Converts the value of this instance to an of the specified that has an equivalent value, using the specified culture-specific formatting information. @@ -183,8 +135,5 @@ string IConvertible.ToString(IFormatProvider? provider) /// The to which the value of this instance is converted /// An interface implementation that supplies culture-specific formatting information. /// Returns an instance of type conversionType whose value is equivalent to the value of this instance. - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - return Convert.ChangeType(this, conversionType, provider); - } + object IConvertible.ToType(Type conversionType, IFormatProvider? provider) => Convert.ChangeType(this, conversionType, provider); } diff --git a/OnixLabs.Numerics/BigDecimal.Equatable.cs b/OnixLabs.Numerics/BigDecimal.Equatable.cs index 72ec86c..45d7389 100644 --- a/OnixLabs.Numerics/BigDecimal.Equatable.cs +++ b/OnixLabs.Numerics/BigDecimal.Equatable.cs @@ -23,10 +23,7 @@ public readonly partial struct BigDecimal /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the two specified instances are equal; otherwise, . - public static bool Equals(BigDecimal left, BigDecimal right) - { - return Equals(left, right, BigDecimalEqualityComparer.Strict); - } + public static bool Equals(BigDecimal left, BigDecimal right) => Equals(left, right, BigDecimalEqualityComparer.Strict); /// /// Compares two instances of to determine whether their values are equal. @@ -35,10 +32,7 @@ public static bool Equals(BigDecimal left, BigDecimal right) /// The right-hand value to compare. /// The equality comparer to use to determine equality. /// Returns if the two specified instances are equal; otherwise, . - public static bool Equals(BigDecimal left, BigDecimal right, BigDecimalEqualityComparer comparer) - { - return comparer.Equals(left, right); - } + public static bool Equals(BigDecimal left, BigDecimal right, BigDecimalEqualityComparer comparer) => comparer.Equals(left, right); /// /// Compares the current instance of with the specified other instance of . @@ -46,10 +40,7 @@ public static bool Equals(BigDecimal left, BigDecimal right, BigDecimalEqualityC /// /// The other instance of to compare with the current instance. /// Returns if the current instance is equal to the specified other instance; otherwise, . - public bool Equals(BigDecimal other) - { - return Equals(this, other); - } + public bool Equals(BigDecimal other) => Equals(this, other); /// /// Compares the current instance of with the specified other instance of . @@ -57,10 +48,7 @@ public bool Equals(BigDecimal other) /// The other instance of to compare with the current instance. /// The equality comparer to use to determine equality. /// Returns if the current instance is equal to the specified other instance; otherwise, . - public bool Equals(BigDecimal other, BigDecimalEqualityComparer comparer) - { - return Equals(this, other, comparer); - } + public bool Equals(BigDecimal other, BigDecimalEqualityComparer comparer) => Equals(this, other, comparer); /// /// Checks for equality between this instance and another object. @@ -68,10 +56,7 @@ public bool Equals(BigDecimal other, BigDecimalEqualityComparer comparer) /// /// The object to check for equality. /// Returns if the object is equal to this instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is BigDecimal other && Equals(other); - } + public override bool Equals(object? obj) => obj is BigDecimal other && Equals(other); /// /// Checks for equality between this instance and another object. @@ -79,20 +64,14 @@ public override bool Equals(object? obj) /// The object to check for equality. /// The equality comparer to use to determine equality. /// Returns if the object is equal to this instance; otherwise, . - public bool Equals(object? obj, BigDecimalEqualityComparer comparer) - { - return obj is BigDecimal other && Equals(other, comparer); - } + public bool Equals(object? obj, BigDecimalEqualityComparer comparer) => obj is BigDecimal other && Equals(other, comparer); /// /// Serves as a hash code function for this instance. /// This method implements the comparer. /// /// A hash code for this instance. - public override int GetHashCode() - { - return BigDecimalEqualityComparer.Strict.GetHashCode(this); - } + public override int GetHashCode() => BigDecimalEqualityComparer.Strict.GetHashCode(this); /// /// Compares two instances of to determine whether their values are equal. @@ -101,10 +80,7 @@ public override int GetHashCode() /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the two specified instances are equal; otherwise, . - public static bool operator ==(BigDecimal left, BigDecimal right) - { - return Equals(left, right, BigDecimalEqualityComparer.Semantic); - } + public static bool operator ==(BigDecimal left, BigDecimal right) => Equals(left, right, BigDecimalEqualityComparer.Semantic); /// /// Compares two instances of to determine whether their values are not equal. @@ -113,8 +89,5 @@ public override int GetHashCode() /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the two specified instances are not equal; otherwise, . - public static bool operator !=(BigDecimal left, BigDecimal right) - { - return Equals(left, right, BigDecimalEqualityComparer.Semantic); - } + public static bool operator !=(BigDecimal left, BigDecimal right) => !Equals(left, right, BigDecimalEqualityComparer.Semantic); } diff --git a/OnixLabs.Numerics/BigDecimal.Get.cs b/OnixLabs.Numerics/BigDecimal.Get.cs index ed81ddb..fff3174 100644 --- a/OnixLabs.Numerics/BigDecimal.Get.cs +++ b/OnixLabs.Numerics/BigDecimal.Get.cs @@ -18,23 +18,8 @@ namespace OnixLabs.Numerics; public readonly partial struct BigDecimal { - int IFloatingPoint.GetExponentByteCount() - { - return sizeof(int); - } - - int IFloatingPoint.GetExponentShortestBitLength() - { - return sizeof(int) - int.LeadingZeroCount(number.Exponent); - } - - int IFloatingPoint.GetSignificandBitLength() - { - return number.Significand.ToByteArray().Length * 8; - } - - int IFloatingPoint.GetSignificandByteCount() - { - return number.Significand.ToByteArray().Length; - } + int IFloatingPoint.GetExponentByteCount() => sizeof(int); + int IFloatingPoint.GetExponentShortestBitLength() => sizeof(int) - int.LeadingZeroCount(number.Exponent); + int IFloatingPoint.GetSignificandBitLength() => number.Significand.ToByteArray().Length * 8; + int IFloatingPoint.GetSignificandByteCount() => number.Significand.ToByteArray().Length; } diff --git a/OnixLabs.Numerics/BigDecimal.Is.cs b/OnixLabs.Numerics/BigDecimal.Is.cs index 4a4631a..5de1a19 100644 --- a/OnixLabs.Numerics/BigDecimal.Is.cs +++ b/OnixLabs.Numerics/BigDecimal.Is.cs @@ -23,168 +23,117 @@ public readonly partial struct BigDecimal /// /// The value to be checked. /// Returns if the value is an integer; otherwise, . - public static bool IsInteger(BigDecimal value) - { - return value.number.Fraction == BigInteger.Zero; - } + public static bool IsInteger(BigDecimal value) => value.number.Fraction == BigInteger.Zero; /// /// Determines if a value represents an even integral number. /// /// The value to be checked. /// Returns if the value is an even integer; otherwise, . - public static bool IsEvenInteger(BigDecimal value) - { - return IsInteger(value) && BigInteger.IsEvenInteger(value.number.Integer); - } + public static bool IsEvenInteger(BigDecimal value) => IsInteger(value) && BigInteger.IsEvenInteger(value.number.Integer); /// /// Determines if a value represents an odd integral number. /// /// The value to be checked. /// Returns if the value is an odd integer; otherwise, . - public static bool IsOddInteger(BigDecimal value) - { - return IsInteger(value) && BigInteger.IsOddInteger(value.number.Integer); - } + public static bool IsOddInteger(BigDecimal value) => IsInteger(value) && BigInteger.IsOddInteger(value.number.Integer); /// /// Determines if a value is negative. /// /// The value to be checked. /// Returns if the value is negative; otherwise, . - public static bool IsNegative(BigDecimal value) - { - return BigInteger.IsNegative(value.UnscaledValue); - } + public static bool IsNegative(BigDecimal value) => BigInteger.IsNegative(value.UnscaledValue); /// /// Determines if a value is positive. /// /// The value to be checked. /// Returns if the value is positive; otherwise, . - public static bool IsPositive(BigDecimal value) - { - return BigInteger.IsPositive(value.UnscaledValue); - } + public static bool IsPositive(BigDecimal value) => BigInteger.IsPositive(value.UnscaledValue); /// /// Determines if a value is zero. /// /// The value to be checked. /// Returns if the value is zero; otherwise, . - public static bool IsZero(BigDecimal value) - { - return value.UnscaledValue == BigInteger.Zero; - } + public static bool IsZero(BigDecimal value) => value.UnscaledValue == BigInteger.Zero; /// /// Determines if a value is in its canonical representation. /// /// The value to be checked. /// Returns if value is in its canonical representation; otherwise, . - static bool INumberBase.IsCanonical(BigDecimal value) - { - return true; - } + static bool INumberBase.IsCanonical(BigDecimal value) => true; /// /// Determines if a value represents a complex number. /// /// The value to be checked. /// Returns if value is a complex number; otherwise, . - static bool INumberBase.IsComplexNumber(BigDecimal value) - { - return false; - } + static bool INumberBase.IsComplexNumber(BigDecimal value) => false; /// /// Determines if a value is finite. /// /// The value to be checked. /// Returns if value is finite; otherwise, . - static bool INumberBase.IsFinite(BigDecimal value) - { - return true; - } + static bool INumberBase.IsFinite(BigDecimal value) => true; /// /// Determines if a value represents a pure imaginary number. /// /// The value to be checked. /// Returns if value is a pure imaginary number; otherwise, . - static bool INumberBase.IsImaginaryNumber(BigDecimal value) - { - return false; - } + static bool INumberBase.IsImaginaryNumber(BigDecimal value) => false; /// /// Determines if a value is infinite. /// /// The value to be checked. /// Returns if value is infinite; otherwise, . - static bool INumberBase.IsInfinity(BigDecimal value) - { - return false; - } + static bool INumberBase.IsInfinity(BigDecimal value) => false; /// /// Determines if a value is NaN. /// /// The value to be checked. /// Returns if value is NaN; otherwise, . - static bool INumberBase.IsNaN(BigDecimal value) - { - return false; - } + static bool INumberBase.IsNaN(BigDecimal value) => false; /// /// Determines if a value is negative infinity. /// /// The value to be checked. /// Returns if value is negative infinity; otherwise, . - static bool INumberBase.IsNegativeInfinity(BigDecimal value) - { - return false; - } + static bool INumberBase.IsNegativeInfinity(BigDecimal value) => false; /// /// Determines if a value is normal. /// /// The value to be checked. /// Returns if value is normal; otherwise, . - static bool INumberBase.IsNormal(BigDecimal value) - { - return true; - } + static bool INumberBase.IsNormal(BigDecimal value) => true; /// /// Determines if a value is positive infinity. /// /// The value to be checked. /// Returns if value is positive infinity; otherwise, . - static bool INumberBase.IsPositiveInfinity(BigDecimal value) - { - return false; - } + static bool INumberBase.IsPositiveInfinity(BigDecimal value) => false; /// /// Determines if a value represents a real number. /// /// The value to be checked. /// Returns if value is a real number; otherwise, - static bool INumberBase.IsRealNumber(BigDecimal value) - { - return true; - } + static bool INumberBase.IsRealNumber(BigDecimal value) => true; /// /// Determines if a value is subnormal. /// /// The value to be checked. /// Returns if value is subnormal; otherwise, . - static bool INumberBase.IsSubnormal(BigDecimal value) - { - return false; - } + static bool INumberBase.IsSubnormal(BigDecimal value) => false; } diff --git a/OnixLabs.Numerics/BigDecimal.Parse.cs b/OnixLabs.Numerics/BigDecimal.Parse.cs index 5219347..3cae2c5 100644 --- a/OnixLabs.Numerics/BigDecimal.Parse.cs +++ b/OnixLabs.Numerics/BigDecimal.Parse.cs @@ -25,10 +25,7 @@ public readonly partial struct BigDecimal /// The value to parse. /// An object that provides culture-specific information about the specified value. /// Returns a new instance parsed from the specified value. - public static BigDecimal Parse(string value, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), provider); - } + public static BigDecimal Parse(string value, IFormatProvider? provider = null) => Parse(value.AsSpan(), provider); /// /// Parses the specified value into a value. @@ -37,10 +34,7 @@ public static BigDecimal Parse(string value, IFormatProvider? provider = null) /// A bitwise combination of number styles that can be present in the specified value. /// An object that provides culture-specific information about the specified value. /// Returns a new instance parsed from the specified value. - public static BigDecimal Parse(string value, NumberStyles style, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), style, provider); - } + public static BigDecimal Parse(string value, NumberStyles style, IFormatProvider? provider = null) => Parse(value.AsSpan(), style, provider); /// /// Parses the specified value into a value. @@ -48,10 +42,7 @@ public static BigDecimal Parse(string value, NumberStyles style, IFormatProvider /// The value to parse. /// An object that provides culture-specific information about the specified value. /// Returns a new instance parsed from the specified value. - public static BigDecimal Parse(ReadOnlySpan value, IFormatProvider? provider = null) - { - return Parse(value, DefaultNumberStyles, provider); - } + public static BigDecimal Parse(ReadOnlySpan value, IFormatProvider? provider = null) => Parse(value, DefaultNumberStyles, provider); /// /// Parses the specified value into a value. @@ -76,10 +67,7 @@ public static BigDecimal Parse(ReadOnlySpan value, NumberStyles style, IFo /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(string? value, out BigDecimal result) - { - return TryParse(value.AsSpan(), out result); - } + public static bool TryParse(string? value, out BigDecimal result) => TryParse(value.AsSpan(), out result); /// /// Tries to parse the specified value into a value. @@ -91,10 +79,7 @@ public static bool TryParse(string? value, out BigDecimal result) /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(string? value, IFormatProvider? provider, out BigDecimal result) - { - return TryParse(value.AsSpan(), provider, out result); - } + public static bool TryParse(string? value, IFormatProvider? provider, out BigDecimal result) => TryParse(value.AsSpan(), provider, out result); /// /// Tries to parse the specified value into a value. @@ -107,10 +92,7 @@ public static bool TryParse(string? value, IFormatProvider? provider, out BigDec /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(string? value, NumberStyles style, IFormatProvider? provider, out BigDecimal result) - { - return TryParse(value.AsSpan(), style, provider, out result); - } + public static bool TryParse(string? value, NumberStyles style, IFormatProvider? provider, out BigDecimal result) => TryParse(value.AsSpan(), style, provider, out result); /// /// Tries to parse the specified value into a value. @@ -121,10 +103,7 @@ public static bool TryParse(string? value, NumberStyles style, IFormatProvider? /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(ReadOnlySpan value, out BigDecimal result) - { - return TryParse(value, DefaultCulture, out result); - } + public static bool TryParse(ReadOnlySpan value, out BigDecimal result) => TryParse(value, DefaultCulture, out result); /// /// Tries to parse the specified value into a value. @@ -136,10 +115,7 @@ public static bool TryParse(ReadOnlySpan value, out BigDecimal result) /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(ReadOnlySpan value, IFormatProvider? provider, out BigDecimal result) - { - return TryParse(value, DefaultNumberStyles, provider, out result); - } + public static bool TryParse(ReadOnlySpan value, IFormatProvider? provider, out BigDecimal result) => TryParse(value, DefaultNumberStyles, provider, out result); /// /// Tries to parse the specified value into a value. diff --git a/OnixLabs.Numerics/BigDecimal.To.cs b/OnixLabs.Numerics/BigDecimal.To.cs index a8a4aab..3639b0f 100644 --- a/OnixLabs.Numerics/BigDecimal.To.cs +++ b/OnixLabs.Numerics/BigDecimal.To.cs @@ -23,19 +23,13 @@ public readonly partial struct BigDecimal /// Gets a representing the current . /// /// Returns a representing the current . - public NumberInfo ToNumberInfo() - { - return number; - } + public NumberInfo ToNumberInfo() => number; /// /// Formats the value of the current instance using the default format. /// /// The value of the current instance in the default format. - public override string ToString() - { - return ToString(DefaultNumberFormat, DefaultCulture); - } + public override string ToString() => ToString(DefaultNumberFormat, DefaultCulture); /// /// Formats the value of the current instance using the specified format. @@ -43,10 +37,7 @@ public override string ToString() /// The format to use, or null to use the default format. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(string? format, IFormatProvider? formatProvider = null) - { - return ToString((format ?? DefaultNumberFormat).AsSpan(), formatProvider); - } + public string ToString(string? format, IFormatProvider? formatProvider = null) => ToString((format ?? DefaultNumberFormat).AsSpan(), formatProvider); /// /// Formats the value of the current instance using the specified format. diff --git a/OnixLabs.Numerics/BigDecimal.Write.cs b/OnixLabs.Numerics/BigDecimal.Write.cs index 3a1d89b..bd9730b 100644 --- a/OnixLabs.Numerics/BigDecimal.Write.cs +++ b/OnixLabs.Numerics/BigDecimal.Write.cs @@ -60,17 +60,13 @@ bool IFloatingPoint.TryWriteExponentLittleEndian(Span destinat /// The span to which the current significand should be written. /// When this method returns, contains the number of bytes written to . /// Returns if the significand was successfully written to ; otherwise, . - bool IFloatingPoint.TryWriteSignificandBigEndian(Span destination, out int bytesWritten) - { - return number.Significand.TryWriteBytes(destination, out bytesWritten, isBigEndian: true); - } + bool IFloatingPoint.TryWriteSignificandBigEndian(Span destination, out int bytesWritten) => + number.Significand.TryWriteBytes(destination, out bytesWritten, isBigEndian: true); /// Tries to write the current significand, in little-endian format, to a given span. /// The span to which the current significand should be written. /// When this method returns, contains the number of bytes written to . /// Returns if the significand was successfully written to ; otherwise, . - bool IFloatingPoint.TryWriteSignificandLittleEndian(Span destination, out int bytesWritten) - { - return number.Significand.TryWriteBytes(destination, out bytesWritten); - } + bool IFloatingPoint.TryWriteSignificandLittleEndian(Span destination, out int bytesWritten) => + number.Significand.TryWriteBytes(destination, out bytesWritten); } diff --git a/OnixLabs.Numerics/BigDecimal.cs b/OnixLabs.Numerics/BigDecimal.cs index 2de9c4d..7671ae1 100644 --- a/OnixLabs.Numerics/BigDecimal.cs +++ b/OnixLabs.Numerics/BigDecimal.cs @@ -67,10 +67,7 @@ public BigDecimal(double value, ConversionMode mode = default) /// Initializes a new instance of the struct. /// /// The decimal value from which to construct a value. - public BigDecimal(decimal value) - { - number = value.ToNumberInfo(); - } + public BigDecimal(decimal value) => number = value.ToNumberInfo(); /// /// Gets the unscaled value of the current value. diff --git a/OnixLabs.Numerics/BigDecimalEqualityComparer.cs b/OnixLabs.Numerics/BigDecimalEqualityComparer.cs index ac29578..c97f013 100644 --- a/OnixLabs.Numerics/BigDecimalEqualityComparer.cs +++ b/OnixLabs.Numerics/BigDecimalEqualityComparer.cs @@ -54,18 +54,12 @@ private BigDecimalEqualityComparer() /// The first object to compare. /// The second object to compare. /// Returns if the specified objects are both of type and are equal; otherwise, . - public new bool Equals(object? x, object? y) - { - return x is BigDecimal left && y is BigDecimal right && Equals(left, right); - } + public new bool Equals(object? x, object? y) => x is BigDecimal left && y is BigDecimal right && Equals(left, right); /// Returns a hash code for the specified object. /// The for which a hash code is to be returned. /// A hash code for the specified object. - public int GetHashCode(object obj) - { - return obj is BigDecimal value ? GetHashCode(value) : obj.GetHashCode(); - } + public int GetHashCode(object obj) => obj is BigDecimal value ? GetHashCode(value) : obj.GetHashCode(); /// /// Represents an equality comparer that compares values using strict equality. @@ -77,18 +71,12 @@ private sealed class BigDecimalStrictEqualityComparer : BigDecimalEqualityCompar /// The first object of type to compare. /// The second object of type to compare. /// Returns if the specified values are equal; otherwise, . - public override bool Equals(BigDecimal x, BigDecimal y) - { - return NumberInfoEqualityComparer.Strict.Equals(x.ToNumberInfo(), y.ToNumberInfo()); - } + public override bool Equals(BigDecimal x, BigDecimal y) => NumberInfoEqualityComparer.Strict.Equals(x.ToNumberInfo(), y.ToNumberInfo()); /// Returns a hash code for the specified object. /// The for which a hash code is to be returned. /// A hash code for the specified object. - public override int GetHashCode(BigDecimal obj) - { - return NumberInfoEqualityComparer.Strict.GetHashCode(obj.ToNumberInfo()); - } + public override int GetHashCode(BigDecimal obj) => NumberInfoEqualityComparer.Strict.GetHashCode(obj.ToNumberInfo()); } /// @@ -101,17 +89,11 @@ private sealed class BigDecimalSemanticEqualityComparer : BigDecimalEqualityComp /// The first object of type to compare. /// The second object of type to compare. /// Returns if the specified values are equal; otherwise, . - public override bool Equals(BigDecimal x, BigDecimal y) - { - return NumberInfoEqualityComparer.Semantic.Equals(x.ToNumberInfo(), y.ToNumberInfo()); - } + public override bool Equals(BigDecimal x, BigDecimal y) => NumberInfoEqualityComparer.Semantic.Equals(x.ToNumberInfo(), y.ToNumberInfo()); /// Returns a hash code for the specified object. /// The for which a hash code is to be returned. /// A hash code for the specified object. - public override int GetHashCode(BigDecimal obj) - { - return NumberInfoEqualityComparer.Semantic.GetHashCode(obj.ToNumberInfo()); - } + public override int GetHashCode(BigDecimal obj) => NumberInfoEqualityComparer.Semantic.GetHashCode(obj.ToNumberInfo()); } } diff --git a/OnixLabs.Numerics/BigDecimalOrdinalityComparer.cs b/OnixLabs.Numerics/BigDecimalOrdinalityComparer.cs index b3e67ce..9546a2d 100644 --- a/OnixLabs.Numerics/BigDecimalOrdinalityComparer.cs +++ b/OnixLabs.Numerics/BigDecimalOrdinalityComparer.cs @@ -39,10 +39,7 @@ private BigDecimalOrdinalityComparer() /// The first value to compare. /// The second value to compare. /// Returns a signed integer that indicates the relative order of the values being compared. - public int Compare(BigDecimal x, BigDecimal y) - { - return NumberInfoOrdinalityComparer.Default.Compare(x.ToNumberInfo(), y.ToNumberInfo()); - } + public int Compare(BigDecimal x, BigDecimal y) => NumberInfoOrdinalityComparer.Default.Compare(x.ToNumberInfo(), y.ToNumberInfo()); /// Compares two values and returns a value indicating whether one is less than, equal to, or greater than the other. /// The first value to compare. @@ -63,10 +60,7 @@ public int Compare(object? x, object? y) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is equal to the right-hand value; otherwise, . - public bool IsEqual(BigDecimal left, BigDecimal right) - { - return Compare(left, right) is 0; - } + public bool IsEqual(BigDecimal left, BigDecimal right) => Compare(left, right) is 0; /// /// Determines whether the left-hand value is greater than the right-hand value. @@ -74,10 +68,7 @@ public bool IsEqual(BigDecimal left, BigDecimal right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is greater than the right-hand value; otherwise, . - public bool IsGreaterThan(BigDecimal left, BigDecimal right) - { - return Compare(left, right) is 1; - } + public bool IsGreaterThan(BigDecimal left, BigDecimal right) => Compare(left, right) is 1; /// /// Determines whether the left-hand value is greater than, or equal to the right-hand value. @@ -85,10 +76,7 @@ public bool IsGreaterThan(BigDecimal left, BigDecimal right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is greater than, or equal to the right-hand value; otherwise, . - public bool IsGreaterThanOrEqual(BigDecimal left, BigDecimal right) - { - return Compare(left, right) is 0 or 1; - } + public bool IsGreaterThanOrEqual(BigDecimal left, BigDecimal right) => Compare(left, right) is 0 or 1; /// /// Determines whether the left-hand value is less than the right-hand value. @@ -96,10 +84,7 @@ public bool IsGreaterThanOrEqual(BigDecimal left, BigDecimal right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is less than the right-hand value; otherwise, . - public bool IsLessThan(BigDecimal left, BigDecimal right) - { - return Compare(left, right) is -1; - } + public bool IsLessThan(BigDecimal left, BigDecimal right) => Compare(left, right) is -1; /// /// Determines whether the left-hand value is less than, or equal to the right-hand value. @@ -107,8 +92,5 @@ public bool IsLessThan(BigDecimal left, BigDecimal right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is less than, or equal to the right-hand value; otherwise, . - public bool IsLessThanOrEqual(BigDecimal left, BigDecimal right) - { - return Compare(left, right) is -1 or 0; - } + public bool IsLessThanOrEqual(BigDecimal left, BigDecimal right) => Compare(left, right) is -1 or 0; } diff --git a/OnixLabs.Numerics/GenericMath.cs b/OnixLabs.Numerics/GenericMath.cs index fa663a3..5f50792 100644 --- a/OnixLabs.Numerics/GenericMath.cs +++ b/OnixLabs.Numerics/GenericMath.cs @@ -29,10 +29,7 @@ public static class GenericMath /// The right-hand number from which to compute the delta. /// The underlying type. /// Returns the delta, or difference between the specified numbers. - public static T Delta(T left, T right) where T : INumberBase - { - return T.Abs(left - right); - } + public static T Delta(T left, T right) where T : INumberBase => T.Abs(left - right); /// /// Obtains the length of the integral component of the specified value. @@ -53,11 +50,5 @@ public static int IntegerLength(T value) where T : INumberBase /// The right-hand value to compare. /// The underlying type. /// Returns the minimum and maximum values from the specified left-hand and right-hand values. - public static (T Min, T Max) MinMax(T left, T right) where T : INumber - { - T min = T.Min(left, right); - T max = T.Max(left, right); - - return (min, max); - } + public static (T Min, T Max) MinMax(T left, T right) where T : INumber => (T.Min(left, right), T.Max(left, right)); } diff --git a/OnixLabs.Numerics/NumberInfo.Comparable.cs b/OnixLabs.Numerics/NumberInfo.Comparable.cs index 8c71bd4..87af347 100644 --- a/OnixLabs.Numerics/NumberInfo.Comparable.cs +++ b/OnixLabs.Numerics/NumberInfo.Comparable.cs @@ -23,10 +23,7 @@ public readonly partial struct NumberInfo /// The left-hand value to compare. /// The right-hand value to compare. /// Returns a value that indicates the relative order of the objects being compared. - public static int Compare(NumberInfo left, NumberInfo right) - { - return NumberInfoOrdinalityComparer.Default.Compare(left, right); - } + public static int Compare(NumberInfo left, NumberInfo right) => NumberInfoOrdinalityComparer.Default.Compare(left, right); /// /// Compares the current instance with another object of the same type and returns an integer that indicates @@ -35,10 +32,7 @@ public static int Compare(NumberInfo left, NumberInfo right) /// /// An object to compare with this instance. /// Returns a value that indicates the relative order of the objects being compared. - public int CompareTo(NumberInfo other) - { - return Compare(this, other); - } + public int CompareTo(NumberInfo other) => Compare(this, other); /// /// Compares the current instance with another object of the same type and returns an integer that indicates @@ -47,10 +41,7 @@ public int CompareTo(NumberInfo other) /// /// An object to compare with this instance. /// Returns a value that indicates the relative order of the objects being compared. - public int CompareTo(object? obj) - { - return NumberInfoOrdinalityComparer.Default.Compare(this, obj); - } + public int CompareTo(object? obj) => NumberInfoOrdinalityComparer.Default.Compare(this, obj); /// /// Determines whether the left-hand value is greater than the right-hand value. @@ -58,10 +49,7 @@ public int CompareTo(object? obj) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is greater than right-hand operand; otherwise, . - public static bool operator >(NumberInfo left, NumberInfo right) - { - return NumberInfoOrdinalityComparer.Default.IsGreaterThan(left, right); - } + public static bool operator >(NumberInfo left, NumberInfo right) => NumberInfoOrdinalityComparer.Default.IsGreaterThan(left, right); /// /// Determines whether the left-hand value is greater than or equal to the right-hand value. @@ -69,10 +57,7 @@ public int CompareTo(object? obj) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is greater than or equal to the right-hand operand; otherwise, . - public static bool operator >=(NumberInfo left, NumberInfo right) - { - return NumberInfoOrdinalityComparer.Default.IsGreaterThanOrEqual(left, right); - } + public static bool operator >=(NumberInfo left, NumberInfo right) => NumberInfoOrdinalityComparer.Default.IsGreaterThanOrEqual(left, right); /// /// Determines whether the left-hand value is less than right-hand value. @@ -80,10 +65,7 @@ public int CompareTo(object? obj) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is less than the right-hand operand; otherwise, . - public static bool operator <(NumberInfo left, NumberInfo right) - { - return NumberInfoOrdinalityComparer.Default.IsLessThan(left, right); - } + public static bool operator <(NumberInfo left, NumberInfo right) => NumberInfoOrdinalityComparer.Default.IsLessThan(left, right); /// /// Determines whether the left-hand value is less than or equal to the right-hand value. @@ -91,8 +73,5 @@ public int CompareTo(object? obj) /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the left-hand operand is less than or equal to the right-hand operand; otherwise, . - public static bool operator <=(NumberInfo left, NumberInfo right) - { - return NumberInfoOrdinalityComparer.Default.IsLessThanOrEqual(left, right); - } + public static bool operator <=(NumberInfo left, NumberInfo right) => NumberInfoOrdinalityComparer.Default.IsLessThanOrEqual(left, right); } diff --git a/OnixLabs.Numerics/NumberInfo.Equatable.cs b/OnixLabs.Numerics/NumberInfo.Equatable.cs index fba2bad..4c25189 100644 --- a/OnixLabs.Numerics/NumberInfo.Equatable.cs +++ b/OnixLabs.Numerics/NumberInfo.Equatable.cs @@ -25,10 +25,7 @@ public readonly partial struct NumberInfo /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the two specified instances are equal; otherwise, . - public static bool Equals(NumberInfo left, NumberInfo right) - { - return Equals(left, right, NumberInfoEqualityComparer.Strict); - } + public static bool Equals(NumberInfo left, NumberInfo right) => Equals(left, right, NumberInfoEqualityComparer.Strict); /// /// Compares two instances of to determine whether their values are equal. @@ -37,10 +34,7 @@ public static bool Equals(NumberInfo left, NumberInfo right) /// The right-hand value to compare. /// The equality comparer to use to determine equality. /// Returns if the two specified instances are equal; otherwise, . - public static bool Equals(NumberInfo left, NumberInfo right, NumberInfoEqualityComparer comparer) - { - return comparer.Equals(left, right); - } + public static bool Equals(NumberInfo left, NumberInfo right, NumberInfoEqualityComparer comparer) => comparer.Equals(left, right); /// /// Compares the current instance of with the specified other instance of . @@ -48,10 +42,7 @@ public static bool Equals(NumberInfo left, NumberInfo right, NumberInfoEqualityC /// /// The other instance of to compare with the current instance. /// Returns if the current instance is equal to the specified other instance; otherwise, . - public bool Equals(NumberInfo other) - { - return Equals(this, other); - } + public bool Equals(NumberInfo other) => Equals(this, other); /// /// Compares the current instance of with the specified other instance of . @@ -59,10 +50,7 @@ public bool Equals(NumberInfo other) /// The other instance of to compare with the current instance. /// The equality comparer to use to determine equality. /// Returns if the current instance is equal to the specified other instance; otherwise, . - public bool Equals(NumberInfo other, NumberInfoEqualityComparer comparer) - { - return Equals(this, other, comparer); - } + public bool Equals(NumberInfo other, NumberInfoEqualityComparer comparer) => Equals(this, other, comparer); /// /// Checks for equality between this instance and another object. @@ -70,10 +58,7 @@ public bool Equals(NumberInfo other, NumberInfoEqualityComparer comparer) /// /// The object to check for equality. /// Returns if the object is equal to this instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is NumberInfo other && Equals(other); - } + public override bool Equals(object? obj) => obj is NumberInfo other && Equals(other); /// /// Checks for equality between this instance and another object. @@ -81,20 +66,14 @@ public override bool Equals(object? obj) /// The object to check for equality. /// The equality comparer to use to determine equality. /// Returns if the object is equal to this instance; otherwise, . - public bool Equals(object? obj, NumberInfoEqualityComparer comparer) - { - return obj is NumberInfo other && Equals(other, comparer); - } + public bool Equals(object? obj, NumberInfoEqualityComparer comparer) => obj is NumberInfo other && Equals(other, comparer); /// /// Serves as a hash code function for this instance. /// This method implements the comparer. /// /// A hash code for this instance. - public override int GetHashCode() - { - return NumberInfoEqualityComparer.Strict.GetHashCode(this); - } + public override int GetHashCode() => NumberInfoEqualityComparer.Strict.GetHashCode(this); /// /// Compares two instances of to determine whether their values are equal. @@ -103,10 +82,7 @@ public override int GetHashCode() /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the two specified instances are equal; otherwise, . - public static bool operator ==(NumberInfo left, NumberInfo right) - { - return Equals(left, right, NumberInfoEqualityComparer.Semantic); - } + public static bool operator ==(NumberInfo left, NumberInfo right) => Equals(left, right, NumberInfoEqualityComparer.Semantic); /// /// Compares two instances of to determine whether their values are not equal. @@ -115,8 +91,5 @@ public override int GetHashCode() /// The left-hand value to compare. /// The right-hand value to compare. /// Returns if the two specified instances are not equal; otherwise, . - public static bool operator !=(NumberInfo left, NumberInfo right) - { - return Equals(left, right, NumberInfoEqualityComparer.Semantic); - } + public static bool operator !=(NumberInfo left, NumberInfo right) => !Equals(left, right, NumberInfoEqualityComparer.Semantic); } diff --git a/OnixLabs.Numerics/NumberInfo.Parse.cs b/OnixLabs.Numerics/NumberInfo.Parse.cs index 51c760d..4ba6df7 100644 --- a/OnixLabs.Numerics/NumberInfo.Parse.cs +++ b/OnixLabs.Numerics/NumberInfo.Parse.cs @@ -25,10 +25,7 @@ public readonly partial struct NumberInfo /// The value to parse. /// An object that provides culture-specific information about the specified value. /// Returns a new instance parsed from the specified value. - public static NumberInfo Parse(string value, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), provider); - } + public static NumberInfo Parse(string value, IFormatProvider? provider = null) => Parse(value.AsSpan(), provider); /// /// Parses the specified value into a value. @@ -37,10 +34,7 @@ public static NumberInfo Parse(string value, IFormatProvider? provider = null) /// A bitwise combination of number styles that can be present in the specified value. /// An object that provides culture-specific information about the specified value. /// Returns a new instance parsed from the specified value. - public static NumberInfo Parse(string value, NumberStyles style, IFormatProvider? provider = null) - { - return Parse(value.AsSpan(), style, provider); - } + public static NumberInfo Parse(string value, NumberStyles style, IFormatProvider? provider = null) => Parse(value.AsSpan(), style, provider); /// /// Parses the specified value into a value. @@ -48,10 +42,7 @@ public static NumberInfo Parse(string value, NumberStyles style, IFormatProvider /// The value to parse. /// An object that provides culture-specific information about the specified value. /// Returns a new instance parsed from the specified value. - public static NumberInfo Parse(ReadOnlySpan value, IFormatProvider? provider = null) - { - return Parse(value, DefaultNumberStyles, provider); - } + public static NumberInfo Parse(ReadOnlySpan value, IFormatProvider? provider = null) => Parse(value, DefaultNumberStyles, provider); /// /// Parses the specified value into a value. @@ -76,10 +67,7 @@ public static NumberInfo Parse(ReadOnlySpan value, NumberStyles style, IFo /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(string? value, out NumberInfo result) - { - return TryParse(value.AsSpan(), out result); - } + public static bool TryParse(string? value, out NumberInfo result) => TryParse(value.AsSpan(), out result); /// /// Tries to parse the specified value into a value. @@ -91,10 +79,7 @@ public static bool TryParse(string? value, out NumberInfo result) /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(string? value, IFormatProvider? provider, out NumberInfo result) - { - return TryParse(value.AsSpan(), provider, out result); - } + public static bool TryParse(string? value, IFormatProvider? provider, out NumberInfo result) => TryParse(value.AsSpan(), provider, out result); /// /// Tries to parse the specified value into a value. @@ -107,10 +92,7 @@ public static bool TryParse(string? value, IFormatProvider? provider, out Number /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(string? value, NumberStyles style, IFormatProvider? provider, out NumberInfo result) - { - return TryParse(value.AsSpan(), style, provider, out result); - } + public static bool TryParse(string? value, NumberStyles style, IFormatProvider? provider, out NumberInfo result) => TryParse(value.AsSpan(), style, provider, out result); /// /// Tries to parse the specified value into a value. @@ -121,10 +103,7 @@ public static bool TryParse(string? value, NumberStyles style, IFormatProvider? /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(ReadOnlySpan value, out NumberInfo result) - { - return TryParse(value, DefaultCulture, out result); - } + public static bool TryParse(ReadOnlySpan value, out NumberInfo result) => TryParse(value, DefaultCulture, out result); /// /// Tries to parse the specified value into a value. @@ -136,10 +115,7 @@ public static bool TryParse(ReadOnlySpan value, out NumberInfo result) /// or the default value in the event that the specified value could not be parsed. /// /// Returns if the specified value was parsed successfully; otherwise, . - public static bool TryParse(ReadOnlySpan value, IFormatProvider? provider, out NumberInfo result) - { - return TryParse(value, DefaultNumberStyles, provider, out result); - } + public static bool TryParse(ReadOnlySpan value, IFormatProvider? provider, out NumberInfo result) => TryParse(value, DefaultNumberStyles, provider, out result); /// /// Tries to parse the specified value into a value. diff --git a/OnixLabs.Numerics/NumberInfo.To.cs b/OnixLabs.Numerics/NumberInfo.To.cs index ddf9be3..e5eaf86 100644 --- a/OnixLabs.Numerics/NumberInfo.To.cs +++ b/OnixLabs.Numerics/NumberInfo.To.cs @@ -23,10 +23,7 @@ public readonly partial struct NumberInfo /// Formats the value of the current instance using the default format. /// /// The value of the current instance in the default format. - public override string ToString() - { - return ToString(DefaultNumberFormat, DefaultCulture); - } + public override string ToString() => ToString(DefaultNumberFormat, DefaultCulture); /// /// Formats the value of the current instance using the specified format. @@ -34,10 +31,7 @@ public override string ToString() /// The format to use, or null to use the default format. /// The provider to use to format the value. /// The value of the current instance in the specified format. - public string ToString(string? format, IFormatProvider? formatProvider = null) - { - return ToString((format ?? DefaultNumberFormat).AsSpan(), formatProvider); - } + public string ToString(string? format, IFormatProvider? formatProvider = null) => ToString((format ?? DefaultNumberFormat).AsSpan(), formatProvider); /// /// Formats the value of the current instance using the specified format. diff --git a/OnixLabs.Numerics/NumberInfo.cs b/OnixLabs.Numerics/NumberInfo.cs index 5a47e61..d6f7f97 100644 --- a/OnixLabs.Numerics/NumberInfo.cs +++ b/OnixLabs.Numerics/NumberInfo.cs @@ -21,22 +21,14 @@ namespace OnixLabs.Numerics; /// /// Represents component information about rational numbers. /// -public readonly partial struct NumberInfo : - IValueEquatable, - IValueComparable, - ISpanParsable, - IFormattable +public readonly partial struct NumberInfo : IValueEquatable, IValueComparable, ISpanParsable, IFormattable { /// /// Prevents a default instance of the struct from being created. /// /// The unscaled value of the represented number. /// The scale of the represented number. - internal NumberInfo(BigInteger unscaledValue, int scale) - { - UnscaledValue = unscaledValue; - Scale = scale; - } + internal NumberInfo(BigInteger unscaledValue, int scale) => (UnscaledValue, Scale) = (unscaledValue, scale); /// /// Gets the unscaled value of the represented number. diff --git a/OnixLabs.Numerics/NumberInfoEqualityComparer.cs b/OnixLabs.Numerics/NumberInfoEqualityComparer.cs index 7181e25..e904bdd 100644 --- a/OnixLabs.Numerics/NumberInfoEqualityComparer.cs +++ b/OnixLabs.Numerics/NumberInfoEqualityComparer.cs @@ -55,18 +55,12 @@ private NumberInfoEqualityComparer() /// The first object to compare. /// The second object to compare. /// Returns if the specified objects are both of type and are equal; otherwise, . - public new bool Equals(object? x, object? y) - { - return x is NumberInfo left && y is NumberInfo right && Equals(left, right); - } + public new bool Equals(object? x, object? y) => x is NumberInfo left && y is NumberInfo right && Equals(left, right); /// Returns a hash code for the specified object. /// The for which a hash code is to be returned. /// A hash code for the specified object. - public int GetHashCode(object obj) - { - return obj is NumberInfo value ? GetHashCode(value) : obj.GetHashCode(); - } + public int GetHashCode(object obj) => obj is NumberInfo value ? GetHashCode(value) : obj.GetHashCode(); /// /// Represents an equality comparer that compares values using strict equality. @@ -78,18 +72,12 @@ private sealed class NumberInfoStrictEqualityComparer : NumberInfoEqualityCompar /// The first object of type to compare. /// The second object of type to compare. /// Returns if the specified values are equal; otherwise, . - public override bool Equals(NumberInfo x, NumberInfo y) - { - return x.UnscaledValue == y.UnscaledValue && x.Scale == y.Scale; - } + public override bool Equals(NumberInfo x, NumberInfo y) => x.UnscaledValue == y.UnscaledValue && x.Scale == y.Scale; /// Returns a hash code for the specified value. /// The value for which a hash code is to be returned. /// Returns a hash code for the specified value. - public override int GetHashCode(NumberInfo obj) - { - return HashCode.Combine(obj.UnscaledValue, obj.Scale); - } + public override int GetHashCode(NumberInfo obj) => HashCode.Combine(obj.UnscaledValue, obj.Scale); } /// @@ -102,17 +90,11 @@ private sealed class NumberInfoSemanticEqualityComparer : NumberInfoEqualityComp /// The first object of type to compare. /// The second object of type to compare. /// Returns if the specified values are equal; otherwise, . - public override bool Equals(NumberInfo x, NumberInfo y) - { - return NumberInfoOrdinalityComparer.Default.IsEqual(x, y); - } + public override bool Equals(NumberInfo x, NumberInfo y) => NumberInfoOrdinalityComparer.Default.IsEqual(x, y); /// Returns a hash code for the specified value. /// The value for which a hash code is to be returned. /// Returns a hash code for the specified value. - public override int GetHashCode(NumberInfo obj) - { - return HashCode.Combine(obj.Significand, obj.Exponent); - } + public override int GetHashCode(NumberInfo obj) => HashCode.Combine(obj.Significand, obj.Exponent); } } diff --git a/OnixLabs.Numerics/NumberInfoOrdinalityComparer.cs b/OnixLabs.Numerics/NumberInfoOrdinalityComparer.cs index a31b6e9..51cf8a4 100644 --- a/OnixLabs.Numerics/NumberInfoOrdinalityComparer.cs +++ b/OnixLabs.Numerics/NumberInfoOrdinalityComparer.cs @@ -68,10 +68,7 @@ public int Compare(object? x, object? y) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is equal to the right-hand value; otherwise, . - public bool IsEqual(NumberInfo left, NumberInfo right) - { - return Compare(left, right) is 0; - } + public bool IsEqual(NumberInfo left, NumberInfo right) => Compare(left, right) is 0; /// /// Determines whether the left-hand value is greater than the right-hand value. @@ -79,10 +76,7 @@ public bool IsEqual(NumberInfo left, NumberInfo right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is greater than the right-hand value; otherwise, . - public bool IsGreaterThan(NumberInfo left, NumberInfo right) - { - return Compare(left, right) is 1; - } + public bool IsGreaterThan(NumberInfo left, NumberInfo right) => Compare(left, right) is 1; /// /// Determines whether the left-hand value is greater than, or equal to the right-hand value. @@ -90,10 +84,7 @@ public bool IsGreaterThan(NumberInfo left, NumberInfo right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is greater than, or equal to the right-hand value; otherwise, . - public bool IsGreaterThanOrEqual(NumberInfo left, NumberInfo right) - { - return Compare(left, right) is 0 or 1; - } + public bool IsGreaterThanOrEqual(NumberInfo left, NumberInfo right) => Compare(left, right) is 0 or 1; /// /// Determines whether the left-hand value is less than the right-hand value. @@ -101,10 +92,7 @@ public bool IsGreaterThanOrEqual(NumberInfo left, NumberInfo right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is less than the right-hand value; otherwise, . - public bool IsLessThan(NumberInfo left, NumberInfo right) - { - return Compare(left, right) is -1; - } + public bool IsLessThan(NumberInfo left, NumberInfo right) => Compare(left, right) is -1; /// /// Determines whether the left-hand value is less than, or equal to the right-hand value. @@ -112,8 +100,5 @@ public bool IsLessThan(NumberInfo left, NumberInfo right) /// The left-hand value to compare. /// The left-hand value to compare. /// Returns if the left-hand value is less than, or equal to the right-hand value; otherwise, . - public bool IsLessThanOrEqual(NumberInfo left, NumberInfo right) - { - return Compare(left, right) is -1 or 0; - } + public bool IsLessThanOrEqual(NumberInfo left, NumberInfo right) => Compare(left, right) is -1 or 0; } diff --git a/OnixLabs.Numerics/NumericsExtensions.cs b/OnixLabs.Numerics/NumericsExtensions.cs index 185ba6e..5daf9c2 100644 --- a/OnixLabs.Numerics/NumericsExtensions.cs +++ b/OnixLabs.Numerics/NumericsExtensions.cs @@ -75,10 +75,7 @@ private static BigInteger GetUnscaledInteger(this T value, int scale, ScaleMo /// The inclusive maximum value. /// The underlying type. /// Returns if the current value is inclusively between the specified minimum and maximum values; otherwise, . - public static bool IsBetween(this T value, T minimum, T maximum) where T : INumber - { - return value >= minimum && value <= maximum; - } + public static bool IsBetween(this T value, T minimum, T maximum) where T : INumber => value >= minimum && value <= maximum; /// /// Converts the current value to a value. @@ -88,10 +85,8 @@ public static bool IsBetween(this T value, T minimum, T maximum) where T : IN /// The scale mode that determines how the current value should be scaled. /// The underlying type of the value to convert. /// Returns a representing the current value. - public static BigDecimal ToBigDecimal(this T value, int scale = default, ScaleMode mode = ScaleMode.Integral) where T : IBinaryInteger - { - return new BigDecimal(value.ToBigInteger(), scale, mode); - } + public static BigDecimal ToBigDecimal(this T value, int scale = default, ScaleMode mode = ScaleMode.Integral) where T : IBinaryInteger => + new(value.ToBigInteger(), scale, mode); /// /// Converts the current value to a . @@ -99,10 +94,7 @@ public static BigDecimal ToBigDecimal(this T value, int scale = default, Scal /// The value to convert. /// The mode that specifies whether the value should be converted using its binary or decimal representation. /// Returns a new representing the current value. - public static BigDecimal ToBigDecimal(this float value, ConversionMode mode = default) - { - return new BigDecimal(value, mode); - } + public static BigDecimal ToBigDecimal(this float value, ConversionMode mode = default) => new(value, mode); /// /// Converts the current value to a . @@ -110,20 +102,14 @@ public static BigDecimal ToBigDecimal(this float value, ConversionMode mode = de /// The value to convert. /// The mode that specifies whether the value should be converted using its binary or decimal representation. /// Returns a new representing the current value. - public static BigDecimal ToBigDecimal(this double value, ConversionMode mode = default) - { - return new BigDecimal(value, mode); - } + public static BigDecimal ToBigDecimal(this double value, ConversionMode mode = default) => new(value, mode); /// /// Converts the current value to a . /// /// The value to convert. /// Returns a new representing the current value. - public static BigDecimal ToBigDecimal(this decimal value) - { - return new BigDecimal(value); - } + public static BigDecimal ToBigDecimal(this decimal value) => new(value); /// /// Converts the current value to a value. @@ -131,10 +117,7 @@ public static BigDecimal ToBigDecimal(this decimal value) /// The value to convert. /// The underlying type of the value to convert. /// Returns a representing the current value. - public static BigInteger ToBigInteger(this T value) where T : IBinaryInteger - { - return BigInteger.CreateChecked(value); - } + public static BigInteger ToBigInteger(this T value) where T : IBinaryInteger => BigInteger.CreateChecked(value); /// /// Converts the current value to a . @@ -205,8 +188,5 @@ public static NumberInfo ToNumberInfo(this double value, ConversionMode mode = d /// /// The value to convert. /// Returns a representing the current value. - public static NumberInfo ToNumberInfo(this decimal value) - { - return new NumberInfo(value.GetUnscaledValue(), value.Scale); - } + public static NumberInfo ToNumberInfo(this decimal value) => new(value.GetUnscaledValue(), value.Scale); } diff --git a/OnixLabs.Security.Cryptography/DigitalSignature.Equatable.cs b/OnixLabs.Security.Cryptography/DigitalSignature.Equatable.cs index 6d6eed8..2aca747 100644 --- a/OnixLabs.Security.Cryptography/DigitalSignature.Equatable.cs +++ b/OnixLabs.Security.Cryptography/DigitalSignature.Equatable.cs @@ -24,29 +24,20 @@ public readonly partial struct DigitalSignature /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(DigitalSignature other) - { - return value.SequenceEqual(other.value); - } + public bool Equals(DigitalSignature other) => value.SequenceEqual(other.value); /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is DigitalSignature other && Equals(other); - } + public override bool Equals(object? obj) => obj is DigitalSignature other && Equals(other); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return value.GetContentHashCode(); - } + public override int GetHashCode() => value.GetContentHashCode(); /// /// Performs an equality comparison between two object instances. @@ -54,10 +45,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(DigitalSignature left, DigitalSignature right) - { - return Equals(left, right); - } + public static bool operator ==(DigitalSignature left, DigitalSignature right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -65,8 +53,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(DigitalSignature left, DigitalSignature right) - { - return !Equals(left, right); - } + public static bool operator !=(DigitalSignature left, DigitalSignature right) => !Equals(left, right); } diff --git a/OnixLabs.Security.Cryptography/DigitalSignature.To.cs b/OnixLabs.Security.Cryptography/DigitalSignature.To.cs index 73e4f4f..7bff0ef 100644 --- a/OnixLabs.Security.Cryptography/DigitalSignature.To.cs +++ b/OnixLabs.Security.Cryptography/DigitalSignature.To.cs @@ -23,17 +23,11 @@ public readonly partial struct DigitalSignature /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return value.Copy(); - } + public byte[] ToByteArray() => value.Copy(); /// /// Returns a that represents the current object. /// /// Returns a that represents the current object. - public override string ToString() - { - return Convert.ToHexString(value).ToLower(); - } + public override string ToString() => Convert.ToHexString(value).ToLower(); } diff --git a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs index 6650422..2bf1bb4 100644 --- a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs +++ b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs @@ -24,10 +24,7 @@ public sealed partial class EcdsaPrivateKey /// /// The cryptographic private key data to import. /// Returns a new instance from the imported cryptographic private key data. - public static EcdsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data) - { - return ImportPkcs8PrivateKey(data, out int _); - } + public static EcdsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data) => ImportPkcs8PrivateKey(data, out int _); /// /// Imports the ECDSA cryptographic private key data in PKCS #8 format. @@ -49,10 +46,7 @@ public static EcdsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data, out /// The cryptographic private key data to import. /// The password required for password based decryption. /// Returns a new instance from the imported cryptographic private key data. - public static EcdsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data, ReadOnlySpan password) - { - return ImportPkcs8PrivateKey(data, password, out int _); - } + public static EcdsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data, ReadOnlySpan password) => ImportPkcs8PrivateKey(data, password, out int _); /// /// Imports the ECDSA cryptographic private key data in encrypted PKCS #8 format. diff --git a/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs b/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs index 97f9678..d1b1005 100644 --- a/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs +++ b/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs @@ -36,10 +36,8 @@ public static class HashAlgorithmExtensions /// The input data to compute the hash for. /// The number of rounds that the input data should be hashed. /// Returns the computed hash value. - public static byte[] ComputeHash(this HashAlgorithm algorithm, byte[] data, int rounds) - { - return algorithm.ComputeHash(new MemoryStream(data), rounds); - } + public static byte[] ComputeHash(this HashAlgorithm algorithm, byte[] data, int rounds) => + algorithm.ComputeHash(new MemoryStream(data), rounds); /// /// Computes the hash value for the specified byte array. @@ -50,10 +48,8 @@ public static byte[] ComputeHash(this HashAlgorithm algorithm, byte[] data, int /// The number of bytes in the array to use as data. /// The number of rounds that the input data should be hashed. /// Returns the computed hash value. - public static byte[] ComputeHash(this HashAlgorithm algorithm, byte[] data, int offset, int count, int rounds) - { - return algorithm.ComputeHash(data.Copy(offset, count), rounds); - } + public static byte[] ComputeHash(this HashAlgorithm algorithm, byte[] data, int offset, int count, int rounds) => + algorithm.ComputeHash(data.Copy(offset, count), rounds); /// /// Computes the hash value for the specified . @@ -63,10 +59,8 @@ public static byte[] ComputeHash(this HashAlgorithm algorithm, byte[] data, int /// The which will be used to convert the specified . /// The number of rounds that the input data should be hashed. /// Returns the computed hash value. - public static byte[] ComputeHash(this HashAlgorithm algorithm, ReadOnlySpan data, Encoding? encoding = null, int rounds = 1) - { - return algorithm.ComputeHash((encoding ?? Encoding.Default).GetBytes(data.ToArray()), rounds); - } + public static byte[] ComputeHash(this HashAlgorithm algorithm, ReadOnlySpan data, Encoding? encoding = null, int rounds = 1) => + algorithm.ComputeHash((encoding ?? Encoding.Default).GetBytes(data.ToArray()), rounds); /// /// Computes the hash value for the specified object. diff --git a/OnixLabs.Security.Cryptography/Hash.Comparable.cs b/OnixLabs.Security.Cryptography/Hash.Comparable.cs index 15418f8..947c48c 100644 --- a/OnixLabs.Security.Cryptography/Hash.Comparable.cs +++ b/OnixLabs.Security.Cryptography/Hash.Comparable.cs @@ -41,10 +41,7 @@ public int CompareTo(Hash other) /// /// An object to compare with this instance. /// Returns a value that indicates the relative order of the objects being compared. - public int CompareTo(object? obj) - { - return this.CompareToObject(obj); - } + public int CompareTo(object? obj) => this.CompareToObject(obj); /// /// Performs a greater than comparison between two object instances. @@ -52,10 +49,7 @@ public int CompareTo(object? obj) /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is greater than the right-hand instance; otherwise, . - public static bool operator >(Hash left, Hash right) - { - return left.CompareTo(right) is 1; - } + public static bool operator >(Hash left, Hash right) => left.CompareTo(right) is 1; /// /// Performs a greater than or equal comparison between two object instances. @@ -63,10 +57,7 @@ public int CompareTo(object? obj) /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is greater than or equal to the right-hand instance; otherwise, . - public static bool operator >=(Hash left, Hash right) - { - return left.CompareTo(right) is 0 or 1; - } + public static bool operator >=(Hash left, Hash right) => left.CompareTo(right) is 0 or 1; /// /// Performs a less than comparison between two object instances. @@ -74,10 +65,7 @@ public int CompareTo(object? obj) /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is less than the right-hand instance; otherwise, . - public static bool operator <(Hash left, Hash right) - { - return left.CompareTo(right) is -1; - } + public static bool operator <(Hash left, Hash right) => left.CompareTo(right) is -1; /// /// Performs a less than or equal comparison between two object instances. @@ -85,8 +73,5 @@ public int CompareTo(object? obj) /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is less than or equal to the right-hand instance; otherwise, . - public static bool operator <=(Hash left, Hash right) - { - return left.CompareTo(right) is 0 or -1; - } + public static bool operator <=(Hash left, Hash right) => left.CompareTo(right) is 0 or -1; } diff --git a/OnixLabs.Security.Cryptography/Hash.Concatenate.cs b/OnixLabs.Security.Cryptography/Hash.Concatenate.cs index 96f32bd..c87ac9b 100644 --- a/OnixLabs.Security.Cryptography/Hash.Concatenate.cs +++ b/OnixLabs.Security.Cryptography/Hash.Concatenate.cs @@ -39,8 +39,5 @@ public static Hash Concatenate(HashAlgorithm algorithm, Hash left, Hash right) /// The which will be used to compute the hash. /// The other hash to concatenate with the current hash. /// Returns a cryptographic hash representing the concatenation of the left-hand and right-hand hash values. - public Hash Concatenate(HashAlgorithm algorithm, Hash other) - { - return Concatenate(algorithm, this, other); - } + public Hash Concatenate(HashAlgorithm algorithm, Hash other) => Concatenate(algorithm, this, other); } diff --git a/OnixLabs.Security.Cryptography/Hash.Equatable.cs b/OnixLabs.Security.Cryptography/Hash.Equatable.cs index 85b449e..39d2b80 100644 --- a/OnixLabs.Security.Cryptography/Hash.Equatable.cs +++ b/OnixLabs.Security.Cryptography/Hash.Equatable.cs @@ -24,29 +24,20 @@ public readonly partial struct Hash /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(Hash other) - { - return value.SequenceEqual(other.value); - } + public bool Equals(Hash other) => value.SequenceEqual(other.value); /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is Hash other && Equals(other); - } + public override bool Equals(object? obj) => obj is Hash other && Equals(other); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return value.GetContentHashCode(); - } + public override int GetHashCode() => value.GetContentHashCode(); /// /// Performs an equality comparison between two object instances. @@ -54,10 +45,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(Hash left, Hash right) - { - return Equals(left, right); - } + public static bool operator ==(Hash left, Hash right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -65,8 +53,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(Hash left, Hash right) - { - return !Equals(left, right); - } + public static bool operator !=(Hash left, Hash right) => !Equals(left, right); } diff --git a/OnixLabs.Security.Cryptography/Hash.To.cs b/OnixLabs.Security.Cryptography/Hash.To.cs index 75d7395..a24c432 100644 --- a/OnixLabs.Security.Cryptography/Hash.To.cs +++ b/OnixLabs.Security.Cryptography/Hash.To.cs @@ -23,17 +23,11 @@ public readonly partial struct Hash /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return value.Copy(); - } + public byte[] ToByteArray() => value.Copy(); /// /// Returns a that represents the current object. /// /// Returns that represents the current object. - public override string ToString() - { - return Convert.ToHexString(value).ToLower(); - } + public override string ToString() => Convert.ToHexString(value).ToLower(); } diff --git a/OnixLabs.Security.Cryptography/MerkleTree.Create.cs b/OnixLabs.Security.Cryptography/MerkleTree.Create.cs index 9e339eb..7ce94b6 100644 --- a/OnixLabs.Security.Cryptography/MerkleTree.Create.cs +++ b/OnixLabs.Security.Cryptography/MerkleTree.Create.cs @@ -40,10 +40,7 @@ public static MerkleTree Create(IEnumerable leaves, HashAlgorithm algorith /// The Merkle tree leaf nodes from which to build a Merkle tree. /// The hash algorithm that will be used to hash together left-hand and right-hand nodes. /// Returns a new node that represents the Merkle root. - public static MerkleTree Create(IEnumerable leaves, HashAlgorithm algorithm) where T : IHashable - { - return MerkleTree.Create(leaves, algorithm); - } + public static MerkleTree Create(IEnumerable leaves, HashAlgorithm algorithm) where T : IHashable => MerkleTree.Create(leaves, algorithm); /// /// Builds a Merkle tree from the specified nodes. diff --git a/OnixLabs.Security.Cryptography/MerkleTree.Equatable.cs b/OnixLabs.Security.Cryptography/MerkleTree.Equatable.cs index 8f94ce1..f93d878 100644 --- a/OnixLabs.Security.Cryptography/MerkleTree.Equatable.cs +++ b/OnixLabs.Security.Cryptography/MerkleTree.Equatable.cs @@ -23,31 +23,20 @@ public abstract partial class MerkleTree /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(MerkleTree? other) - { - return ReferenceEquals(this, other) - || other is not null - && other.Hash == Hash; - } + public bool Equals(MerkleTree? other) => ReferenceEquals(this, other) || other is not null && other.Hash == Hash; /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return Equals(obj as MerkleTree); - } + public override bool Equals(object? obj) => Equals(obj as MerkleTree); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return HashCode.Combine(GetType(), Hash); - } + public override int GetHashCode() => HashCode.Combine(GetType(), Hash); /// /// Performs an equality comparison between two object instances. @@ -55,10 +44,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(MerkleTree left, MerkleTree right) - { - return Equals(left, right); - } + public static bool operator ==(MerkleTree left, MerkleTree right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -66,8 +52,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(MerkleTree left, MerkleTree right) - { - return !Equals(left, right); - } + public static bool operator !=(MerkleTree left, MerkleTree right) => !Equals(left, right); } diff --git a/OnixLabs.Security.Cryptography/MerkleTree.Generic.Equatable.cs b/OnixLabs.Security.Cryptography/MerkleTree.Generic.Equatable.cs index 0ff59da..016015f 100644 --- a/OnixLabs.Security.Cryptography/MerkleTree.Generic.Equatable.cs +++ b/OnixLabs.Security.Cryptography/MerkleTree.Generic.Equatable.cs @@ -23,31 +23,20 @@ public abstract partial class MerkleTree /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(MerkleTree? other) - { - return ReferenceEquals(this, other) - || other is not null - && other.Hash == Hash; - } + public bool Equals(MerkleTree? other) => ReferenceEquals(this, other) || other is not null && other.Hash == Hash; /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return Equals(obj as MerkleTree); - } + public override bool Equals(object? obj) => Equals(obj as MerkleTree); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return HashCode.Combine(GetType(), Hash); - } + public override int GetHashCode() => HashCode.Combine(GetType(), Hash); /// /// Performs an equality comparison between two object instances. @@ -55,10 +44,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(MerkleTree left, MerkleTree right) - { - return Equals(left, right); - } + public static bool operator ==(MerkleTree left, MerkleTree right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -66,8 +52,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(MerkleTree left, MerkleTree right) - { - return !Equals(left, right); - } + public static bool operator !=(MerkleTree left, MerkleTree right) => !Equals(left, right); } diff --git a/OnixLabs.Security.Cryptography/MerkleTree.Generic.cs b/OnixLabs.Security.Cryptography/MerkleTree.Generic.cs index 3b9d788..06546b0 100644 --- a/OnixLabs.Security.Cryptography/MerkleTree.Generic.cs +++ b/OnixLabs.Security.Cryptography/MerkleTree.Generic.cs @@ -68,10 +68,7 @@ private sealed class MerkleTreeLeafNode : MerkleTree /// /// The underlying value of the current node. /// The hash algorithm that will be used to hash the specified value. - public MerkleTreeLeafNode(T value, HashAlgorithm algorithm) : base(value.ComputeHash(algorithm)) - { - Value = value; - } + public MerkleTreeLeafNode(T value, HashAlgorithm algorithm) : base(value.ComputeHash(algorithm)) => Value = value; /// /// Gets the underlying value of the current node. diff --git a/OnixLabs.Security.Cryptography/MerkleTree.To.cs b/OnixLabs.Security.Cryptography/MerkleTree.To.cs index 355bc24..7537939 100644 --- a/OnixLabs.Security.Cryptography/MerkleTree.To.cs +++ b/OnixLabs.Security.Cryptography/MerkleTree.To.cs @@ -20,17 +20,11 @@ public abstract partial class MerkleTree /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return Hash.ToByteArray(); - } + public byte[] ToByteArray() => Hash.ToByteArray(); /// /// Returns a that represents the current object. /// /// Returns that represents the current object. - public override string ToString() - { - return Hash.ToString(); - } + public override string ToString() => Hash.ToString(); } diff --git a/OnixLabs.Security.Cryptography/MerkleTree.cs b/OnixLabs.Security.Cryptography/MerkleTree.cs index cf6fab2..7da96eb 100644 --- a/OnixLabs.Security.Cryptography/MerkleTree.cs +++ b/OnixLabs.Security.Cryptography/MerkleTree.cs @@ -25,10 +25,7 @@ public abstract partial class MerkleTree : ICryptoPrimitive /// Initializes a new instance of the class. /// This constructor is marked internal to prevent external implementation. /// - internal MerkleTree(Hash hash) - { - Hash = hash; - } + internal MerkleTree(Hash hash) => Hash = hash; /// /// Gets the of the current node. diff --git a/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs b/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs index ae5332f..88f2209 100644 --- a/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs +++ b/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs @@ -38,19 +38,13 @@ public bool Equals(PrivateKey? other) /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return Equals(obj as PrivateKey); - } + public override bool Equals(object? obj) => Equals(obj as PrivateKey); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return HashCode.Combine(GetType(), KeyData.GetContentHashCode()); - } + public override int GetHashCode() => HashCode.Combine(GetType(), KeyData.GetContentHashCode()); /// /// Performs an equality comparison between two object instances. @@ -58,10 +52,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(PrivateKey left, PrivateKey right) - { - return Equals(left, right); - } + public static bool operator ==(PrivateKey left, PrivateKey right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -69,8 +60,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(PrivateKey left, PrivateKey right) - { - return !Equals(left, right); - } + public static bool operator !=(PrivateKey left, PrivateKey right) => !Equals(left, right); } diff --git a/OnixLabs.Security.Cryptography/PrivateKey.To.cs b/OnixLabs.Security.Cryptography/PrivateKey.To.cs index 1f24ed1..9526da2 100644 --- a/OnixLabs.Security.Cryptography/PrivateKey.To.cs +++ b/OnixLabs.Security.Cryptography/PrivateKey.To.cs @@ -23,17 +23,11 @@ public abstract partial class PrivateKey /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return KeyData.Copy(); - } + public byte[] ToByteArray() => KeyData.Copy(); /// /// Returns a that represents the current object. /// /// Returns that represents the current object. - public override string ToString() - { - return Convert.ToHexString(KeyData).ToLower(); - } + public override string ToString() => Convert.ToHexString(KeyData).ToLower(); } diff --git a/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs b/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs index 5a6a110..246507a 100644 --- a/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs +++ b/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs @@ -38,19 +38,13 @@ public bool Equals(PublicKey? other) /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return Equals(obj as PublicKey); - } + public override bool Equals(object? obj) => Equals(obj as PublicKey); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return HashCode.Combine(GetType(), KeyData.GetContentHashCode()); - } + public override int GetHashCode() => HashCode.Combine(GetType(), KeyData.GetContentHashCode()); /// /// Performs an equality comparison between two object instances. @@ -58,10 +52,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(PublicKey left, PublicKey right) - { - return Equals(left, right); - } + public static bool operator ==(PublicKey left, PublicKey right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -69,8 +60,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(PublicKey left, PublicKey right) - { - return !Equals(left, right); - } + public static bool operator !=(PublicKey left, PublicKey right) => !Equals(left, right); } diff --git a/OnixLabs.Security.Cryptography/PublicKey.To.cs b/OnixLabs.Security.Cryptography/PublicKey.To.cs index 615fc5b..0c2e8de 100644 --- a/OnixLabs.Security.Cryptography/PublicKey.To.cs +++ b/OnixLabs.Security.Cryptography/PublicKey.To.cs @@ -23,17 +23,11 @@ public abstract partial class PublicKey /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return KeyData.Copy(); - } + public byte[] ToByteArray() => KeyData.Copy(); /// /// Returns a that represents the current object. /// /// Returns that represents the current object. - public override string ToString() - { - return Convert.ToHexString(KeyData).ToLower(); - } + public override string ToString() => Convert.ToHexString(KeyData).ToLower(); } diff --git a/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs b/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs index 5c07ad3..e8eadf1 100644 --- a/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs +++ b/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs @@ -24,10 +24,7 @@ public sealed partial class RsaPrivateKey /// /// The cryptographic private key data to import. /// Returns a new instance from the imported cryptographic private key data. - public static RsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data) - { - return ImportPkcs8PrivateKey(data, out int _); - } + public static RsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data) => ImportPkcs8PrivateKey(data, out int _); /// /// Imports the RSA cryptographic private key data in PKCS #8 format. @@ -49,10 +46,7 @@ public static RsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data, out i /// The cryptographic private key data to import. /// The password required for password based decryption. /// Returns a new instance from the imported cryptographic private key data. - public static RsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data, ReadOnlySpan password) - { - return ImportPkcs8PrivateKey(data, password, out int _); - } + public static RsaPrivateKey ImportPkcs8PrivateKey(ReadOnlySpan data, ReadOnlySpan password) => ImportPkcs8PrivateKey(data, password, out int _); /// /// Imports the RSA cryptographic private key data in encrypted PKCS #8 format. diff --git a/OnixLabs.Security.Cryptography/Salt.Equatable.cs b/OnixLabs.Security.Cryptography/Salt.Equatable.cs index c8d713c..ea09397 100644 --- a/OnixLabs.Security.Cryptography/Salt.Equatable.cs +++ b/OnixLabs.Security.Cryptography/Salt.Equatable.cs @@ -24,29 +24,20 @@ public readonly partial struct Salt /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(Salt other) - { - return value.SequenceEqual(other.value); - } + public bool Equals(Salt other) => value.SequenceEqual(other.value); /// /// Checks for equality between the current instance and another object. /// /// The object to check for equality. /// Returns if the object is equal to the current instance; otherwise, . - public override bool Equals(object? obj) - { - return obj is Salt other && Equals(other); - } + public override bool Equals(object? obj) => obj is Salt other && Equals(other); /// /// Serves as a hash code function for the current instance. /// /// Returns a hash code for the current instance. - public override int GetHashCode() - { - return value.GetContentHashCode(); - } + public override int GetHashCode() => value.GetContentHashCode(); /// /// Performs an equality comparison between two object instances. @@ -54,10 +45,7 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is equal to the right-hand instance; otherwise, . - public static bool operator ==(Salt left, Salt right) - { - return Equals(left, right); - } + public static bool operator ==(Salt left, Salt right) => Equals(left, right); /// /// Performs an inequality comparison between two object instances. @@ -65,8 +53,5 @@ public override int GetHashCode() /// The left-hand instance to compare. /// The right-hand instance to compare. /// Returns if the left-hand instance is not equal to the right-hand instance; otherwise, . - public static bool operator !=(Salt left, Salt right) - { - return !Equals(left, right); - } + public static bool operator !=(Salt left, Salt right) => !Equals(left, right); } diff --git a/OnixLabs.Security.Cryptography/Salt.To.cs b/OnixLabs.Security.Cryptography/Salt.To.cs index 100dd40..ef1887a 100644 --- a/OnixLabs.Security.Cryptography/Salt.To.cs +++ b/OnixLabs.Security.Cryptography/Salt.To.cs @@ -23,17 +23,11 @@ public readonly partial struct Salt /// Gets the underlying representation of the current instance. /// /// Return the underlying representation of the current instance. - public byte[] ToByteArray() - { - return value.Copy(); - } + public byte[] ToByteArray() => value.Copy(); /// /// Returns a that represents the current object. /// /// Returns that represents the current object. - public override string ToString() - { - return Convert.ToHexString(value).ToLower(); - } + public override string ToString() => Convert.ToHexString(value).ToLower(); } diff --git a/OnixLabs.Security.Cryptography/Sha3.Create.cs b/OnixLabs.Security.Cryptography/Sha3.Create.cs index a6cfaaf..5140735 100644 --- a/OnixLabs.Security.Cryptography/Sha3.Create.cs +++ b/OnixLabs.Security.Cryptography/Sha3.Create.cs @@ -20,55 +20,37 @@ public abstract partial class Sha3 /// Creates an instance of the algorithm. /// /// An instance of the algorithm. - public static Sha3Hash224 CreateSha3Hash224() - { - return new Sha3Hash224(); - } + public static Sha3Hash224 CreateSha3Hash224() => new(); /// /// Creates an instance of the algorithm. /// /// An instance of the algorithm. - public static Sha3Hash256 CreateSha3Hash256() - { - return new Sha3Hash256(); - } + public static Sha3Hash256 CreateSha3Hash256() => new(); /// /// Creates an instance of the algorithm. /// /// An instance of the algorithm. - public static Sha3Hash384 CreateSha3Hash384() - { - return new Sha3Hash384(); - } + public static Sha3Hash384 CreateSha3Hash384() => new(); /// /// Creates an instance of the algorithm. /// /// An instance of the algorithm. - public static Sha3Hash512 CreateSha3Hash512() - { - return new Sha3Hash512(); - } + public static Sha3Hash512 CreateSha3Hash512() => new(); /// /// Creates an instance of the algorithm. /// /// The output length of the hash in bytes. /// An instance of the algorithm. - public static Sha3Shake128 CreateSha3Shake128(int length) - { - return new Sha3Shake128(length); - } + public static Sha3Shake128 CreateSha3Shake128(int length) => new(length); /// /// Creates an instance of the algorithm. /// /// The output length of the hash in bytes. /// An instance of the algorithm. - public static Sha3Shake256 CreateSha3Shake256(int length) - { - return new Sha3Shake256(length); - } + public static Sha3Shake256 CreateSha3Shake256(int length) => new(length); } diff --git a/OnixLabs.Security.Cryptography/Sha3.Permute.cs b/OnixLabs.Security.Cryptography/Sha3.Permute.cs index 81bdc1c..e93905a 100644 --- a/OnixLabs.Security.Cryptography/Sha3.Permute.cs +++ b/OnixLabs.Security.Cryptography/Sha3.Permute.cs @@ -137,14 +137,8 @@ void Chi() } } - void Iota(int round) - { - state[0] ^= roundConstants[round]; - } + void Iota(int round) => state[0] ^= roundConstants[round]; - ulong RotateLeft(ulong x, byte y) - { - return (x << y) | (x >> (64 - y)); - } + ulong RotateLeft(ulong x, byte y) => (x << y) | (x >> (64 - y)); } }