diff --git a/lib/YANLib/Async/YANEnumerable.cs b/lib/YANLib/Async/YANEnumerable.cs deleted file mode 100644 index ad650b07..00000000 --- a/lib/YANLib/Async/YANEnumerable.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace YANLib.Async; - -public static partial class YANEnumerable -{ - public static async ValueTask> ToListAsync(this IAsyncEnumerable srcs) - { - var rslts = new List(); - await foreach (var src in srcs.ConfigureAwait(false)) - { - rslts.Add(src); - } - return rslts; - } -} diff --git a/lib/YANLib/Async/YANFunc.cs b/lib/YANLib/Async/YANFunc.cs deleted file mode 100644 index 6e78f460..00000000 --- a/lib/YANLib/Async/YANFunc.cs +++ /dev/null @@ -1,133 +0,0 @@ -using static System.Environment; -using static System.Threading.Tasks.Task; - -namespace YANLib.Async; - -public static partial class YANFunc -{ - public static async ValueTask> AggregateResultsConcurrentlyAsync(Func> func, IEnumerable args) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var rng = await func(arg).ToListAsync(); - await semSlim.WaitAsync(); - try - { - rslts.AddRange(rng); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrentlyAsync(Func, IAsyncEnumerable> func, IEnumerable args, IEnumerable coll) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var rng = await func(arg, coll).ToListAsync(); - await semSlim.WaitAsync(); - try - { - rslts.AddRange(rng); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrentlyAsync(Func>> func, IEnumerable args) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var rng = await (await func(arg)).ToListAsync(); - await semSlim.WaitAsync(); - try - { - rslts.AddRange(rng); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrentlyAsync(Func, ValueTask>> func, IEnumerable args, IEnumerable coll) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var rng = await (await func(arg, coll)).ToListAsync(); - await semSlim.WaitAsync(); - try - { - rslts.AddRange(rng); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrentlyAsync(Func>> func, IEnumerable args) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var rng = await (await func(arg)).ToListAsync(); - await semSlim.WaitAsync(); - try - { - rslts.AddRange(rng); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrentlyAsync(Func, Task>> func, IEnumerable args, IEnumerable coll) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var rng = await (await func(arg, coll)).ToListAsync(); - await semSlim.WaitAsync(); - try - { - rslts.AddRange(rng); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } -} diff --git a/lib/YANLib/Async/YANHttpClient.cs b/lib/YANLib/Demo/YANHttpClient.cs similarity index 86% rename from lib/YANLib/Async/YANHttpClient.cs rename to lib/YANLib/Demo/YANHttpClient.cs index 5babf421..f06a92b3 100644 --- a/lib/YANLib/Async/YANHttpClient.cs +++ b/lib/YANLib/Demo/YANHttpClient.cs @@ -11,11 +11,11 @@ using System.Xml.Linq; using static System.Net.HttpStatusCode; -namespace YANLib.Async; +namespace YANLib.Demo; public static partial class YANHttpClient { - public static async ValueTask GetApiAsync(this HttpClient httpClient, string uri, string param, string? path = null, string? authorization = null, JsonSerializerOptions? serializerOptions = null) where T : class, new() + private static async ValueTask GetApiAsync(this HttpClient httpClient, string uri, string param, string? path = null, string? authorization = null, JsonSerializerOptions? serializerOptions = null) where T : class, new() { try { @@ -52,7 +52,7 @@ public static partial class YANHttpClient } } - public static async Task PostApiAsync(string uri, string param, object data, string? authorization = null) where T : class, new() + private static async Task PostApiAsync(string uri, string param, object data, string? authorization = null) where T : class, new() { var httpCl = new HttpClient { diff --git a/lib/YANLib/Nullable/YANDateTime.Nullable.cs b/lib/YANLib/Nullable/YANDateTime.Nullable.cs index e597545d..f56620f2 100644 --- a/lib/YANLib/Nullable/YANDateTime.Nullable.cs +++ b/lib/YANLib/Nullable/YANDateTime.Nullable.cs @@ -4,26 +4,11 @@ namespace YANLib.Nullable; public static partial class YANDateTime { - /// - /// Parses the string representation of a date and time using . - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The format of the string representation. - /// The default value to return if the parsing fails. - /// The parsed value, or if the parsing fails. + public static DateTime? ToDateTime(this string str, string fmt, DateTime? dfltVal) => dfltVal.HasValue ? str.ToDateTime(fmt, dfltVal.Value) : default; - /// - /// Converts an enumerable of strings representing date/time values in a specified format to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// If a string cannot be parsed to a valid DateTime value, the default value specified by is used instead. - /// - /// The format of the date/time values in the input strings. - /// The default DateTime value to be used for strings that cannot be parsed to valid DateTime values. - /// The enumerable of strings to convert to DateTime values. - /// An containing the parsed DateTime values. - public static IEnumerable ToDateTime(IEnumerable strs, string fmt, DateTime? dfltVal) + + public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal) { if (strs.IsNullOrWhiteSpace()) { @@ -35,28 +20,10 @@ public static partial class YANDateTime } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . + public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : default; - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -65,19 +32,7 @@ public static partial class YANDateTime } } - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -86,28 +41,10 @@ public static partial class YANDateTime } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . + public static DateTime? GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default; - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -116,19 +53,7 @@ public static partial class YANDateTime } } - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T? size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -137,28 +62,10 @@ public static partial class YANDateTime } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . + public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max); - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -167,19 +74,7 @@ public static partial class YANDateTime } } - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -188,26 +83,13 @@ public static partial class YANDateTime } } - /// - /// Generates a random value between and . - /// - /// The maximum value. - /// A random value between and . + public static DateTime? GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default; - /// - /// Returns the week of the year that the specified value falls in, according to the current culture's calendar, week rule, and first day of the week settings. - /// - /// The value. - /// The week of the year that the specified value falls in. + public static int? GetWeekOfYear(this DateTime? dt) => dt.HasValue ? dt.Value.GetWeekOfYear() : default; - /// - /// Gets the week of the year for an enumerable of DateTime values using the default calendar of the current culture. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The enumerable of DateTime values for which to get the week of the year. - /// An containing the week of the year values for the input DateTime values. + public static IEnumerable GetWeekOfYear(this IEnumerable dts) { if (dts is null || !dts.Any()) @@ -220,52 +102,19 @@ public static partial class YANDateTime } } - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. + public static int? TotalMonths(DateTime? dt1, DateTime dt2) => dt1.HasValue ? TotalMonths(dt1.Value, dt2) : default; - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. + public static int? TotalMonths(DateTime dt1, DateTime? dt2) => dt2.HasValue ? TotalMonths(dt1, dt2.Value) : default; - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. + public static int? TotalMonths(DateTime? dt1, DateTime? dt2) => dt1.HasValue ? TotalMonths(dt1.Value, dt2) : default; - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime? dt, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The source time zone. - /// The destination time zone. - /// The values to convert to the destination time zone. - /// An containing the values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -278,15 +127,7 @@ public static partial class YANDateTime } } - /// - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. + public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -298,28 +139,10 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime dt, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => tzSrc.HasValue ? dt.ChangeTimeZone(tzSrc.Value, tzDst) : dt.ChangeTimeZone(tzDst); - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The source time zone. - /// The destination time zone. - /// The values to convert to the destination time zone. - /// An containing the values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -332,28 +155,10 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime dt, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => tzDst.HasValue ? dt.ChangeTimeZone(tzSrc, tzDst.Value) : dt; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The source time zone. - /// The destination time zone. - /// The values to convert to the destination time zone. - /// An containing the values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -366,28 +171,10 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime? dt, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The source time zone. - /// The destination time zone. - /// The values to convert to the destination time zone. - /// An containing the values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -400,15 +187,7 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. + public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -420,28 +199,10 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime? dt, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The source time zone. - /// The destination time zone. - /// The values to convert to the destination time zone. - /// An containing the values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -454,15 +215,7 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, } } - /// - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. + public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -474,28 +227,10 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime dt, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => tzSrc.HasValue ? dt.ChangeTimeZone(tzSrc.Value, tzDst) : dt.ChangeTimeZone(tzDst); - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The source time zone. - /// The destination time zone. - /// The values to convert to the destination time zone. - /// An containing the values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -508,28 +243,10 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime? dt, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The source time zone. - /// The destination time zone. - /// The values to convert to the destination time zone. - /// An containing the values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -542,15 +259,7 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. + public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -562,22 +271,10 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. + public static DateTime? ChangeTimeZone(this DateTime? dt, T tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct { if (dts is null || !dts.Any()) @@ -590,13 +287,7 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, } } - /// - /// Converts a list of DateTime values from one time zone to another using the specified destination time zone, and updates the original list in place with the DateTime values converted to the destination time zone. - /// If the input list is or empty, no changes will be made. - /// - /// The type of the destination time zone. - /// The list of DateTime values to convert. - /// The destination time zone to convert to. + public static void ChangeTimeZone(this IList dts, T tzDst) where T : struct { if (dts is not null && dts.Count > 0) @@ -608,22 +299,10 @@ public static void ChangeTimeZone(this IList dts, T tzDst) where T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. + public static DateTime? ChangeTimeZone(this DateTime dt, T? tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct { if (dts is null || !dts.Any()) @@ -636,22 +315,10 @@ public static void ChangeTimeZone(this IList dts, T tzDst) where T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. + public static DateTime? ChangeTimeZone(this DateTime? dt, T? tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct { if (dts is null || !dts.Any()) @@ -664,13 +331,7 @@ public static void ChangeTimeZone(this IList dts, T tzDst) where T } } - /// - /// Converts a list of DateTime values from one time zone to another using the specified destination time zone, and updates the original list in place with the DateTime values converted to the destination time zone. - /// If the input list is or empty, no changes will be made. - /// - /// The type of the destination time zone. - /// The list of DateTime values to convert. - /// The destination time zone to convert to. + public static void ChangeTimeZone(this IList dts, T? tzDst) where T : struct { if (dts is not null && dts.Count > 0) diff --git a/lib/YANLib/Nullable/YANDateTime.cs b/lib/YANLib/Nullable/YANDateTime.cs index 18dff697..d8162276 100644 --- a/lib/YANLib/Nullable/YANDateTime.cs +++ b/lib/YANLib/Nullable/YANDateTime.cs @@ -9,20 +9,10 @@ namespace YANLib.Nullable; public static partial class YANDateTime { - /// - /// Parses the string representation of a date and time using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. + public static DateTime? ToDateTime(this string str) => TryParse(str, out var dt) ? dt : default; - /// - /// Converts an enumerable of strings representing date/time values to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// - /// The enumerable of strings to convert to DateTime values. - /// An containing the parsed DateTime values. + public static IEnumerable ToDateTime(this IEnumerable strs) { if (strs.IsNullOrWhiteSpace()) @@ -35,23 +25,11 @@ public static partial class YANDateTime } } - /// - /// Parses the string representation of a date and time using . - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The format of the string representation. - /// The parsed value, or if the parsing fails. + public static DateTime? ToDateTime(this string str, string fmt) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : default; - /// - /// Converts an enumerable of strings representing date/time values in a specified format to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// - /// The enumerable of strings to convert to DateTime values. - /// The format of the date/time values in the input strings. - /// An containing the parsed DateTime values. - public static IEnumerable ToDateTime(IEnumerable strs, string fmt) + + public static IEnumerable ToDateTime(this IEnumerable strs, string fmt) { if (strs.IsNullOrWhiteSpace()) { @@ -63,26 +41,11 @@ public static partial class YANDateTime } } - /// - /// Parses the string representation of a date and time using . - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The format of the string representation. - /// The default value to return if the parsing fails. - /// The parsed value, or if the parsing fails. + public static DateTime? ToDateTime(this string str, string fmt, DateTime dfltVal) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : dfltVal; - /// - /// Converts an enumerable of strings representing date/time values in a specified format to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// If a string cannot be parsed to a valid DateTime value, the default value specified by is used instead. - /// - /// The enumerable of strings to convert to DateTime values. - /// The format of the date/time values in the input strings. - /// The default DateTime value to be used for strings that cannot be parsed to valid DateTime values. - /// An containing the parsed DateTime values. - public static IEnumerable ToDateTime(IEnumerable strs, string fmt, DateTime dfltVal) + + public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal) { if (strs.IsNullOrWhiteSpace()) { @@ -94,28 +57,10 @@ public static partial class YANDateTime } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . + public static DateTime? GenerateRandomDateTime(DateTime min, DateTime max) => min > max ? default : min.AddTicks(GenerateRandomLong((max - min).Ticks)); - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -124,32 +69,16 @@ public static partial class YANDateTime } } - /// - /// Generates a random value between and . - /// - /// A random value between and . + public static DateTime? GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue); - /// - /// Generates a random value between and . - /// - /// The maximum value. - /// A random value between and . + public static DateTime? GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max); - /// - /// Returns the week of the year that the specified value falls in, according to the current culture's calendar, week rule, and first day of the week settings. - /// - /// The value. - /// The week of the year that the specified value falls in. + public static int? GetWeekOfYear(this DateTime dt) => CurrentInfo.Calendar.GetWeekOfYear(dt, CurrentInfo.CalendarWeekRule, CurrentInfo.FirstDayOfWeek); - /// - /// Gets the week of the year for an enumerable of DateTime values using the default calendar of the current culture. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The enumerable of DateTime values for which to get the week of the year. - /// An containing the week of the year values for the input DateTime values. + public static IEnumerable GetWeekOfYear(this IEnumerable dts) { if (dts is null || !dts.Any()) @@ -162,23 +91,10 @@ public static partial class YANDateTime } } - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. + public static int? TotalMonths(DateTime dt1, DateTime dt2) => Abs((dt1.Year - dt2.Year) * 12 + dt1.Month - dt2.Month); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. + public static DateTime? ChangeTimeZone(this DateTime dt, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { var diff = tzDst.ToInt() - tzSrc.ToInt(); @@ -190,16 +106,7 @@ public static partial class YANDateTime } : default; } - /// - /// Converts an enumerable of DateTime values from one time zone to another using the specified source and destination time zones. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The enumerable of DateTime values to convert. - /// The source time zone to convert from. - /// The destination time zone to convert to. - /// An containing the DateTime values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -212,23 +119,10 @@ public static partial class YANDateTime } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. + public static DateTime? ChangeTimeZone(this DateTime dt, T tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Converts an array of DateTime values from one time zone to another using the specified destination time zone, and returns an containing the DateTime values converted to the destination time zone. - /// Returns an empty sequence if the input array is or empty. - /// - /// The type of the destination time zone. - /// The array of DateTime values to convert. - /// The destination time zone to convert to. - /// An containing the DateTime values converted to the destination time zone. + public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct { if (dts is null || !dts.Any()) diff --git a/lib/YANLib/Nullable/YANNum.Byte.Nullable.cs b/lib/YANLib/Nullable/YANNum.Byte.Nullable.cs index f4708153..8cca8796 100644 --- a/lib/YANLib/Nullable/YANNum.Byte.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Byte.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a byte. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static byte? ToByte(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. public static IEnumerable ToByte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static byte? ToByte(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToByte(dfltVal.Value) : default; - /// - /// Converts an enumerable of string objects to an containing the byte representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The default value to be used for invalid conversions. - /// The enumerable of string objects to be converted. - /// An containing the byte representations of the strings. public static IEnumerable ToByte(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static byte? GenerateRandomByte(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomByte(min.Value, max) : default; - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public static partial class YANNum } } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static byte? GenerateRandomByte(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomByte(min, max.Value) : default; - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public static partial class YANNum } } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static byte? GenerateRandomByte(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomByte(min.Value, max) : default; - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public static partial class YANNum } } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static byte? GenerateRandomByte(T? max) where T : struct => max.HasValue ? GenerateRandomByte(byte.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Byte.cs b/lib/YANLib/Nullable/YANNum.Byte.cs index 690a2858..da91dd0e 100644 --- a/lib/YANLib/Nullable/YANNum.Byte.cs +++ b/lib/YANLib/Nullable/YANNum.Byte.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a byte. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static byte? ToByte(this T num) where T : struct { try @@ -21,16 +15,7 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. + public static IEnumerable ToByte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +28,10 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. + public static byte? ToByte(this string str) => byte.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of string objects to an containing the byte representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// The enumerable of string objects to be converted. - /// An containing the byte representations of the strings. + public static IEnumerable ToByte(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +44,10 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. + public static byte? ToByte(this string str, T dfltVal) where T : struct => byte.TryParse(str, out var num) ? num : dfltVal.ToByte(); - /// - /// Converts an enumerable of string objects to an containing the byte representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The default value to be used for invalid conversions. - /// The enumerable of string objects to be converted. - /// An containing the byte representations of the strings. + public static IEnumerable ToByte(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +60,7 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . + public static byte? GenerateRandomByte(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToByte(); @@ -118,17 +68,7 @@ public static partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().Next(minValue.Value, maxValue.Value).ToByte() : default; } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . + public static IEnumerable GenerateRandomBytes(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +77,9 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . + public static byte? GenerateRandomByte() => GenerateRandomByte(byte.MinValue, byte.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . + public static byte? GenerateRandomByte(T max) where T : struct => GenerateRandomByte(byte.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Decimal.Nullable.cs b/lib/YANLib/Nullable/YANNum.Decimal.Nullable.cs index 384b248c..c2a45307 100644 --- a/lib/YANLib/Nullable/YANNum.Decimal.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Decimal.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a decimal. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static decimal? ToDecimal(this T? num) where T : struct { try @@ -21,15 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of values of a generic value type to an containing the decimal representations of the values. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the values to be converted, which must be a value type. - /// - /// The enumerable of values to be converted. - /// An containing the decimal representations of the values. public static IEnumerable ToDecimal(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -42,27 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a decimal using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static decimal? ToDecimal(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToDecimal(dfltVal.Value) : default; - /// - /// Converts an enumerable of string objects to an containing the decimal representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The default value to be used for invalid conversions. - /// The enumerable of string objects to be converted. - /// An containing the decimal representations of the strings. public static IEnumerable ToDecimal(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -75,27 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal? GenerateRandomDecimal(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDecimal(min.Value, max) : default; - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -104,16 +51,6 @@ public partial class YANNum } } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -122,27 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal? GenerateRandomDecimal(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomDecimal(min, max.Value) : default; - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -151,16 +69,6 @@ public partial class YANNum } } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -169,27 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal? GenerateRandomDecimal(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDecimal(min.Value, max) : default; - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -198,16 +87,6 @@ public partial class YANNum } } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -216,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static decimal? GenerateRandomDecimal(T? max) where T : struct => max.HasValue ? GenerateRandomDecimal(decimal.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Decimal.cs b/lib/YANLib/Nullable/YANNum.Decimal.cs index bd2bbeb4..89645441 100644 --- a/lib/YANLib/Nullable/YANNum.Decimal.cs +++ b/lib/YANLib/Nullable/YANNum.Decimal.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a decimal. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static decimal? ToDecimal(this T num) where T : struct { try @@ -21,15 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of values of a generic value type to an containing the decimal representations of the values. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the values to be converted, which must be a value type. - /// - /// The enumerable of values to be converted. - /// An containing the decimal representations of the values. public static IEnumerable ToDecimal(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -42,20 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a decimal using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static decimal? ToDecimal(this string str) => decimal.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of string objects to an containing the decimal representations of the strings. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The enumerable of string objects to be converted. - /// An containing the decimal representations of the strings. public static IEnumerable ToDecimal(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -68,27 +41,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a decimal using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static decimal? ToDecimal(this string str, T dfltVal) where T : struct => decimal.TryParse(str, out var num) ? num : dfltVal.ToDecimal(); - /// - /// Converts an enumerable of string objects to an containing the decimal representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The default value to be used for invalid conversions. - /// The enumerable of string objects to be converted. - /// An containing the decimal representations of the strings. public static IEnumerable ToDecimal(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -101,15 +55,6 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal? GenerateRandomDecimal(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToDecimal(); @@ -117,16 +62,6 @@ public partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().NextDecimal(minValue.Value, maxValue.Value) : default; } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -135,17 +70,7 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static decimal? GenerateRandomDecimal() => GenerateRandomDecimal(decimal.MinValue, decimal.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static decimal? GenerateRandomDecimal(T max) where T : struct => GenerateRandomDecimal(decimal.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Double.Nullable.cs b/lib/YANLib/Nullable/YANNum.Double.Nullable.cs index ffa69186..992d3e74 100644 --- a/lib/YANLib/Nullable/YANNum.Double.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Double.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a double. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static double? ToDouble(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the double representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the double representations of the objects. public static IEnumerable ToDouble(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a double using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static double? ToDouble(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToDouble(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the double representations of the strings, using a default value for conversion failures. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failures. - /// Must be a value type. - /// - /// The default value to use for conversion failures. - /// The enumerable of strings to be converted. - /// An containing the double representations of the strings. public static IEnumerable ToDouble(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double? GenerateRandomDouble(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDouble(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double? GenerateRandomDouble(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomDouble(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double? GenerateRandomDouble(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDouble(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static double? GenerateRandomDouble(T? max) where T : struct => max.HasValue ? GenerateRandomDouble(double.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Double.cs b/lib/YANLib/Nullable/YANNum.Double.cs index ac66bd60..ecde846c 100644 --- a/lib/YANLib/Nullable/YANNum.Double.cs +++ b/lib/YANLib/Nullable/YANNum.Double.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a double. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static double? ToDouble(this T num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the double representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the double representations of the objects. public static IEnumerable ToDouble(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a double using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static double? ToDouble(this string str) => double.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the double representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the double representations of the strings. public static IEnumerable ToDouble(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a double using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static double? ToDouble(this string str, T dfltVal) where T : struct => double.TryParse(str, out var num) ? num : dfltVal.ToDouble(); - /// - /// Converts an enumerable of strings to an containing the double representations of the strings, using a default value for conversion failures. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failures. - /// Must be a value type. - /// - /// The default value to use for conversion failures. - /// The enumerable of strings to be converted. - /// An containing the double representations of the strings. public static IEnumerable ToDouble(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double? GenerateRandomDouble(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToDouble(); @@ -118,17 +62,6 @@ public partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().NextDouble(minValue.Value, maxValue.Value) : default; } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +70,7 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static double? GenerateRandomDouble() => GenerateRandomDouble(double.MinValue, double.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static double? GenerateRandomDouble(T max) where T : struct => GenerateRandomDouble(double.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Float.Nullable.cs b/lib/YANLib/Nullable/YANNum.Float.Nullable.cs index aac5dacb..898ac12f 100644 --- a/lib/YANLib/Nullable/YANNum.Float.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Float.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a single-precision floating-point number. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static float? ToFloat(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the float representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the float representations of the objects. public static IEnumerable ToFloat(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a float using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static float? ToFloat(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToFloat(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the float representations of the strings, using a default value for parsing invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for parsing invalid or null strings. - /// Must be a value type. - /// - /// The default value to be used for parsing invalid or null strings. - /// The enumerable of strings to be converted to float. - /// An containing the float representations of the strings. public static IEnumerable ToFloat(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float? GenerateRandomFloat(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomFloat(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float? GenerateRandomFloat(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomFloat(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float? GenerateRandomFloat(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomFloat(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static float? GenerateRandomFloat(T? max) where T : struct => max.HasValue ? GenerateRandomFloat(float.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Float.cs b/lib/YANLib/Nullable/YANNum.Float.cs index 80a5bf0f..477a6b86 100644 --- a/lib/YANLib/Nullable/YANNum.Float.cs +++ b/lib/YANLib/Nullable/YANNum.Float.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a single-precision floating-point number. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static float? ToFloat(this T num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the float representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the float representations of the objects. public static IEnumerable ToFloat(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static float? ToFloat(this string str) => float.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the float representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted to float. - /// An containing the float representations of the strings. public static IEnumerable ToFloat(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a float using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static float? ToFloat(this string str, T dfltVal) where T : struct => float.TryParse(str, out var num) ? num : dfltVal.ToFloat(); - /// - /// Converts an enumerable of strings to an containing the float representations of the strings, using a default value for parsing invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for parsing invalid or null strings. - /// Must be a value type. - /// - /// The default value to be used for parsing invalid or null strings. - /// The enumerable of strings to be converted to float. - /// An containing the float representations of the strings. public static IEnumerable ToFloat(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float? GenerateRandomFloat(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToFloat(); @@ -118,17 +62,6 @@ public partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().NextSingle(minValue.Value, maxValue.Value) : default; } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +70,7 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static float? GenerateRandomFloat() => GenerateRandomFloat(float.MinValue, float.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static float? GenerateRandomFloat(T max) where T : struct => GenerateRandomFloat(float.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Int.Nullable.cs b/lib/YANLib/Nullable/YANNum.Int.Nullable.cs index 1fac46ac..d8c00828 100644 --- a/lib/YANLib/Nullable/YANNum.Int.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Int.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to an integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static int? ToInt(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the integer representations of the objects. public static IEnumerable ToInt(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of an integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static int? ToInt(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToInt(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the integer representations of the strings, using the specified default value for parsing strings that cannot be converted to integers. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for parsing strings that cannot be converted to integers. - /// Must be a value type. - /// - /// The default value to be used for parsing strings that cannot be converted to integers. - /// The enumerable of strings to be converted. - /// An containing the integer representations of the strings. public static IEnumerable ToInt(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int? GenerateRandomInt(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomInt(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int? GenerateRandomInt(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomInt(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int? GenerateRandomInt(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomInt(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static int? GenerateRandomInt(T? max) where T : struct => max.HasValue ? GenerateRandomInt(int.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Int.cs b/lib/YANLib/Nullable/YANNum.Int.cs index 6f3620d5..9308ae18 100644 --- a/lib/YANLib/Nullable/YANNum.Int.cs +++ b/lib/YANLib/Nullable/YANNum.Int.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to an integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static int? ToInt(this T num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the integer representations of the objects. public static IEnumerable ToInt(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of an integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static int? ToInt(this string str) => int.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the integer representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the integer representations of the strings. public static IEnumerable ToInt(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of an integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static int? ToInt(this string str, T dfltVal) where T : struct => int.TryParse(str, out var num) ? num : dfltVal.ToInt(); - /// - /// Converts an enumerable of strings to an containing the integer representations of the strings, using the specified default value for parsing strings that cannot be converted to integers. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for parsing strings that cannot be converted to integers. - /// Must be a value type. - /// - /// The default value to be used for parsing strings that cannot be converted to integers. - /// The enumerable of strings to be converted. - /// An containing the integer representations of the strings. public static IEnumerable ToInt(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int? GenerateRandomInt(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToInt(); @@ -118,17 +62,6 @@ public partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().Next(minValue.Value, maxValue.Value) : default; } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +70,7 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static int? GenerateRandomInt() => GenerateRandomInt(int.MinValue, int.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static int? GenerateRandomInt(T max) where T : struct => GenerateRandomInt(int.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Long.Nullable.cs b/lib/YANLib/Nullable/YANNum.Long.Nullable.cs index 911d7c14..9eb44daa 100644 --- a/lib/YANLib/Nullable/YANNum.Long.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Long.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static long? ToLong(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the long integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the long integer representations of the objects. public static IEnumerable ToLong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a long using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static long? ToLong(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToLong(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the long integer representations of the strings, using a default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The default value to be used for invalid or null strings. - /// The enumerable of strings to be converted. - /// An containing the long integer representations of the strings. public static IEnumerable ToLong(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long? GenerateRandomLong(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomLong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long? GenerateRandomLong(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomLong(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long? GenerateRandomLong(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomLong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static long? GenerateRandomLong(T? max) where T : struct => max.HasValue ? GenerateRandomLong(long.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Long.cs b/lib/YANLib/Nullable/YANNum.Long.cs index ea15b879..f5568593 100644 --- a/lib/YANLib/Nullable/YANNum.Long.cs +++ b/lib/YANLib/Nullable/YANNum.Long.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static long? ToLong(this T num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the long integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the long integer representations of the objects. public static IEnumerable ToLong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a long using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static long? ToLong(this string str) => long.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the long integer representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the long integer representations of the strings. public static IEnumerable ToLong(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a long using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static long? ToLong(this string str, T dfltVal) where T : struct => long.TryParse(str, out var num) ? num : dfltVal.ToLong(); - /// - /// Converts an enumerable of strings to an containing the long integer representations of the strings, using a default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The default value to be used for invalid or null strings. - /// The enumerable of strings to be converted. - /// An containing the long integer representations of the strings. public static IEnumerable ToLong(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long? GenerateRandomLong(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToLong(); @@ -118,17 +62,6 @@ public partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().NextInt64(minValue.Value, maxValue.Value) : default; } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +70,7 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static long? GenerateRandomLong() => GenerateRandomLong(long.MinValue, long.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static long? GenerateRandomLong(T max) where T : struct => GenerateRandomLong(long.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Nint.Nullable.cs b/lib/YANLib/Nullable/YANNum.Nint.Nullable.cs index b133ce36..508465a5 100644 --- a/lib/YANLib/Nullable/YANNum.Nint.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Nint.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a native integer (nint). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nint? ToNint(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the nint representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the nint representations of the objects. public static IEnumerable ToNint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,30 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a pointer-sized signed integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nint? ToNint(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToNint(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the nint representations of the strings, with an optional default value for conversion. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion. - /// Must be a value type. - /// - /// - /// The default value for conversion if a string cannot be parsed to nint. - /// Used when conversion fails for a particular string. - /// - /// The enumerable of strings to be converted. - /// An containing the nint representations of the strings. public static IEnumerable ToNint(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -79,28 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint? GenerateRandomNint(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -109,17 +51,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -128,28 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint? GenerateRandomNint(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomNint(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -158,17 +69,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -177,28 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint? GenerateRandomNint(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -207,17 +87,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -226,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nint? GenerateRandomNint(T? max) where T : struct => max.HasValue ? GenerateRandomNint(nint.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Nint.cs b/lib/YANLib/Nullable/YANNum.Nint.cs index d8d2b4fb..a0e8ffd4 100644 --- a/lib/YANLib/Nullable/YANNum.Nint.cs +++ b/lib/YANLib/Nullable/YANNum.Nint.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a native integer (nint). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nint? ToNint(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the nint representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the nint representations of the objects. public static IEnumerable ToNint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a nint using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static nint? ToNint(this string str) => nint.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the nint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the nint representations of the strings. public static IEnumerable ToNint(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,30 +41,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a nint using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nint? ToNint(this string str, T dfltVal) where T : struct => nint.TryParse(str, out var num) ? num : dfltVal.ToNint(); - /// - /// Converts an enumerable of strings to an containing the nint representations of the strings, with an optional default value for conversion. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion. - /// Must be a value type. - /// - /// - /// The default value for conversion if a string cannot be parsed to nint. - /// Used when conversion fails for a particular string. - /// - /// The enumerable of strings to be converted. - /// An containing the nint representations of the strings. public static IEnumerable ToNint(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -105,15 +55,6 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint? GenerateRandomNint(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToNint(); @@ -121,17 +62,6 @@ public static partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().NextInt64(minValue.Value, maxValue.Value).ToNint() : default; } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -140,17 +70,7 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static nint? GenerateRandomNint() => GenerateRandomNint(nint.MinValue, nint.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nint? GenerateRandomNint(T max) where T : struct => GenerateRandomNint(nint.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Nuint.Nullable.cs b/lib/YANLib/Nullable/YANNum.Nuint.Nullable.cs index 55923c27..ad04c1c9 100644 --- a/lib/YANLib/Nullable/YANNum.Nuint.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Nuint.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a (an unsigned integer type representing a pointer or a handle). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nuint? ToNuint(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an enumerable of values, which represent the unsigned integer equivalent of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the objects. public static IEnumerable ToNuint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nuint? ToNuint(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToNuint(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an enumerable of values, which represent the unsigned integer equivalent of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for conversion. - /// Must be a value type. - /// - /// The default value to be used for conversion in case of failure. - /// The enumerable of strings to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the strings. public static IEnumerable ToNuint(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint? GenerateRandomNuint(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNuint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint? GenerateRandomNuint(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomNuint(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint? GenerateRandomNuint(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNuint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nuint? GenerateRandomNuint(T? max) where T : struct => max.HasValue ? GenerateRandomNuint(nuint.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Nuint.cs b/lib/YANLib/Nullable/YANNum.Nuint.cs index f8bc90bf..190b6a0e 100644 --- a/lib/YANLib/Nullable/YANNum.Nuint.cs +++ b/lib/YANLib/Nullable/YANNum.Nuint.cs @@ -4,13 +4,7 @@ namespace YANLib.Nullable; public static partial class YANNum { - /// - /// Converts the specified value to a (an unsigned integer type representing a pointer or a handle). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nuint? ToNuint(this T num) where T : struct { try @@ -23,16 +17,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an enumerable of values, which represent the unsigned integer equivalent of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the objects. public static IEnumerable ToNuint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -45,20 +29,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static nuint? ToNuint(this string str) => nuint.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an enumerable of values, which represent the unsigned integer equivalent of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// The enumerable of strings to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the strings. public static IEnumerable ToNuint(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -71,27 +43,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nuint? ToNuint(this string str, T dfltVal) where T : struct => nuint.TryParse(str, out var num) ? num : dfltVal.ToNuint(); - /// - /// Converts an enumerable of strings to an enumerable of values, which represent the unsigned integer equivalent of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for conversion. - /// Must be a value type. - /// - /// The default value to be used for conversion in case of failure. - /// The enumerable of strings to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the strings. public static IEnumerable ToNuint(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -104,15 +57,6 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint? GenerateRandomNuint(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToNuint(); @@ -120,17 +64,6 @@ public static partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : (new Random().NextInt64(nint.MinValue, (long)(maxValue - (minValue - (BigInteger)nint.MinValue))) - nint.MinValue).ToNuint() + minValue : default; } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -139,17 +72,7 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static nuint? GenerateRandomNuint() => GenerateRandomNuint(nuint.MinValue, nuint.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nuint? GenerateRandomNuint(T max) where T : struct => GenerateRandomNuint(nuint.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Sbyte.Nullable.cs b/lib/YANLib/Nullable/YANNum.Sbyte.Nullable.cs index 78b1aa7b..b5a76ee1 100644 --- a/lib/YANLib/Nullable/YANNum.Sbyte.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Sbyte.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a signed byte (sbyte). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static sbyte? ToSbyte(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the signed byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the signed byte representations of the objects. public static IEnumerable ToSbyte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of an using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static sbyte? ToSbyte(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToSbyte(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the signed byte representations of the strings, using the specified default value for invalid string representations. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid string representations. - /// Must be a value type. - /// - /// The default value to be used for invalid string representations. - /// The enumerable of strings to be converted. - /// An containing the signed byte representations of the strings. public static IEnumerable ToSbyte(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte? GenerateRandomSbyte(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomSbyte(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte? GenerateRandomSbyte(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomSbyte(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte? GenerateRandomSbyte(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomSbyte(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static sbyte? GenerateRandomSbyte(T? max) where T : struct => max.HasValue ? GenerateRandomSbyte(sbyte.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Sbyte.cs b/lib/YANLib/Nullable/YANNum.Sbyte.cs index 518c3b51..6f88353e 100644 --- a/lib/YANLib/Nullable/YANNum.Sbyte.cs +++ b/lib/YANLib/Nullable/YANNum.Sbyte.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a signed byte (sbyte). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static sbyte? ToSbyte(this T num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the signed byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the signed byte representations of the objects. public static IEnumerable ToSbyte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a signed byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static sbyte? ToSbyte(this string str) => sbyte.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the signed byte representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the signed byte representations of the strings. public static IEnumerable ToSbyte(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a signed byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static sbyte? ToSbyte(this string str, T dfltVal) where T : struct => sbyte.TryParse(str, out var num) ? num : dfltVal.ToSbyte(); - /// - /// Converts an enumerable of strings to an containing the signed byte representations of the strings, using the specified default value for invalid string representations. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid string representations. - /// Must be a value type. - /// - /// The default value to be used for invalid string representations. - /// The enumerable of strings to be converted. - /// An containing the signed byte representations of the strings. public static IEnumerable ToSbyte(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte? GenerateRandomSbyte(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToSbyte(); @@ -118,17 +62,6 @@ public partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().Next(minValue.Value, maxValue.Value).ToSbyte() : default; } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +70,7 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static sbyte? GenerateRandomSbyte() => GenerateRandomSbyte(sbyte.MinValue, sbyte.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static sbyte? GenerateRandomSbyte(T max) where T : struct => GenerateRandomSbyte(sbyte.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Short.Nullable.cs b/lib/YANLib/Nullable/YANNum.Short.Nullable.cs index 56e9520d..57536e74 100644 --- a/lib/YANLib/Nullable/YANNum.Short.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Short.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a . - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static short? ToShort(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the short integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the short integer representations of the objects. public static IEnumerable ToShort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a short using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static short? ToShort(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToShort(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the short integer representations of the strings, using the specified default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The default value to be used for invalid or null strings. - /// The enumerable of strings to be converted. - /// An containing the short integer representations of the strings. public static IEnumerable ToShort(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short? GenerateRandomShort(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomShort(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short? GenerateRandomShort(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomShort(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short? GenerateRandomShort(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomShort(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public partial class YANNum } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static short? GenerateRandomShort(T? max) where T : struct => max.HasValue ? GenerateRandomShort(short.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Short.cs b/lib/YANLib/Nullable/YANNum.Short.cs index dfccec92..fd404513 100644 --- a/lib/YANLib/Nullable/YANNum.Short.cs +++ b/lib/YANLib/Nullable/YANNum.Short.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a . - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static short? ToShort(this T num) where T : struct { try @@ -21,16 +15,6 @@ public partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the short integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the short integer representations of the objects. public static IEnumerable ToShort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a short integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static short? ToShort(this string str) => short.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the short integer representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the short integer representations of the strings. public static IEnumerable ToShort(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public partial class YANNum } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static short? ToShort(this string str, T dfltVal) where T : struct => short.TryParse(str, out var num) ? num : dfltVal.ToShort(); - /// - /// Converts an enumerable of strings to an containing the short integer representations of the strings, using the specified default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The default value to be used for invalid or null strings. - /// The enumerable of strings to be converted. - /// An containing the short integer representations of the strings. public static IEnumerable ToShort(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short? GenerateRandomShort(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToShort(); @@ -118,17 +62,6 @@ public partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().Next(minValue.Value, maxValue.Value).ToShort() : default; } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +70,7 @@ public partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static short? GenerateRandomShort() => GenerateRandomShort(short.MinValue, short.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static short? GenerateRandomShort(T max) where T : struct => GenerateRandomShort(short.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Uint.Nullable.cs b/lib/YANLib/Nullable/YANNum.Uint.Nullable.cs index 8847330b..ab69bd24 100644 --- a/lib/YANLib/Nullable/YANNum.Uint.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Uint.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to an unsigned integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static uint? ToUint(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. public static IEnumerable ToUint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an unsigned integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static uint? ToUint(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToUint(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the uint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for the conversion to uint. - /// Must be a value type. - /// - /// The default value for the conversion to uint. - /// The enumerable of strings to be converted. - /// An containing the uint representations of the strings. public static IEnumerable ToUint(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,29 +41,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint? GenerateRandomUint(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -107,18 +51,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -127,29 +59,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint? GenerateRandomUint(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomUint(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -158,18 +69,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -178,29 +77,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint? GenerateRandomUint(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -209,18 +87,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -229,11 +95,5 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static uint? GenerateRandomUint(T? max) where T : struct => max.HasValue ? GenerateRandomUint(uint.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Uint.cs b/lib/YANLib/Nullable/YANNum.Uint.cs index 9f28576e..ac00ebec 100644 --- a/lib/YANLib/Nullable/YANNum.Uint.cs +++ b/lib/YANLib/Nullable/YANNum.Uint.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to an unsigned integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static uint? ToUint(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. public static IEnumerable ToUint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an unsigned integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static uint? ToUint(this string str) => uint.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the uint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the uint representations of the strings. public static IEnumerable ToUint(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an unsigned integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static uint? ToUint(this string str, T dfltVal) where T : struct => uint.TryParse(str, out var num) ? num : dfltVal.ToUint(); - /// - /// Converts an enumerable of strings to an containing the uint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for the conversion to uint. - /// Must be a value type. - /// - /// The default value for the conversion to uint. - /// The enumerable of strings to be converted. - /// An containing the uint representations of the strings. public static IEnumerable ToUint(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint? GenerateRandomUint(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToUint(); @@ -118,18 +62,6 @@ public static partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().NextInt64(minValue.Value, maxValue.Value).ToUint() : default; } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -138,17 +70,7 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static uint? GenerateRandomUint() => GenerateRandomUint(uint.MinValue, uint.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static uint? GenerateRandomUint(T max) where T : struct => GenerateRandomUint(uint.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Ulong.Nullable.cs b/lib/YANLib/Nullable/YANNum.Ulong.Nullable.cs index 04d9e375..173201d4 100644 --- a/lib/YANLib/Nullable/YANNum.Ulong.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Ulong.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to an unsigned long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ulong? ToUlong(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ulong representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ulong representations of the objects. public static IEnumerable ToUlong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an unsigned long integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ulong? ToUlong(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToUlong(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the ulong representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used when converting strings to ulong. - /// Must be a value type. - /// - /// The default value to be used when converting strings to ulong. - /// The enumerable of strings to be converted. - /// An containing the ulong representations of the strings. public static IEnumerable ToUlong(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,29 +41,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong? GenerateRandomUlong(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUlong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -107,18 +51,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -127,29 +59,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong? GenerateRandomUlong(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomUlong(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -158,18 +69,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -178,29 +77,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong? GenerateRandomUlong(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUlong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -209,18 +87,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -229,11 +95,5 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ulong? GenerateRandomUlong(T? max) where T : struct => max.HasValue ? GenerateRandomUlong(ulong.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Ulong.cs b/lib/YANLib/Nullable/YANNum.Ulong.cs index 341a82ae..dafc5b12 100644 --- a/lib/YANLib/Nullable/YANNum.Ulong.cs +++ b/lib/YANLib/Nullable/YANNum.Ulong.cs @@ -4,13 +4,7 @@ namespace YANLib.Nullable; public static partial class YANNum { - /// - /// Converts the specified value to an unsigned long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ulong? ToUlong(this T num) where T : struct { try @@ -23,16 +17,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ulong representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ulong representations of the objects. public static IEnumerable ToUlong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -45,20 +29,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an unsigned long integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static ulong? ToUlong(this string str) => ulong.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the ulong representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the ulong representations of the strings. public static IEnumerable ToUlong(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -71,27 +43,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ulong? ToUlong(this string str, T dfltVal) where T : struct => ulong.TryParse(str, out var num) ? num : dfltVal.ToUlong(); - /// - /// Converts an enumerable of strings to an containing the ulong representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used when converting strings to ulong. - /// Must be a value type. - /// - /// The default value to be used when converting strings to ulong. - /// The enumerable of strings to be converted. - /// An containing the ulong representations of the strings. public static IEnumerable ToUlong(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -104,15 +57,6 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong? GenerateRandomUlong(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToUlong(); @@ -120,18 +64,6 @@ public static partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : (new Random().NextInt64(long.MinValue, (long)(maxValue - (minValue - (BigInteger)long.MinValue))) - long.MinValue).ToUlong() + minValue : default; } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -140,17 +72,7 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static ulong? GenerateRandomUlong() => GenerateRandomUlong(ulong.MinValue, ulong.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ulong? GenerateRandomUlong(T max) where T : struct => GenerateRandomUlong(ulong.MinValue, max); } diff --git a/lib/YANLib/Nullable/YANNum.Ushort.Nullable.cs b/lib/YANLib/Nullable/YANNum.Ushort.Nullable.cs index 5331aee4..945162b3 100644 --- a/lib/YANLib/Nullable/YANNum.Ushort.Nullable.cs +++ b/lib/YANLib/Nullable/YANNum.Ushort.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a unsigned short integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ushort? ToUshort(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ushort representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ushort representations of the objects. public static IEnumerable ToUshort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of a ushort using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ushort? ToUshort(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToUshort(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the ushort representations of the strings, using the specified default value for conversion failure. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failure. - /// Must be a value type. - /// - /// The default value to be used for conversion failure. - /// The enumerable of strings to be converted. - /// An containing the ushort representations of the strings. public static IEnumerable ToUshort(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort? GenerateRandomUshort(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUshort(min.Value, max) : default; - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -106,17 +51,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -125,28 +59,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort? GenerateRandomUshort(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomUshort(min, max.Value) : default; - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -155,17 +69,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -174,28 +77,8 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort? GenerateRandomUshort(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUshort(min.Value, max) : default; - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -204,17 +87,6 @@ public static partial class YANNum } } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -223,11 +95,5 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ushort? GenerateRandomUshort(T? max) where T : struct => max.HasValue ? GenerateRandomUshort(ushort.MinValue, max.Value) : default; } diff --git a/lib/YANLib/Nullable/YANNum.Ushort.cs b/lib/YANLib/Nullable/YANNum.Ushort.cs index 963493e5..8e05a6b7 100644 --- a/lib/YANLib/Nullable/YANNum.Ushort.cs +++ b/lib/YANLib/Nullable/YANNum.Ushort.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a unsigned short integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ushort? ToUshort(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static partial class YANNum } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ushort representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ushort representations of the objects. public static IEnumerable ToUshort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an unsigned short integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static ushort? ToUshort(this string str) => ushort.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the ushort representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the ushort representations of the strings. public static IEnumerable ToUshort(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static partial class YANNum } } - /// - /// Parses the string representation of an unsigned short using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ushort? ToUshort(this string str, T dfltVal) where T : struct => ushort.TryParse(str, out var num) ? num : dfltVal.ToUshort(); - /// - /// Converts an enumerable of strings to an containing the ushort representations of the strings, using the specified default value for conversion failure. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failure. - /// Must be a value type. - /// - /// The default value to be used for conversion failure. - /// The enumerable of strings to be converted. - /// An containing the ushort representations of the strings. public static IEnumerable ToUshort(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort? GenerateRandomUshort(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToUshort(); @@ -118,17 +62,6 @@ public static partial class YANNum return minValue.HasValue && maxValue.HasValue ? minValue > maxValue ? default : new Random().Next(minValue.Value, maxValue.Value).ToUshort() : default; } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < YANLib.YANNum.ToUlong(size); i++) @@ -137,17 +70,7 @@ public static partial class YANNum } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static ushort? GenerateRandomUshort() => GenerateRandomUshort(ushort.MinValue, ushort.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ushort? GenerateRandomUshort(T max) where T : struct => GenerateRandomUshort(ushort.MinValue, max); } diff --git a/lib/YANLib/YANDateTime.Nullable.cs b/lib/YANLib/YANDateTime.Nullable.cs index ad1987a7..4cf2d76f 100644 --- a/lib/YANLib/YANDateTime.Nullable.cs +++ b/lib/YANLib/YANDateTime.Nullable.cs @@ -4,26 +4,10 @@ namespace YANLib; public static partial class YANDateTime { - /// - /// Parses the string representation of a date and time using . - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The format of the string representation. - /// The default value to return if the parsing fails. - /// The parsed value, or if the parsing fails. + public static DateTime ToDateTime(this string str, string fmt, DateTime? dfltVal) => dfltVal.HasValue ? str.ToDateTime(fmt, dfltVal.Value) : default; - /// - /// Converts an enumerable of strings representing date/time values in a specified format to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// If a string cannot be parsed to a valid DateTime value, the default value specified by is used instead. - /// - /// The enumerable of strings to convert to DateTime values. - /// The format of the date/time values in the input strings. - /// The default DateTime value to be used for strings that cannot be parsed to valid DateTime values. - /// An containing the parsed DateTime values. - public static IEnumerable ToDateTime(IEnumerable strs, string fmt, DateTime? dfltVal) + public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal) { if (strs.IsNullOrWhiteSpace()) { @@ -35,28 +19,8 @@ public static IEnumerable ToDateTime(IEnumerable strs, string } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime? min, DateTime max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : default; - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -65,19 +29,6 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -86,28 +37,8 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default; - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -116,19 +47,6 @@ public static IEnumerable GenerateRandomDateTimes(DateTime min, Dat } } - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T? size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,28 +55,8 @@ public static IEnumerable GenerateRandomDateTimes(DateTime min, Dat } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max); - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -167,19 +65,6 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -188,26 +73,10 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - /// - /// Generates a random value between and . - /// - /// The maximum value. - /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default; - /// - /// Returns the week of the year that the specified value falls in, according to the current culture's calendar, week rule, and first day of the week settings. - /// - /// The value. - /// The week of the year that the specified value falls in. public static int GetWeekOfYear(this DateTime? dt) => dt.HasValue ? dt.Value.GetWeekOfYear() : default; - /// - /// Gets the week of the year for an enumerable of DateTime values using the default calendar of the current culture. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The enumerable of DateTime values for which to get the week of the year. - /// An containing the week of the year values for the input DateTime values. public static IEnumerable GetWeekOfYear(this IEnumerable dts) { if (dts is null || !dts.Any()) @@ -220,52 +89,14 @@ public static IEnumerable GetWeekOfYear(this IEnumerable dts) } } - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. public static int TotalMonths(DateTime? dt1, DateTime dt2) => dt1.HasValue ? TotalMonths(dt1.Value, dt2) : default; - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. public static int TotalMonths(DateTime dt1, DateTime? dt2) => dt2.HasValue ? TotalMonths(dt1, dt2.Value) : default; - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. public static int TotalMonths(DateTime? dt1, DateTime? dt2) => dt1.HasValue ? TotalMonths(dt1.Value, dt2) : default; - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime? dt, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The values to convert to the destination time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -278,15 +109,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -298,28 +120,8 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime dt, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => tzSrc.HasValue ? dt.ChangeTimeZone(tzSrc.Value, tzDst) : dt.ChangeTimeZone(tzDst); - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The values to convert to the destination time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -332,15 +134,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -352,28 +145,8 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime dt, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => tzDst.HasValue ? dt.ChangeTimeZone(tzSrc, tzDst.Value) : dt; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The values to convert to the destination time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -386,15 +159,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -406,28 +170,8 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2 } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime? dt, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The values to convert to the destination time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -440,15 +184,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -460,28 +195,8 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime? dt, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The values to convert to the destination time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -494,15 +209,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -514,28 +220,8 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime dt, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => tzSrc.HasValue ? dt.ChangeTimeZone(tzSrc.Value, tzDst) : dt.ChangeTimeZone(tzDst); - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The values to convert to the destination time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -548,15 +234,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -568,28 +245,8 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime? dt, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default; - /// - /// Returns an containing the values converted to a different time zone, based on the source and destination time zones specified. - /// The source and destination time zones are specified as generic type parameters and respectively, and must be of a struct type that represents a valid time zone identifier. - /// If any of the input values is , no value will be returned for that input. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The values to convert to the destination time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -602,15 +259,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -622,22 +270,8 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. public static DateTime ChangeTimeZone(this DateTime? dt, T tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct { if (dts is null || !dts.Any()) @@ -650,13 +284,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts a list of DateTime values from one time zone to another using the specified destination time zone, and updates the original list in place with the DateTime values converted to the destination time zone. - /// If the input list is or empty, no changes will be made. - /// - /// The type of the destination time zone. - /// The list of DateTime values to convert. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T tzDst) where T : struct { if (dts is not null && dts.Count > 0) @@ -668,22 +295,8 @@ public static void ChangeTimeZone(this IList dts, T tzDst) where T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. public static DateTime ChangeTimeZone(this DateTime dt, T? tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct { if (dts is null || !dts.Any()) @@ -696,13 +309,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable } } - /// - /// Converts a list of DateTime values from one time zone to another using the specified destination time zone, and updates the original list in place with the DateTime values converted to the destination time zone. - /// If the input list is or empty, no changes will be made. - /// - /// The type of the destination time zone. - /// The list of DateTime values to convert. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T? tzDst) where T : struct { if (dts is not null && dts.Count > 0) @@ -714,22 +320,8 @@ public static void ChangeTimeZone(this IList dts, T? tzDst) where T } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. public static DateTime ChangeTimeZone(this DateTime? dt, T? tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct { if (dts is null || !dts.Any()) @@ -742,13 +334,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts a list of DateTime values from one time zone to another using the specified destination time zone, and updates the original list in place with the DateTime values converted to the destination time zone. - /// If the input list is or empty, no changes will be made. - /// - /// The type of the destination time zone. - /// The list of DateTime values to convert. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T? tzDst) where T : struct { if (dts is not null && dts.Count > 0) diff --git a/lib/YANLib/YANDateTime.cs b/lib/YANLib/YANDateTime.cs index ab847554..c4b3c845 100644 --- a/lib/YANLib/YANDateTime.cs +++ b/lib/YANLib/YANDateTime.cs @@ -9,21 +9,10 @@ namespace YANLib; public static partial class YANDateTime { - /// - /// Parses the string representation of a date and time using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. + public static DateTime ToDateTime(this string str) => TryParse(str, out var dt) ? dt : default; - /// - /// Converts an enumerable of strings representing date/time values to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// - /// The enumerable of strings to convert to DateTime values. - /// An containing the parsed DateTime values. - public static IEnumerable ToDateTime(IEnumerable strs) + public static IEnumerable ToDateTime(this IEnumerable strs) { if (strs.IsNullOrWhiteSpace()) { @@ -35,23 +24,9 @@ public static IEnumerable ToDateTime(IEnumerable strs) } } - /// - /// Parses the string representation of a date and time using . - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The format of the string representation. - /// The parsed value, or if the parsing fails. public static DateTime ToDateTime(this string str, string fmt) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : default; - /// - /// Converts an enumerable of strings representing date/time values in a specified format to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// - /// The enumerable of strings to convert to DateTime values. - /// The format of the date/time values in the input strings. - /// An containing the parsed DateTime values. - public static IEnumerable ToDateTime(IEnumerable strs, string fmt) + public static IEnumerable ToDateTime(this IEnumerable strs, string fmt) { if (strs.IsNullOrWhiteSpace()) { @@ -63,26 +38,9 @@ public static IEnumerable ToDateTime(IEnumerable strs, string } } - /// - /// Parses the string representation of a date and time using . - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The format of the string representation. - /// The default value to return if the parsing fails. - /// The parsed value, or if the parsing fails. public static DateTime ToDateTime(this string str, string fmt, DateTime dfltVal) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : dfltVal; - /// - /// Converts an enumerable of strings representing date/time values in a specified format to an containing the parsed DateTime values. - /// Returns an empty sequence if the input enumerable is , empty, or contains only whitespace strings. - /// If a string cannot be parsed to a valid DateTime value, the default value specified by is used instead. - /// - /// The enumerable of strings to convert to DateTime values. - /// The format of the date/time values in the input strings. - /// The default DateTime value to be used for strings that cannot be parsed to valid DateTime values. - /// An containing the parsed DateTime values. - public static IEnumerable ToDateTime(IEnumerable strs, string fmt, DateTime dfltVal) + public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal) { if (strs.IsNullOrWhiteSpace()) { @@ -94,28 +52,8 @@ public static IEnumerable ToDateTime(IEnumerable strs, string } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The minimum value. - /// The maximum value. - /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime min, DateTime max) => min > max ? default : min.AddTicks(GenerateRandomLong((max - min).Ticks)); - /// - /// Generates an containing random DateTime values between and . - /// The number of DateTime values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// - /// The type of . - /// Must be a value type. - /// - /// The minimum DateTime value. - /// The maximum DateTime value. - /// The number of DateTime values to generate. - /// An containing random DateTime values between and . public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime max, T size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -124,32 +62,12 @@ public static IEnumerable GenerateRandomDateTimes(DateTime min, Dat } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static DateTime GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue); - /// - /// Generates a random value between and . - /// - /// The maximum value. - /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max); - /// - /// Returns the week of the year that the specified value falls in, according to the current culture's calendar, week rule, and first day of the week settings. - /// - /// The value. - /// The week of the year that the specified value falls in. public static int GetWeekOfYear(this DateTime dt) => CurrentInfo.Calendar.GetWeekOfYear(dt, CurrentInfo.CalendarWeekRule, CurrentInfo.FirstDayOfWeek); - /// - /// Gets the week of the year for an enumerable of DateTime values using the default calendar of the current culture. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The enumerable of DateTime values for which to get the week of the year. - /// An containing the week of the year values for the input DateTime values. public static IEnumerable GetWeekOfYear(this IEnumerable dts) { if (dts is null || !dts.Any()) @@ -162,23 +80,8 @@ public static IEnumerable GetWeekOfYear(this IEnumerable dts) } } - /// - /// Returns the total number of months between the two specified values, ignoring the day of the month. - /// - /// The first value. - /// The second value. - /// The total number of months between the two specified values, ignoring the day of the month. public static int TotalMonths(DateTime dt1, DateTime dt2) => Abs((dt1.Year - dt2.Year) * 12 + dt1.Month - dt2.Month); - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. - /// - /// The type of the original time zone offset, which must be a value type. - /// The type of the destination time zone offset, which must be a value type. - /// The original value. - /// The time zone offset of the original value, in hours. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone. public static DateTime ChangeTimeZone(this DateTime dt, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { var diff = tzDst.ToInt() - tzSrc.ToInt(); @@ -190,16 +93,6 @@ public static DateTime ChangeTimeZone(this DateTime dt, T1 tzSrc, T2 tzD }; } - /// - /// Converts an enumerable of DateTime values from one time zone to another using the specified source and destination time zones. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The enumerable of DateTime values to convert. - /// The source time zone to convert from. - /// The destination time zone to convert to. - /// An containing the DateTime values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is null || !dts.Any()) @@ -212,15 +105,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable - /// Converts an list of DateTime values from one time zone to another using the specified source and destination time zones, and updates the original list in-place. - /// If the input list is or empty, no action is taken. - /// - /// The type of the source time zone. - /// The type of the destination time zone. - /// The list of DateTime values to convert and update. - /// The source time zone to convert from. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct { if (dts is not null && dts.Count > 0) @@ -232,23 +116,8 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2 } } - /// - /// Returns a new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. - /// - /// The type of the time zone offset to convert the original value to, which must be a value type. - /// The original value. - /// The time zone offset to convert the original value to, in hours. - /// A new value representing the same point in time as the original value, but converted to a different time zone with a time zone offset of 0. public static DateTime ChangeTimeZone(this DateTime dt, T tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst); - /// - /// Converts an array of DateTime values from one time zone to another using the specified destination time zone, and returns an containing the DateTime values converted to the destination time zone. - /// Returns an empty sequence if the input array is or empty. - /// - /// The type of the destination time zone. - /// The array of DateTime values to convert. - /// The destination time zone to convert to. - /// An containing the DateTime values converted to the destination time zone. public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct { if (dts is null || !dts.Any()) @@ -261,13 +130,6 @@ public static IEnumerable ChangeTimeZone(this IEnumerable } } - /// - /// Converts a list of DateTime values from one time zone to another using the specified destination time zone, and updates the original list in place with the DateTime values converted to the destination time zone. - /// If the input list is or empty, no changes will be made. - /// - /// The type of the destination time zone. - /// The list of DateTime values to convert. - /// The destination time zone to convert to. public static void ChangeTimeZone(this IList dts, T tzDst) where T : struct { if (dts is not null && dts.Count > 0) diff --git a/lib/YANLib/YANEnumerable.cs b/lib/YANLib/YANEnumerable.cs index b52e1cfb..eb91848f 100644 --- a/lib/YANLib/YANEnumerable.cs +++ b/lib/YANLib/YANEnumerable.cs @@ -6,14 +6,7 @@ namespace YANLib; public static partial class YANEnumerable { - /// - /// Splits a given into smaller chunks of a specified size. - /// - /// The type of elements in the list. - /// The type of the chunk size, which must be a value type. - /// The source list to be chunked. - /// The maximum number of elements in each chunk. - /// An of s, where each inner list has a maximum size of . + public static IEnumerable> ChunkBySize(this List srcs, T1 chunkSize) where T1 : struct { var size = chunkSize.ToInt(); @@ -28,14 +21,6 @@ public static IEnumerable> ChunkBySize(this List srcs, T1 chun } } - /// - /// Removes values from the specified objects and returns an containing the non-null values. - /// If the type is a class or a nullable value type, the method checks for values and excludes them. - /// If is a non-nullable value type, the method returns all objects in the input enumerable without modification. - /// - /// The type of the objects to clean. - /// The objects to clean. - /// An containing the non-null values. public static IEnumerable Clean(this IEnumerable srcs) { if (srcs is null || !srcs.Any()) @@ -62,13 +47,6 @@ public static IEnumerable Clean(this IEnumerable srcs) } } - /// - /// Removes values from the specified collection of objects and modifies the collection in-place, by removing the null values. - /// If the type is a class or a nullable value type, the method checks for values and removes them from the collection. - /// If is a non-nullable value type, the method does not modify the collection. - /// - /// The type of the objects in the collection. - /// The collection of objects to clean. public static void Clean(this ICollection srcs) { if (srcs is not null && srcs.Any()) @@ -87,11 +65,6 @@ public static void Clean(this ICollection srcs) } } - /// - /// Removes values and empty strings from the specified enumerable of strings, and returns an containing the non-null and non-empty strings. - /// - /// The enumerable of strings to clean. - /// An containing the non-null and non-empty strings. public static IEnumerable Clean(this IEnumerable srcs) { if (srcs is null || !srcs.Any()) @@ -107,11 +80,6 @@ public static IEnumerable Clean(this IEnumerable srcs) } } - /// - /// Removes or whitespace values from the specified collection of strings and modifies the collection in-place, by removing the null or whitespace values. - /// If the string value is not null or whitespace, the method checks for whitespace values using method and removes them from the collection. - /// - /// The collection of strings to clean. public static void Clean(this ICollection srcs) { if (srcs is not null && srcs.Any()) @@ -125,23 +93,4 @@ public static void Clean(this ICollection srcs) } } } - - public static Dictionary? CreateDictionary(IEnumerable keys, IEnumerable values) where TKey : notnull - { - if (keys is not null && values is not null && keys.Any() && values.Any()) - { - var keyList = keys.ToList(); - var valueList = values.ToList(); - if (keyList.Count > 0 && keyList.Count == keyList.Distinct().Count() && valueList.Count >= keyList.Count) - { - var rslt = new Dictionary(keyList.Count); - for (var i = 0; i < keyList.Count; i++) - { - rslt.Add(keyList[i], valueList[i]); - } - return rslt; - } - } - return default; - } } diff --git a/lib/YANLib/YANFunc.cs b/lib/YANLib/YANFunc.cs deleted file mode 100644 index ce950532..00000000 --- a/lib/YANLib/YANFunc.cs +++ /dev/null @@ -1,133 +0,0 @@ -using static System.Environment; -using static System.Threading.Tasks.Task; - -namespace YANLib; - -public static partial class YANFunc -{ - public static async ValueTask> AggregateResultsConcurrently(Func func, IEnumerable args) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var item = func(arg); - await semSlim.WaitAsync(); - try - { - rslts.Add(item); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrently(Func, TResult> func, IEnumerable args, IEnumerable coll) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var item = func(arg, coll); - await semSlim.WaitAsync(); - try - { - rslts.Add(item); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrently(Func> func, IEnumerable args) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var item = await func(arg); - await semSlim.WaitAsync(); - try - { - rslts.Add(item); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrently(Func, ValueTask> func, IEnumerable args, IEnumerable coll) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var item = await func(arg, coll); - await semSlim.WaitAsync(); - try - { - rslts.Add(item); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrently(Func> func, IEnumerable args) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var item = await func(arg); - await semSlim.WaitAsync(); - try - { - rslts.Add(item); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } - - public static async ValueTask> AggregateResultsConcurrently(Func, Task> func, IEnumerable args, IEnumerable coll) - { - var rslts = new List(); - var semSlim = new SemaphoreSlim(ProcessorCount); - var tasks = args.Select(async arg => - { - var item = await func(arg, coll); - await semSlim.WaitAsync(); - try - { - rslts.Add(item); - } - finally - { - _ = semSlim.Release(); - } - }); - await WhenAll(tasks); - return rslts; - } -} diff --git a/lib/YANLib/YANJson.cs b/lib/YANLib/YANJson.cs index 154b5032..cdae2aab 100644 --- a/lib/YANLib/YANJson.cs +++ b/lib/YANLib/YANJson.cs @@ -5,28 +5,10 @@ namespace YANLib; public static partial class YANJson { - /// - /// Serializes the given object of type to a JSON string using the default JSON serialization settings. - /// - /// - /// The type of the object to be serialized. - /// Must be a reference type. - /// - /// The object to be serialized. - /// A JSON string representing the serialized object. + public static string Serialize(this T mdl) where T : class => JsonSerializer.Serialize(mdl); - /// - /// Serializes an enumerable of objects of type to an containing JSON strings representing the serialized objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the objects to be serialized. - /// Must be a reference type. - /// - /// The enumerable of objects to be serialized. - /// An containing JSON strings representing the serialized objects. - public static IEnumerable Serialize(this IEnumerable mdls) where T : class + public static IEnumerable Serializes(this IEnumerable mdls) where T : class { if (mdls is null || !mdls.Any()) { @@ -38,34 +20,13 @@ public static IEnumerable Serialize(this IEnumerable mdls) where T } } - /// - /// Serializes the given object of type to a JSON string using the default JSON serialization settings, - /// with the property names in camelCase and case sensitivity for property names set to false. - /// - /// - /// The type of the object to be serialized. - /// Must be a reference type. - /// - /// The object to be serialized. - /// A JSON string representing the serialized object with camelCase property names and case sensitivity for property names set to false. public static string SerializeCamel(this T mdl) where T : class => JsonSerializer.Serialize(mdl, new JsonSerializerOptions { PropertyNameCaseInsensitive = false, PropertyNamingPolicy = CamelCase }); - /// - /// Serializes an enumerable of objects of type to an containing JSON strings representing the serialized objects, - /// with the property names in camelCase and case sensitivity for property names set to false. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the objects to be serialized. - /// Must be a reference type. - /// - /// The enumerable of objects to be serialized. - /// An containing JSON strings representing the serialized objects with camelCase property names and case sensitivity for property names set to false. - public static IEnumerable SerializeCamel(this IEnumerable mdls) where T : class + public static IEnumerable SerializeCamels(this IEnumerable mdls) where T : class { if (mdls is null || !mdls.Any()) { @@ -77,16 +38,6 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes a JSON string to an object of type using the default JSON deserialization settings. - /// Returns the deserialized object, or if the deserialization fails. - /// - /// - /// The type of the object to be deserialized. - /// Must be a reference type. - /// - /// The JSON string to be deserialized. - /// The deserialized object, or if the deserialization fails. public static T? Deserialize(this string str) where T : class { try @@ -99,17 +50,7 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes an array of JSON strings to an enumerable of objects of type using the default JSON deserialization settings. - /// Returns an enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - /// - /// - /// The type of the objects to be deserialized. - /// Must be a reference type. - /// - /// The array of JSON strings to be deserialized. - /// An enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - public static IEnumerable Deserialize(this IEnumerable strs) where T : class + public static IEnumerable Deserializes(this IEnumerable strs) where T : class { if (strs is null || !strs.Any()) { @@ -121,16 +62,6 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes a JSON string to an object of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false. - /// Returns the deserialized object, or if the deserialization fails. - /// - /// - /// The type of the object to be deserialized. - /// Must be a reference type. - /// - /// The JSON string to be deserialized. - /// The deserialized object, or if the deserialization fails. public static T? DeserializeCamel(this string str) where T : class { try @@ -147,17 +78,7 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes an array of JSON strings to an enumerable of objects of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false. - /// Returns an enumerable of deserialized objects, or an empty sequence if the input array is , empty, or contains only strings. - /// - /// - /// The type of the objects to be deserialized. - /// Must be a reference type. - /// - /// The array of JSON strings to be deserialized. - /// An enumerable of deserialized objects, or an empty sequence if the input array is , empty, or contains only strings. - public static IEnumerable DeserializeCamel(this IEnumerable strs) where T : class + public static IEnumerable DeserializeCamels(this IEnumerable strs) where T : class { if (strs is null || !strs.Any()) { @@ -169,16 +90,6 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes a JSON string to an object of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false as additional options. - /// If the deserialization fails, returns . - /// - /// - /// The type of the object to be deserialized. - /// Must be a reference type. - /// - /// The JSON string to be deserialized. - /// The deserialized object, or if the deserialization fails. public static T? DeserializeDuo(this string str) where T : class { T? rslt; @@ -207,17 +118,7 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes an array of JSON strings to an enumerable of objects of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false as additional options. - /// Returns an enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - /// - /// - /// The type of the objects to be deserialized. - /// Must be a reference type. - /// - /// The array of JSON strings to be deserialized. - /// An enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - public static IEnumerable DeserializeDuo(this IEnumerable strs) where T : class + public static IEnumerable DeserializeDuos(this IEnumerable strs) where T : class { if (strs is null || !strs.Any()) { @@ -229,16 +130,6 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes a JSON string to an object of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false as additional options. - /// If the deserialization fails, returns . - /// - /// - /// The type of the object to be deserialized. - /// Must be a reference type. - /// - /// The JSON string to be deserialized. - /// The deserialized object, or if the deserialization fails. public static T? DeserializeDuoCamelPriority(this string str) where T : class { T? rslt; @@ -267,17 +158,7 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes an array of JSON strings to an enumerable of objects of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false as additional options. - /// Returns an enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - /// - /// - /// The type of the objects to be deserialized. - /// Must be a reference type. - /// - /// The array of JSON strings to be deserialized. - /// An enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - public static IEnumerable DeserializeDuoCamelPriority(this IEnumerable strs) where T : class + public static IEnumerable DeserializeDuoCamelPriorities(this IEnumerable strs) where T : class { if (strs is null || !strs.Any()) { @@ -289,16 +170,6 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes a JSON string to an object of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false as additional options. - /// If the deserialization fails, returns . - /// - /// - /// The type of the object to be deserialized. - /// Must be a reference type. - /// - /// The JSON string to be deserialized. - /// The deserialized object, or if the deserialization fails. public static T? DeserializeStandard(this string str) where T : class { try @@ -315,17 +186,7 @@ public static IEnumerable SerializeCamel(this IEnumerable mdls) wh } } - /// - /// Deserializes an array of JSON strings to an enumerable of objects of type using the default JSON deserialization settings, with camelCase property names and case sensitivity for property names set to false as additional options. - /// Returns an enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - /// - /// - /// The type of the objects to be deserialized. - /// Must be a reference type. - /// - /// The array of JSON strings to be deserialized. - /// An enumerable of deserialized objects, or if the deserialization fails for any of the input strings. - public static IEnumerable DeserializeStandard(this IEnumerable strs) where T : class + public static IEnumerable DeserializeStandards(this IEnumerable strs) where T : class { if (strs is null || !strs.Any()) { diff --git a/lib/YANLib/YANModel.Property.cs b/lib/YANLib/YANModel.Property.cs index 95112b2c..cfcd51a4 100644 --- a/lib/YANLib/YANModel.Property.cs +++ b/lib/YANLib/YANModel.Property.cs @@ -5,13 +5,7 @@ namespace YANLib; public static partial class YANModel { - /// - /// Checks whether all properties of the specified object have non-default values, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// if all properties of the specified object have non-default values; otherwise, . + public static bool AllPropertiesNotDefault(this T mdl) where T : class { if (mdl is null) @@ -29,13 +23,6 @@ public static bool AllPropertiesNotDefault(this T mdl) where T : class return true; } - /// - /// Checks whether all properties of the specified objects have non-default values, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// An containing or for each object, indicating whether all properties have non-default values. public static IEnumerable AllPropertiesNotDefault(this IEnumerable mdls) where T : class { if (mdls is null || !mdls.Any()) @@ -48,13 +35,6 @@ public static IEnumerable AllPropertiesNotDefault(this IEnumerable m } } - /// - /// Checks whether all properties of the specified object have default values, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// if all properties of the specified object have default values; otherwise, . public static bool AllPropertiesDefault(this T mdl) where T : class { if (mdl is null) @@ -72,13 +52,6 @@ public static bool AllPropertiesDefault(this T mdl) where T : class return true; } - /// - /// Checks whether all properties of the specified objects have default values, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// An containing or for each object, indicating whether all properties have default values. public static IEnumerable AllPropertiesDefault(this IEnumerable mdls) where T : class { if (mdls is null || !mdls.Any()) @@ -91,13 +64,6 @@ public static IEnumerable AllPropertiesDefault(this IEnumerable mdls } } - /// - /// Checks whether any property of the specified object has a value other than the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// if any property of the specified object has a value other than the default value; otherwise, . public static bool AnyPropertiesNotDefault(this T mdl) where T : class { if (mdl is null) @@ -115,13 +81,6 @@ public static bool AnyPropertiesNotDefault(this T mdl) where T : class return false; } - /// - /// Checks whether any property of the specified objects has a non-default value, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// An containing or for each object, indicating whether any property has a non-default value. public static IEnumerable AnyPropertiesNotDefault(this IEnumerable mdls) where T : class { if (mdls is null || !mdls.Any()) @@ -134,13 +93,6 @@ public static IEnumerable AnyPropertiesNotDefault(this IEnumerable m } } - /// - /// Checks whether any property of the specified object has a value equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// if any property of the specified object has a value equal to the default value; otherwise, . public static bool AnyPropertiesDefault(this T mdl) where T : class { if (mdl is null) @@ -158,13 +110,6 @@ public static bool AnyPropertiesDefault(this T mdl) where T : class return false; } - /// - /// Checks whether any property of the specified objects has a default value, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// An containing or for each object, indicating whether any property has a default value. public static IEnumerable AnyPropertiesDefault(this IEnumerable mdls) where T : class { if (mdls is null || !mdls.Any()) @@ -177,14 +122,6 @@ public static IEnumerable AnyPropertiesDefault(this IEnumerable mdls } } - /// - /// Checks whether all properties with the specified names of the specified object have values that are not equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if all properties with the specified names of the specified object have values that are not equal to the default value; otherwise, . public static bool AllPropertiesNotDefault(this T mdl, params string[] names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -202,14 +139,6 @@ public static bool AllPropertiesNotDefault(this T mdl, params string[] names) return true; } - /// - /// Checks whether all properties of the specified objects have non-default values, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether all properties, except for the specified names, have non-default values. public static IEnumerable AllPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class { if (mdls is null || !mdls.Any()) @@ -222,14 +151,6 @@ public static IEnumerable AllPropertiesNotDefault(this IEnumerable m } } - /// - /// Checks whether all properties with the specified names of the specified object have values that are equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if all properties with the specified names of the specified object have values that are equal to the default value; otherwise, . public static bool AllPropertiesDefault(this T mdl, params string[] names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -247,14 +168,6 @@ public static bool AllPropertiesDefault(this T mdl, params string[] names) wh return true; } - /// - /// Checks whether all properties of the specified objects have default values, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether all properties, except for the specified names, have default values. public static IEnumerable AllPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class { if (mdls is null || !mdls.Any()) @@ -267,14 +180,6 @@ public static IEnumerable AllPropertiesDefault(this IEnumerable mdls } } - /// - /// Checks whether any properties with the specified names of the specified object have values that are not equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if any properties with the specified names of the specified object have values that are not equal to the default value; otherwise, . public static bool AnyPropertiesNotDefault(this T mdl, params string[] names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -292,14 +197,6 @@ public static bool AnyPropertiesNotDefault(this T mdl, params string[] names) return false; } - /// - /// Checks whether any property of the specified objects has a non-default value, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether any property, except for the specified names, has a non-default value. public static IEnumerable AnyPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class { if (mdls is null || !mdls.Any()) @@ -312,14 +209,6 @@ public static IEnumerable AnyPropertiesNotDefault(this IEnumerable m } } - /// - /// Checks whether any properties with the specified names of the specified object have values that are equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if any properties with the specified names of the specified object have values that are equal to the default value; otherwise, . public static bool AnyPropertiesDefault(this T mdl, params string[] names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -337,14 +226,6 @@ public static bool AnyPropertiesDefault(this T mdl, params string[] names) wh return false; } - /// - /// Checks whether any property of the specified objects has a default value, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether any property, except for the specified names, has a default value. public static IEnumerable AnyPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class { if (mdls is null || !mdls.Any()) @@ -357,14 +238,6 @@ public static IEnumerable AnyPropertiesDefault(this IEnumerable mdls } } - /// - /// Checks whether all properties with the specified names of the specified object have values that are not equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if all properties with the specified names of the specified object have values that are not equal to the default value; otherwise, . public static bool AllPropertiesNotDefault(this T mdl, IEnumerable names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -382,14 +255,6 @@ public static bool AllPropertiesNotDefault(this T mdl, IEnumerable na return true; } - /// - /// Checks whether all properties of the specified objects have non-default values, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether all properties, except for the specified names, have non-default values. public static IEnumerable AllPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class { if (mdls is null || !mdls.Any()) @@ -402,14 +267,6 @@ public static IEnumerable AllPropertiesNotDefault(this IEnumerable m } } - /// - /// Checks whether all properties with the specified names of the specified object have values that are equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if all properties with the specified names of the specified object have values that are equal to the default value; otherwise, . public static bool AllPropertiesDefault(this T mdl, IEnumerable names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -427,14 +284,6 @@ public static bool AllPropertiesDefault(this T mdl, IEnumerable names return true; } - /// - /// Checks whether all properties of the specified objects have default values, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether all properties, except for the specified names, have default values. public static IEnumerable AllPropertiesDefault(this IEnumerable mdls, IEnumerable names) where T : class { if (mdls is null || !mdls.Any()) @@ -447,14 +296,6 @@ public static IEnumerable AllPropertiesDefault(this IEnumerable mdls } } - /// - /// Checks whether any properties with the specified names of the specified object have values that are not equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if any properties with the specified names of the specified object have values that are not equal to the default value; otherwise, . public static bool AnyPropertiesNotDefault(this T mdl, IEnumerable names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -472,14 +313,6 @@ public static bool AnyPropertiesNotDefault(this T mdl, IEnumerable na return false; } - /// - /// Checks whether any property of the specified objects has a non-default value, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether any property, except for the specified names, has a non-default value. public static IEnumerable AnyPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class { if (mdls is null || !mdls.Any()) @@ -492,14 +325,6 @@ public static IEnumerable AnyPropertiesNotDefault(this IEnumerable m } } - /// - /// Checks whether any properties with the specified names of the specified object have values that are equal to the default value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to check. - /// The object to check. - /// The names of the properties to check. - /// if any properties with the specified names of the specified object have values that are equal to the default value; otherwise, . public static bool AnyPropertiesDefault(this T mdl, IEnumerable names) where T : class { if (mdl is null || names.IsNullOrWhiteSpace()) @@ -517,14 +342,6 @@ public static bool AnyPropertiesDefault(this T mdl, IEnumerable names return false; } - /// - /// Checks whether any property of the specified objects has a default value, including all their nested properties and properties in lists, except for properties with the specified names. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to check. - /// The objects to check. - /// The names of properties to exclude from the check. - /// An containing or for each object, indicating whether any property, except for the specified names, has a default value. public static IEnumerable AnyPropertiesDefault(this IEnumerable mdls, IEnumerable names) where T : class { if (mdls is null || !mdls.Any()) diff --git a/lib/YANLib/YANModel.cs b/lib/YANLib/YANModel.cs index 935e4f2c..9e2147c8 100644 --- a/lib/YANLib/YANModel.cs +++ b/lib/YANLib/YANModel.cs @@ -5,15 +5,7 @@ namespace YANLib; public static partial class YANModel { - /// - /// Changes the time zone of all properties of the specified object with nullable value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to change the time zone. - /// The nullable object to change the time zone. - /// The source time zone. - /// The destination time zone. - /// The nullable object with all its properties having the specified time zone; or if the object is . + public static T? ChangeTimeZoneAllProperties(this T? mdl, T1 tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct { if (mdl is not null) @@ -69,17 +61,6 @@ public static partial class YANModel return mdl; } - /// - /// Changes the time zone of all properties of the specified objects in the enumerable with nullable values, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to change the time zone. - /// The type of the source time zone. - /// The type of the destination time zone. - /// The nullable objects to change the time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the nullable objects with all their properties having the specified time zone; or for each object that is in the enumerable. public static IEnumerable ChangeTimeZoneAllProperties(this IEnumerable mdls, T1 tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct { if (mdls is null || !mdls.Any()) @@ -92,15 +73,6 @@ public static partial class YANModel } } - /// - /// Changes the time zone of all properties of the specified object with nullable value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to change the time zone. - /// The nullable object to change the time zone. - /// The source time zone. - /// The destination time zone. - /// The nullable object with all its properties having the specified time zone; or if the object is . public static T? ChangeTimeZoneAllProperties(this T? mdl, T1? tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct { if (mdl is not null) @@ -156,17 +128,6 @@ public static partial class YANModel return mdl; } - /// - /// Changes the time zone of all properties of the specified objects in the enumerable with nullable values, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to change the time zone. - /// The type of the source time zone. - /// The type of the destination time zone. - /// The nullable objects to change the time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the nullable objects with all their properties having the specified time zone; or for each object that is in the enumerable. public static IEnumerable ChangeTimeZoneAllProperties(this IEnumerable mdls, T1? tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct { if (mdls is null || !mdls.Any()) @@ -179,15 +140,6 @@ public static partial class YANModel } } - /// - /// Changes the time zone of all properties of the specified object with nullable value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to change the time zone. - /// The nullable object to change the time zone. - /// The source time zone. - /// The destination time zone. - /// The nullable object with all its properties having the specified time zone; or if the object is . public static T? ChangeTimeZoneAllProperties(this T? mdl, T1 tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct { if (mdl is not null) @@ -243,17 +195,6 @@ public static partial class YANModel return mdl; } - /// - /// Changes the time zone of all properties of the specified objects in the enumerable with nullable values, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to change the time zone. - /// The type of the source time zone. - /// The type of the destination time zone. - /// The nullable objects to change the time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the nullable objects with all their properties having the specified time zone; or for each object that is in the enumerable. public static IEnumerable ChangeTimeZoneAllProperties(this IEnumerable mdls, T1 tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct { if (mdls is null || !mdls.Any()) @@ -266,15 +207,6 @@ public static partial class YANModel } } - /// - /// Changes the time zone of all properties of the specified object with nullable value, including all its nested properties and properties in lists. - /// If the object is , returns . - /// - /// The type of the object to change the time zone. - /// The nullable object to change the time zone. - /// The source time zone. - /// The destination time zone. - /// The nullable object with all its properties having the specified time zone; or if the object is . public static T? ChangeTimeZoneAllProperties(this T? mdl, T1? tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct { if (mdl is not null) @@ -330,17 +262,6 @@ public static partial class YANModel return mdl; } - /// - /// Changes the time zone of all properties of the specified objects in the enumerable with nullable values, including all their nested properties and properties in lists. - /// If any of the objects is , returns for that object. - /// - /// The type of the objects to change the time zone. - /// The type of the source time zone. - /// The type of the destination time zone. - /// The nullable objects to change the time zone. - /// The source time zone. - /// The destination time zone. - /// An containing the nullable objects with all their properties having the specified time zone; or for each object that is in the enumerable. public static IEnumerable ChangeTimeZoneAllProperties(this IEnumerable mdls, T1? tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct { if (mdls is null || !mdls.Any()) diff --git a/lib/YANLib/YANNum.Byte.Nullable.cs b/lib/YANLib/YANNum.Byte.Nullable.cs index 984547d6..8de94b1b 100644 --- a/lib/YANLib/YANNum.Byte.Nullable.cs +++ b/lib/YANLib/YANNum.Byte.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a byte. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static byte ToByte(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static byte ToByte(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. public static IEnumerable ToByte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToByte(this IEnumerable nums) where T : s } } - /// - /// Parses the string representation of a byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static byte ToByte(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToByte(dfltVal.Value) : default; - /// - /// Converts an enumerable of string objects to an containing the byte representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The enumerable of string objects to be converted. - /// The default value to be used for invalid conversions. - /// An containing the byte representations of the strings. public static IEnumerable ToByte(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToByte(this IEnumerable strs, T? dflt } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static byte GenerateRandomByte(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomByte(min.Value, max) : default; - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomBytes(T1? min, T2 max, } } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomBytes(T1? min, T2 max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static byte GenerateRandomByte(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomByte(min, max.Value) : default; - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomBytes(T1 min, T2? max, } } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomBytes(T1 min, T2? max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static byte GenerateRandomByte(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomByte(min.Value, max) : default; - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomBytes(T1? min, T2? max, } } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomBytes(T1? min, T2? max, } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static byte GenerateRandomByte(T? max) where T : struct => max.HasValue ? GenerateRandomByte(byte.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Byte.cs b/lib/YANLib/YANNum.Byte.cs index 0f7f550e..6e5566bb 100644 --- a/lib/YANLib/YANNum.Byte.cs +++ b/lib/YANLib/YANNum.Byte.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a byte. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static byte ToByte(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static byte ToByte(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. public static IEnumerable ToByte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToByte(this IEnumerable nums) where T : st } } - /// - /// Parses the string representation of a byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static byte ToByte(this string str) => byte.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of string objects to an containing the byte representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// The enumerable of string objects to be converted. - /// An containing the byte representations of the strings. public static IEnumerable ToByte(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToByte(this IEnumerable strs) } } - /// - /// Parses the string representation of a byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static byte ToByte(this string str, T dfltVal) where T : struct => byte.TryParse(str, out var num) ? num : dfltVal.ToByte(); - /// - /// Converts an enumerable of string objects to an containing the byte representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The enumerable of string objects to be converted. - /// The default value to be used for invalid conversions. - /// An containing the byte representations of the strings. public static IEnumerable ToByte(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToByte(this IEnumerable strs, T dfltV } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static byte GenerateRandomByte(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToByte(); @@ -118,17 +62,6 @@ public static byte GenerateRandomByte(T1 min, T2 max) where T1 : struct return minValue > maxValue ? default : new Random().Next(minValue, maxValue).ToByte(); } - /// - /// Generates a sequence of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of the generated sequence, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the generated sequence. - /// An containing the random byte values between and . public static IEnumerable GenerateRandomBytes(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomBytes(T1 min, T2 max, T } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static byte GenerateRandomByte() => GenerateRandomByte(byte.MinValue, byte.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static byte GenerateRandomByte(T max) where T : struct => GenerateRandomByte(byte.MinValue, max); } diff --git a/lib/YANLib/YANNum.Decimal.Nullable.cs b/lib/YANLib/YANNum.Decimal.Nullable.cs index b382267e..2b6c67ec 100644 --- a/lib/YANLib/YANNum.Decimal.Nullable.cs +++ b/lib/YANLib/YANNum.Decimal.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a decimal. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static decimal ToDecimal(this T? num) where T : struct { try @@ -21,15 +15,6 @@ public static decimal ToDecimal(this T? num) where T : struct } } - /// - /// Converts an enumerable of values of a generic value type to an containing the decimal representations of the values. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the values to be converted, which must be a value type. - /// - /// The enumerable of values to be converted. - /// An containing the decimal representations of the values. public static IEnumerable ToDecimal(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -42,27 +27,8 @@ public static IEnumerable ToDecimal(this IEnumerable nums) where } } - /// - /// Parses the string representation of a decimal using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static decimal ToDecimal(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToDecimal(dfltVal.Value) : default; - /// - /// Converts an enumerable of string objects to an containing the decimal representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The enumerable of string objects to be converted. - /// The default value to be used for invalid conversions. - /// An containing the decimal representations of the strings. public static IEnumerable ToDecimal(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -75,27 +41,8 @@ public static IEnumerable ToDecimal(this IEnumerable strs, T } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal GenerateRandomDecimal(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDecimal(min.Value, max) : default; - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -104,16 +51,6 @@ public static IEnumerable GenerateRandomDecimals(T1? min, T2 } } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -122,27 +59,8 @@ public static IEnumerable GenerateRandomDecimals(T1? min, T2 } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal GenerateRandomDecimal(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomDecimal(min, max.Value) : default; - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -151,16 +69,6 @@ public static IEnumerable GenerateRandomDecimals(T1 min, T2? } } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -169,27 +77,8 @@ public static IEnumerable GenerateRandomDecimals(T1 min, T2? } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal GenerateRandomDecimal(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDecimal(min.Value, max) : default; - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -198,16 +87,6 @@ public static IEnumerable GenerateRandomDecimals(T1? min, T2 } } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -216,11 +95,5 @@ public static IEnumerable GenerateRandomDecimals(T1? min, T2 } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static decimal GenerateRandomDecimal(T? max) where T : struct => max.HasValue ? GenerateRandomDecimal(decimal.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Decimal.cs b/lib/YANLib/YANNum.Decimal.cs index fd65a2cb..1caa1540 100644 --- a/lib/YANLib/YANNum.Decimal.cs +++ b/lib/YANLib/YANNum.Decimal.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a decimal. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static decimal ToDecimal(this T num) where T : struct { try @@ -21,15 +15,6 @@ public static decimal ToDecimal(this T num) where T : struct } } - /// - /// Converts an enumerable of values of a generic value type to an containing the decimal representations of the values. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the values to be converted, which must be a value type. - /// - /// The enumerable of values to be converted. - /// An containing the decimal representations of the values. public static IEnumerable ToDecimal(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -42,20 +27,8 @@ public static IEnumerable ToDecimal(this IEnumerable nums) where } } - /// - /// Parses the string representation of a decimal using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static decimal ToDecimal(this string str) => decimal.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of string objects to an containing the decimal representations of the strings. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// The enumerable of string objects to be converted. - /// An containing the decimal representations of the strings. public static IEnumerable ToDecimal(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -68,27 +41,8 @@ public static IEnumerable ToDecimal(this IEnumerable strs) } } - /// - /// Parses the string representation of a decimal using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static decimal ToDecimal(this string str, T dfltVal) where T : struct => decimal.TryParse(str, out var num) ? num : dfltVal.ToDecimal(); - /// - /// Converts an enumerable of string objects to an containing the decimal representations of the strings, using a default value for invalid conversions. - /// Returns an empty sequence if the input enumerable is or empty. - /// - /// - /// The type of the default value to be used for invalid conversions. - /// Must be a value type. - /// - /// The enumerable of string objects to be converted. - /// The default value to be used for invalid conversions. - /// An containing the decimal representations of the strings. public static IEnumerable ToDecimal(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -101,15 +55,6 @@ public static IEnumerable ToDecimal(this IEnumerable strs, T } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal GenerateRandomDecimal(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToDecimal(); @@ -117,16 +62,6 @@ public static decimal GenerateRandomDecimal(T1 min, T2 max) where T1 : s return minValue > maxValue ? default : new Random().NextDecimal(minValue, maxValue); } - /// - /// Generates an sequence of random decimal values between and , with the number of values specified by , using a default value for invalid conversions. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random decimal values to generate. - /// An containing the randomly generated decimal values. public static IEnumerable GenerateRandomDecimals(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -135,17 +70,7 @@ public static IEnumerable GenerateRandomDecimals(T1 min, T2 } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static decimal GenerateRandomDecimal() => GenerateRandomDecimal(decimal.MinValue, decimal.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static decimal GenerateRandomDecimal(T max) where T : struct => GenerateRandomDecimal(decimal.MinValue, max); } diff --git a/lib/YANLib/YANNum.Double.Nullable.cs b/lib/YANLib/YANNum.Double.Nullable.cs index db6d3093..a3f43972 100644 --- a/lib/YANLib/YANNum.Double.Nullable.cs +++ b/lib/YANLib/YANNum.Double.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a double. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static double ToDouble(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static double ToDouble(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the double representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the double representations of the objects. public static IEnumerable ToDouble(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToDouble(this IEnumerable nums) where T } } - /// - /// Parses the string representation of a double using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static double ToDouble(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToDouble(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the double representations of the strings, using a default value for conversion failures. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failures. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to use for conversion failures. - /// An containing the double representations of the strings. public static IEnumerable ToDouble(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToDouble(this IEnumerable strs, T? } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double GenerateRandomDouble(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDouble(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomDoubles(T1? min, T2 m } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomDoubles(T1? min, T2 m } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double GenerateRandomDouble(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomDouble(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomDoubles(T1 min, T2? m } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomDoubles(T1 min, T2? m } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double GenerateRandomDouble(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomDouble(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomDoubles(T1? min, T2? } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomDoubles(T1? min, T2? } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static double GenerateRandomDouble(T? max) where T : struct => max.HasValue ? GenerateRandomDouble(double.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Double.cs b/lib/YANLib/YANNum.Double.cs index 62628d3d..c7a1fddd 100644 --- a/lib/YANLib/YANNum.Double.cs +++ b/lib/YANLib/YANNum.Double.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a double. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static double ToDouble(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static double ToDouble(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the double representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the double representations of the objects. public static IEnumerable ToDouble(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToDouble(this IEnumerable nums) where T } } - /// - /// Parses the string representation of a double using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static double ToDouble(this string str) => double.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the double representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the double representations of the strings. public static IEnumerable ToDouble(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToDouble(this IEnumerable strs) } } - /// - /// Parses the string representation of a double using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static double ToDouble(this string str, T dfltVal) where T : struct => double.TryParse(str, out var num) ? num : dfltVal.ToDouble(); - /// - /// Converts an enumerable of strings to an containing the double representations of the strings, using a default value for conversion failures. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failures. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to use for conversion failures. - /// An containing the double representations of the strings. public static IEnumerable ToDouble(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToDouble(this IEnumerable strs, T d } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double GenerateRandomDouble(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToDouble(); @@ -118,17 +62,6 @@ public static double GenerateRandomDouble(T1 min, T2 max) where T1 : str return minValue > maxValue ? default : new Random().NextDouble(minValue, maxValue); } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing the random double values between and . public static IEnumerable GenerateRandomDoubles(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomDoubles(T1 min, T2 ma } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static double GenerateRandomDouble() => GenerateRandomDouble(double.MinValue, double.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static double GenerateRandomDouble(T max) where T : struct => GenerateRandomDouble(double.MinValue, max); } diff --git a/lib/YANLib/YANNum.Float.Nullable.cs b/lib/YANLib/YANNum.Float.Nullable.cs index 874923a9..6cc44980 100644 --- a/lib/YANLib/YANNum.Float.Nullable.cs +++ b/lib/YANLib/YANNum.Float.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a single-precision floating-point number. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static float ToFloat(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static float ToFloat(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the float representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the float representations of the objects. public static IEnumerable ToFloat(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToFloat(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of a float using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static float ToFloat(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToFloat(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the float representations of the strings, using a default value for parsing invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for parsing invalid or null strings. - /// Must be a value type. - /// - /// The enumerable of strings to be converted to float. - /// The default value to be used for parsing invalid or null strings. - /// An containing the float representations of the strings. public static IEnumerable ToFloat(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToFloat(this IEnumerable strs, T? df } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float GenerateRandomFloat(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomFloat(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomFloats(T1? min, T2 max } } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomFloats(T1? min, T2 max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float GenerateRandomFloat(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomFloat(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomFloats(T1 min, T2? max } } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomFloats(T1 min, T2? max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float GenerateRandomFloat(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomFloat(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomFloats(T1? min, T2? ma } } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomFloats(T1? min, T2? ma } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static float GenerateRandomFloat(T? max) where T : struct => max.HasValue ? GenerateRandomFloat(float.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Float.cs b/lib/YANLib/YANNum.Float.cs index 86ee43ae..a57f3290 100644 --- a/lib/YANLib/YANNum.Float.cs +++ b/lib/YANLib/YANNum.Float.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a single-precision floating-point number. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static float ToFloat(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static float ToFloat(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the float representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the float representations of the objects. public static IEnumerable ToFloat(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToFloat(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static float ToFloat(this string str) => float.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the float representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted to float. - /// An containing the float representations of the strings. public static IEnumerable ToFloat(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToFloat(this IEnumerable strs) } } - /// - /// Parses the string representation of a float using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static float ToFloat(this string str, T dfltVal) where T : struct => float.TryParse(str, out var num) ? num : dfltVal.ToFloat(); - /// - /// Converts an enumerable of strings to an containing the float representations of the strings, using a default value for parsing invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for parsing invalid or null strings. - /// Must be a value type. - /// - /// The enumerable of strings to be converted to float. - /// The default value to be used for parsing invalid or null strings. - /// An containing the float representations of the strings. public static IEnumerable ToFloat(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToFloat(this IEnumerable strs, T dfl } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float GenerateRandomFloat(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToFloat(); @@ -118,17 +62,6 @@ public static float GenerateRandomFloat(T1 min, T2 max) where T1 : struc return minValue > maxValue ? default : new Random().NextSingle(minValue, maxValue); } - /// - /// Generates an enumerable of random values between and , with the specified of elements. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size of elements, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of elements to be generated. - /// An containing random float values between and . public static IEnumerable GenerateRandomFloats(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomFloats(T1 min, T2 max, } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static float GenerateRandomFloat() => GenerateRandomFloat(float.MinValue, float.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static float GenerateRandomFloat(T max) where T : struct => GenerateRandomFloat(float.MinValue, max); } diff --git a/lib/YANLib/YANNum.Int.Nullable.cs b/lib/YANLib/YANNum.Int.Nullable.cs index 9fa7f4e6..9b860938 100644 --- a/lib/YANLib/YANNum.Int.Nullable.cs +++ b/lib/YANLib/YANNum.Int.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to an integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static int ToInt(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static int ToInt(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the integer representations of the objects. public static IEnumerable ToInt(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToInt(this IEnumerable nums) where T : str } } - /// - /// Parses the string representation of an integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static int ToInt(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToInt(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the integer representations of the strings, using the specified default value for parsing strings that cannot be converted to integers. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for parsing strings that cannot be converted to integers. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for parsing strings that cannot be converted to integers. - /// An containing the integer representations of the strings. public static IEnumerable ToInt(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToInt(this IEnumerable strs, T? dfltVa } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int GenerateRandomInt(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomInt(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomInts(T1? min, T2 max, T } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomInts(T1? min, T2 max, T? } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int GenerateRandomInt(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomInt(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomInts(T1 min, T2? max, T } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomInts(T1 min, T2? max, T? } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int GenerateRandomInt(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomInt(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomInts(T1? min, T2? max, T } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomInts(T1? min, T2? max, T } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static int GenerateRandomInt(T? max) where T : struct => max.HasValue ? GenerateRandomInt(int.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Int.cs b/lib/YANLib/YANNum.Int.cs index 99cdc108..337955c1 100644 --- a/lib/YANLib/YANNum.Int.cs +++ b/lib/YANLib/YANNum.Int.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to an integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static int ToInt(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static int ToInt(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the integer representations of the objects. public static IEnumerable ToInt(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToInt(this IEnumerable nums) where T : stru } } - /// - /// Parses the string representation of an integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static int ToInt(this string str) => int.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the integer representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the integer representations of the strings. public static IEnumerable ToInt(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToInt(this IEnumerable strs) } } - /// - /// Parses the string representation of an integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static int ToInt(this string str, T dfltVal) where T : struct => int.TryParse(str, out var num) ? num : dfltVal.ToInt(); - /// - /// Converts an enumerable of strings to an containing the integer representations of the strings, using the specified default value for parsing strings that cannot be converted to integers. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for parsing strings that cannot be converted to integers. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for parsing strings that cannot be converted to integers. - /// An containing the integer representations of the strings. public static IEnumerable ToInt(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToInt(this IEnumerable strs, T dfltVal } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static int GenerateRandomInt(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToInt(); @@ -118,17 +62,6 @@ public static int GenerateRandomInt(T1 min, T2 max) where T1 : struct wh return minValue > maxValue ? default : new Random().Next(minValue, maxValue); } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An containing the random integer values between and . public static IEnumerable GenerateRandomInts(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomInts(T1 min, T2 max, T s } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static int GenerateRandomInt() => GenerateRandomInt(int.MinValue, int.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static int GenerateRandomInt(T max) where T : struct => GenerateRandomInt(int.MinValue, max); } diff --git a/lib/YANLib/YANNum.Long.Nullable.cs b/lib/YANLib/YANNum.Long.Nullable.cs index 647f3261..84ecdc92 100644 --- a/lib/YANLib/YANNum.Long.Nullable.cs +++ b/lib/YANLib/YANNum.Long.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static long ToLong(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static long ToLong(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the long integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the long integer representations of the objects. public static IEnumerable ToLong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToLong(this IEnumerable nums) where T : s } } - /// - /// Parses the string representation of a long using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static long ToLong(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToLong(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the long integer representations of the strings, using a default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for invalid or null strings. - /// An containing the long integer representations of the strings. public static IEnumerable ToLong(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToLong(this IEnumerable strs, T? dflt } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long GenerateRandomLong(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomLong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomLongs(T1? min, T2 max, } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomLongs(T1? min, T2 max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long GenerateRandomLong(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomLong(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomLongs(T1 min, T2? max, } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomLongs(T1 min, T2? max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long GenerateRandomLong(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomLong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomLongs(T1? min, T2? max, } } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomLongs(T1? min, T2? max, } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static long GenerateRandomLong(T? max) where T : struct => max.HasValue ? GenerateRandomLong(long.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Long.cs b/lib/YANLib/YANNum.Long.cs index f96eaa5d..c033ecb7 100644 --- a/lib/YANLib/YANNum.Long.cs +++ b/lib/YANLib/YANNum.Long.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static long ToLong(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static long ToLong(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the long integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the long integer representations of the objects. public static IEnumerable ToLong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToLong(this IEnumerable nums) where T : st } } - /// - /// Parses the string representation of a long using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static long ToLong(this string str) => long.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the long integer representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the long integer representations of the strings. public static IEnumerable ToLong(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToLong(this IEnumerable strs) } } - /// - /// Parses the string representation of a long using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static long ToLong(this string str, T dfltVal) where T : struct => long.TryParse(str, out var num) ? num : dfltVal.ToLong(); - /// - /// Converts an enumerable of strings to an containing the long integer representations of the strings, using a default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for invalid or null strings. - /// An containing the long integer representations of the strings. public static IEnumerable ToLong(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToLong(this IEnumerable strs, T dfltV } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static long GenerateRandomLong(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToLong(); @@ -118,17 +62,6 @@ public static long GenerateRandomLong(T1 min, T2 max) where T1 : struct return minValue > maxValue ? default : new Random().NextInt64(minValue, maxValue); } - /// - /// Generates an enumerable of random values between and with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to generate. - /// An containing random long values between and . public static IEnumerable GenerateRandomLongs(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomLongs(T1 min, T2 max, T } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static long GenerateRandomLong() => GenerateRandomLong(long.MinValue, long.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static long GenerateRandomLong(T max) where T : struct => GenerateRandomLong(long.MinValue, max); } diff --git a/lib/YANLib/YANNum.Nint.Nullable.cs b/lib/YANLib/YANNum.Nint.Nullable.cs index 21a0e737..6bd7ae67 100644 --- a/lib/YANLib/YANNum.Nint.Nullable.cs +++ b/lib/YANLib/YANNum.Nint.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a native integer (nint). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nint ToNint(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static nint ToNint(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the nint representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the nint representations of the objects. public static IEnumerable ToNint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,30 +27,8 @@ public static IEnumerable ToNint(this IEnumerable nums) where T : s } } - /// - /// Parses the string representation of a pointer-sized signed integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nint ToNint(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToNint(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the nint representations of the strings, with an optional default value for conversion. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// - /// The default value for conversion if a string cannot be parsed to nint. - /// Used when conversion fails for a particular string. - /// - /// An containing the nint representations of the strings. public static IEnumerable ToNint(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -79,28 +41,8 @@ public static IEnumerable ToNint(this IEnumerable strs, T? dflt } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint GenerateRandomNint(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -109,17 +51,6 @@ public static IEnumerable GenerateRandomNints(T1? min, T2 max, } } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -128,28 +59,8 @@ public static IEnumerable GenerateRandomNints(T1? min, T2 max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint GenerateRandomNint(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomNint(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -158,17 +69,6 @@ public static IEnumerable GenerateRandomNints(T1 min, T2? max, } } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -177,28 +77,8 @@ public static IEnumerable GenerateRandomNints(T1 min, T2? max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint GenerateRandomNint(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -207,17 +87,6 @@ public static IEnumerable GenerateRandomNints(T1? min, T2? max, } } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -226,11 +95,5 @@ public static IEnumerable GenerateRandomNints(T1? min, T2? max, } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nint GenerateRandomNint(T? max) where T : struct => max.HasValue ? GenerateRandomNint(nint.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Nint.cs b/lib/YANLib/YANNum.Nint.cs index 57e7b73a..027dca88 100644 --- a/lib/YANLib/YANNum.Nint.cs +++ b/lib/YANLib/YANNum.Nint.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a native integer (nint). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nint ToNint(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static nint ToNint(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the nint representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the nint representations of the objects. public static IEnumerable ToNint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToNint(this IEnumerable nums) where T : st } } - /// - /// Parses the string representation of a nint using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static nint ToNint(this string str) => nint.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the nint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the nint representations of the strings. public static IEnumerable ToNint(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,30 +41,8 @@ public static IEnumerable ToNint(this IEnumerable strs) } } - /// - /// Parses the string representation of a nint using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nint ToNint(this string str, T dfltVal) where T : struct => nint.TryParse(str, out var num) ? num : dfltVal.ToNint(); - /// - /// Converts an enumerable of strings to an containing the nint representations of the strings, with an optional default value for conversion. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// - /// The default value for conversion if a string cannot be parsed to nint. - /// Used when conversion fails for a particular string. - /// - /// An containing the nint representations of the strings. public static IEnumerable ToNint(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -105,15 +55,6 @@ public static IEnumerable ToNint(this IEnumerable strs, T dfltV } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nint GenerateRandomNint(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToNint(); @@ -121,17 +62,6 @@ public static nint GenerateRandomNint(T1 min, T2 max) where T1 : struct return minValue > maxValue ? default : new Random().NextInt64(minValue, maxValue).ToNint(); } - /// - /// Generates an enumerable of random values between and , with a specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable, specifying the number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNints(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -140,17 +70,7 @@ public static IEnumerable GenerateRandomNints(T1 min, T2 max, T } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static nint GenerateRandomNint() => GenerateRandomNint(nint.MinValue, nint.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nint GenerateRandomNint(T max) where T : struct => GenerateRandomNint(nint.MinValue, max); } diff --git a/lib/YANLib/YANNum.Nuint.Nullable.cs b/lib/YANLib/YANNum.Nuint.Nullable.cs index 56111dd7..e8f4e12b 100644 --- a/lib/YANLib/YANNum.Nuint.Nullable.cs +++ b/lib/YANLib/YANNum.Nuint.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a (an unsigned integer type representing a pointer or a handle). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nuint ToNuint(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static nuint ToNuint(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an enumerable of values, which represent the unsigned integer equivalent of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the objects. public static IEnumerable ToNuint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToNuint(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nuint ToNuint(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToNuint(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an enumerable of values, which represent the unsigned integer equivalent of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for conversion. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for conversion in case of failure. - /// An enumerable of values representing the unsigned integer equivalent of the strings. public static IEnumerable ToNuint(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToNuint(this IEnumerable strs, T? df } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint GenerateRandomNuint(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNuint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomNuints(T1? min, T2 max } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomNuints(T1? min, T2 max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint GenerateRandomNuint(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomNuint(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomNuints(T1 min, T2? max } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomNuints(T1 min, T2? max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint GenerateRandomNuint(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomNuint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomNuints(T1? min, T2? ma } } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomNuints(T1? min, T2? ma } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nuint GenerateRandomNuint(T? max) where T : struct => max.HasValue ? GenerateRandomNuint(nuint.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Nuint.cs b/lib/YANLib/YANNum.Nuint.cs index c44ec55d..0f7f54a9 100644 --- a/lib/YANLib/YANNum.Nuint.cs +++ b/lib/YANLib/YANNum.Nuint.cs @@ -4,13 +4,7 @@ namespace YANLib; public static partial class YANNum { - /// - /// Converts the specified value to a (an unsigned integer type representing a pointer or a handle). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static nuint ToNuint(this T num) where T : struct { try @@ -23,16 +17,6 @@ public static nuint ToNuint(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an enumerable of values, which represent the unsigned integer equivalent of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the objects. public static IEnumerable ToNuint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -45,20 +29,8 @@ public static IEnumerable ToNuint(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static nuint ToNuint(this string str) => nuint.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an enumerable of values, which represent the unsigned integer equivalent of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// The enumerable of strings to be converted. - /// An enumerable of values representing the unsigned integer equivalent of the strings. public static IEnumerable ToNuint(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -71,27 +43,8 @@ public static IEnumerable ToNuint(this IEnumerable strs) } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static nuint ToNuint(this string str, T dfltVal) where T : struct => nuint.TryParse(str, out var num) ? num : dfltVal.ToNuint(); - /// - /// Converts an enumerable of strings to an enumerable of values, which represent the unsigned integer equivalent of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the default value to be used for conversion. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for conversion in case of failure. - /// An enumerable of values representing the unsigned integer equivalent of the strings. public static IEnumerable ToNuint(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -104,15 +57,6 @@ public static IEnumerable ToNuint(this IEnumerable strs, T dfl } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static nuint GenerateRandomNuint(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToNuint(); @@ -120,17 +64,6 @@ public static nuint GenerateRandomNuint(T1 min, T2 max) where T1 : struc return minValue > maxValue ? default : (new Random().NextInt64(nint.MinValue, (long)(maxValue - (minValue - (BigInteger)nint.MinValue))) - nint.MinValue).ToNuint() + minValue; } - /// - /// Generates an enumerable of random values between and with a specified size . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable to be generated. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomNuints(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -139,17 +72,7 @@ public static IEnumerable GenerateRandomNuints(T1 min, T2 max, } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static nuint GenerateRandomNuint() => GenerateRandomNuint(nuint.MinValue, nuint.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static nuint GenerateRandomNuint(T max) where T : struct => GenerateRandomNuint(nuint.MinValue, max); } diff --git a/lib/YANLib/YANNum.Sbyte.Nullable.cs b/lib/YANLib/YANNum.Sbyte.Nullable.cs index cd75a61e..fffec63a 100644 --- a/lib/YANLib/YANNum.Sbyte.Nullable.cs +++ b/lib/YANLib/YANNum.Sbyte.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a signed byte (sbyte). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static sbyte ToSbyte(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static sbyte ToSbyte(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the signed byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the signed byte representations of the objects. public static IEnumerable ToSbyte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToSbyte(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of an using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static sbyte ToSbyte(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToSbyte(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the signed byte representations of the strings, using the specified default value for invalid string representations. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid string representations. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for invalid string representations. - /// An containing the signed byte representations of the strings. public static IEnumerable ToSbyte(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToSbyte(this IEnumerable strs, T? df } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte GenerateRandomSbyte(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomSbyte(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomSbytes(T1? min, T2 max } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomSbytes(T1? min, T2 max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte GenerateRandomSbyte(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomSbyte(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomSbytes(T1 min, T2? max } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomSbytes(T1 min, T2? max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte GenerateRandomSbyte(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomSbyte(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomSbytes(T1? min, T2? ma } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomSbytes(T1? min, T2? ma } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static sbyte GenerateRandomSbyte(T? max) where T : struct => max.HasValue ? GenerateRandomSbyte(sbyte.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Sbyte.cs b/lib/YANLib/YANNum.Sbyte.cs index b13dd7a9..83bd2435 100644 --- a/lib/YANLib/YANNum.Sbyte.cs +++ b/lib/YANLib/YANNum.Sbyte.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a signed byte (sbyte). - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static sbyte ToSbyte(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static sbyte ToSbyte(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the signed byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the signed byte representations of the objects. public static IEnumerable ToSbyte(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToSbyte(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of a signed byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static sbyte ToSbyte(this string str) => sbyte.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the signed byte representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the signed byte representations of the strings. public static IEnumerable ToSbyte(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToSbyte(this IEnumerable strs) } } - /// - /// Parses the string representation of a signed byte using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static sbyte ToSbyte(this string str, T dfltVal) where T : struct => sbyte.TryParse(str, out var num) ? num : dfltVal.ToSbyte(); - /// - /// Converts an enumerable of strings to an containing the signed byte representations of the strings, using the specified default value for invalid string representations. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid string representations. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for invalid string representations. - /// An containing the signed byte representations of the strings. public static IEnumerable ToSbyte(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToSbyte(this IEnumerable strs, T dfl } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static sbyte GenerateRandomSbyte(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToSbyte(); @@ -118,17 +62,6 @@ public static sbyte GenerateRandomSbyte(T1 min, T2 max) where T1 : struc return minValue > maxValue ? default : new Random().Next(minValue, maxValue).ToSbyte(); } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate given by . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomSbytes(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomSbytes(T1 min, T2 max, } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static sbyte GenerateRandomSbyte() => GenerateRandomSbyte(sbyte.MinValue, sbyte.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static sbyte GenerateRandomSbyte(T max) where T : struct => GenerateRandomSbyte(sbyte.MinValue, max); } diff --git a/lib/YANLib/YANNum.Short.Nullable.cs b/lib/YANLib/YANNum.Short.Nullable.cs index e533805c..742a09f1 100644 --- a/lib/YANLib/YANNum.Short.Nullable.cs +++ b/lib/YANLib/YANNum.Short.Nullable.cs @@ -2,13 +2,7 @@ public partial class YANNum { - /// - /// Converts the specified value to a . - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static short ToShort(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static short ToShort(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the short integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the short integer representations of the objects. public static IEnumerable ToShort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToShort(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of a short using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static short ToShort(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToShort(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the short integer representations of the strings, using the specified default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for invalid or null strings. - /// An containing the short integer representations of the strings. public static IEnumerable ToShort(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToShort(this IEnumerable strs, T? df } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short GenerateRandomShort(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomShort(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomShorts(T1? min, T2 max } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomShorts(T1? min, T2 max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short GenerateRandomShort(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomShort(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomShorts(T1 min, T2? max } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomShorts(T1 min, T2? max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short GenerateRandomShort(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomShort(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomShorts(T1? min, T2? ma } } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomShorts(T1? min, T2? ma } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static short GenerateRandomShort(T? max) where T : struct => max.HasValue ? GenerateRandomShort(short.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Short.cs b/lib/YANLib/YANNum.Short.cs index 9b734b8d..6db99731 100644 --- a/lib/YANLib/YANNum.Short.cs +++ b/lib/YANLib/YANNum.Short.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a . - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static short ToShort(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static short ToShort(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the short integer representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the short integer representations of the objects. public static IEnumerable ToShort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToShort(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of a short integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static short ToShort(this string str) => short.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the short integer representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the short integer representations of the strings. public static IEnumerable ToShort(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToShort(this IEnumerable strs) } } - /// - /// Parses the string representation of a using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static short ToShort(this string str, T dfltVal) where T : struct => short.TryParse(str, out var num) ? num : dfltVal.ToShort(); - /// - /// Converts an enumerable of strings to an containing the short integer representations of the strings, using the specified default value for invalid or null strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used for invalid or null strings. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for invalid or null strings. - /// An containing the short integer representations of the strings. public static IEnumerable ToShort(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToShort(this IEnumerable strs, T dfl } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static short GenerateRandomShort(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToShort(); @@ -118,17 +62,6 @@ public static short GenerateRandomShort(T1 min, T2 max) where T1 : struc return minValue > maxValue ? default : new Random().Next(minValue, maxValue).ToShort(); } - /// - /// Generates an enumerable of random values between and , with the specified number of values to generate determined by the parameter. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of values to generate. - /// An containing the random short values between and . public static IEnumerable GenerateRandomShorts(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomShorts(T1 min, T2 max, } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static short GenerateRandomShort() => GenerateRandomShort(short.MinValue, short.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static short GenerateRandomShort(T max) where T : struct => GenerateRandomShort(short.MinValue, max); } diff --git a/lib/YANLib/YANNum.Uint.Nullable.cs b/lib/YANLib/YANNum.Uint.Nullable.cs index 33621d90..ee62d8c4 100644 --- a/lib/YANLib/YANNum.Uint.Nullable.cs +++ b/lib/YANLib/YANNum.Uint.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to an unsigned integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static uint ToUint(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static uint ToUint(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. public static IEnumerable ToUint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToUint(this IEnumerable nums) where T : s } } - /// - /// Parses the string representation of an unsigned integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static uint ToUint(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToUint(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the uint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for the conversion to uint. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value for the conversion to uint. - /// An containing the uint representations of the strings. public static IEnumerable ToUint(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,29 +41,8 @@ public static IEnumerable ToUint(this IEnumerable strs, T? dflt } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint GenerateRandomUint(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -107,18 +51,6 @@ public static IEnumerable GenerateRandomUints(T1? min, T2 max, } } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -127,29 +59,8 @@ public static IEnumerable GenerateRandomUints(T1? min, T2 max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint GenerateRandomUint(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomUint(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -158,18 +69,6 @@ public static IEnumerable GenerateRandomUints(T1 min, T2? max, } } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -178,29 +77,8 @@ public static IEnumerable GenerateRandomUints(T1 min, T2? max, } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint GenerateRandomUint(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUint(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -209,18 +87,6 @@ public static IEnumerable GenerateRandomUints(T1? min, T2? max, } } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -229,11 +95,5 @@ public static IEnumerable GenerateRandomUints(T1? min, T2? max, } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static uint GenerateRandomUint(T? max) where T : struct => max.HasValue ? GenerateRandomUint(uint.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Uint.cs b/lib/YANLib/YANNum.Uint.cs index e31e4fa6..e5369423 100644 --- a/lib/YANLib/YANNum.Uint.cs +++ b/lib/YANLib/YANNum.Uint.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to an unsigned integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static uint ToUint(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static uint ToUint(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the byte representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the byte representations of the objects. public static IEnumerable ToUint(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToUint(this IEnumerable nums) where T : st } } - /// - /// Parses the string representation of an unsigned integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static uint ToUint(this string str) => uint.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the uint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the uint representations of the strings. public static IEnumerable ToUint(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToUint(this IEnumerable strs) } } - /// - /// Parses the string representation of an unsigned integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static uint ToUint(this string str, T dfltVal) where T : struct => uint.TryParse(str, out var num) ? num : dfltVal.ToUint(); - /// - /// Converts an enumerable of strings to an containing the uint representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for the conversion to uint. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value for the conversion to uint. - /// An containing the uint representations of the strings. public static IEnumerable ToUint(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToUint(this IEnumerable strs, T dfltV } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static uint GenerateRandomUint(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToUint(); @@ -118,18 +62,6 @@ public static uint GenerateRandomUint(T1 min, T2 max) where T1 : struct return minValue > maxValue ? default : new Random().NextInt64(minValue, maxValue).ToUint(); } - /// - /// Generates an enumerable of random values between and . - /// The size of the enumerable is determined by the parameter. - /// If is greater than , an empty enumerable is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size parameter, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable. - /// An enumerable of random values between and . public static IEnumerable GenerateRandomUints(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -138,17 +70,7 @@ public static IEnumerable GenerateRandomUints(T1 min, T2 max, T } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static uint GenerateRandomUint() => GenerateRandomUint(uint.MinValue, uint.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static uint GenerateRandomUint(T max) where T : struct => GenerateRandomUint(uint.MinValue, max); } diff --git a/lib/YANLib/YANNum.Ulong.Nullable.cs b/lib/YANLib/YANNum.Ulong.Nullable.cs index 6a972f87..f4d7daf8 100644 --- a/lib/YANLib/YANNum.Ulong.Nullable.cs +++ b/lib/YANLib/YANNum.Ulong.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to an unsigned long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ulong ToUlong(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static ulong ToUlong(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ulong representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ulong representations of the objects. public static IEnumerable ToUlong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToUlong(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of an unsigned long integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ulong ToUlong(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToUlong(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the ulong representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used when converting strings to ulong. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used when converting strings to ulong. - /// An containing the ulong representations of the strings. public static IEnumerable ToUlong(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,29 +41,8 @@ public static IEnumerable ToUlong(this IEnumerable strs, T? df } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong GenerateRandomUlong(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUlong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -107,18 +51,6 @@ public static IEnumerable GenerateRandomUlongs(T1? min, T2 max } } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -127,29 +59,8 @@ public static IEnumerable GenerateRandomUlongs(T1? min, T2 max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong GenerateRandomUlong(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomUlong(min, max.Value) : default; - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -158,18 +69,6 @@ public static IEnumerable GenerateRandomUlongs(T1 min, T2? max } } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -178,29 +77,8 @@ public static IEnumerable GenerateRandomUlongs(T1 min, T2? max } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong GenerateRandomUlong(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUlong(min.Value, max) : default; - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -209,18 +87,6 @@ public static IEnumerable GenerateRandomUlongs(T1? min, T2? ma } } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -229,11 +95,5 @@ public static IEnumerable GenerateRandomUlongs(T1? min, T2? ma } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ulong GenerateRandomUlong(T? max) where T : struct => max.HasValue ? GenerateRandomUlong(ulong.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Ulong.cs b/lib/YANLib/YANNum.Ulong.cs index 2e1e359a..a9370941 100644 --- a/lib/YANLib/YANNum.Ulong.cs +++ b/lib/YANLib/YANNum.Ulong.cs @@ -4,13 +4,7 @@ namespace YANLib; public static partial class YANNum { - /// - /// Converts the specified value to an unsigned long integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ulong ToUlong(this T num) where T : struct { try @@ -23,16 +17,6 @@ public static ulong ToUlong(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ulong representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ulong representations of the objects. public static IEnumerable ToUlong(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -45,20 +29,8 @@ public static IEnumerable ToUlong(this IEnumerable nums) where T : } } - /// - /// Parses the string representation of an unsigned long integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static ulong ToUlong(this string str) => ulong.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the ulong representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the ulong representations of the strings. public static IEnumerable ToUlong(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -71,27 +43,8 @@ public static IEnumerable ToUlong(this IEnumerable strs) } } - /// - /// Parses the string representation of an using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ulong ToUlong(this string str, T dfltVal) where T : struct => ulong.TryParse(str, out var num) ? num : dfltVal.ToUlong(); - /// - /// Converts an enumerable of strings to an containing the ulong representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value to be used when converting strings to ulong. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used when converting strings to ulong. - /// An containing the ulong representations of the strings. public static IEnumerable ToUlong(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -104,15 +57,6 @@ public static IEnumerable ToUlong(this IEnumerable strs, T dfl } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ulong GenerateRandomUlong(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToUlong(); @@ -120,18 +64,6 @@ public static ulong GenerateRandomUlong(T1 min, T2 max) where T1 : struc return minValue > maxValue ? default : (new Random().NextInt64(long.MinValue, (long)(maxValue - (minValue - (BigInteger)long.MinValue))) - long.MinValue).ToUlong() + minValue; } - /// - /// Generates an enumerable of random values between and . - /// The number of values generated is determined by the value of . - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The number of random values to generate. - /// An containing the generated random ulong values. public static IEnumerable GenerateRandomUlongs(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -140,17 +72,7 @@ public static IEnumerable GenerateRandomUlongs(T1 min, T2 max, } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static ulong GenerateRandomUlong() => GenerateRandomUlong(ulong.MinValue, ulong.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ulong GenerateRandomUlong(T max) where T : struct => GenerateRandomUlong(ulong.MinValue, max); } diff --git a/lib/YANLib/YANNum.Ushort.Nullable.cs b/lib/YANLib/YANNum.Ushort.Nullable.cs index bbcd2add..feb336bb 100644 --- a/lib/YANLib/YANNum.Ushort.Nullable.cs +++ b/lib/YANLib/YANNum.Ushort.Nullable.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a unsigned short integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ushort ToUshort(this T? num) where T : struct { try @@ -21,16 +15,6 @@ public static ushort ToUshort(this T? num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ushort representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ushort representations of the objects. public static IEnumerable ToUshort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,27 +27,8 @@ public static IEnumerable ToUshort(this IEnumerable nums) where T } } - /// - /// Parses the string representation of a ushort using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ushort ToUshort(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToUshort(dfltVal.Value) : default; - /// - /// Converts an enumerable of strings to an containing the ushort representations of the strings, using the specified default value for conversion failure. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failure. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for conversion failure. - /// An containing the ushort representations of the strings. public static IEnumerable ToUshort(this IEnumerable strs, T? dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -76,28 +41,8 @@ public static IEnumerable ToUshort(this IEnumerable strs, T? } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort GenerateRandomUshort(T1? min, T2 max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUshort(min.Value, max) : default; - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -106,17 +51,6 @@ public static IEnumerable GenerateRandomUshorts(T1? min, T2 ma } } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2 max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -125,28 +59,8 @@ public static IEnumerable GenerateRandomUshorts(T1? min, T2 ma } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort GenerateRandomUshort(T1 min, T2? max) where T1 : struct where T2 : struct => max.HasValue ? GenerateRandomUshort(min, max.Value) : default; - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1 min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -155,17 +69,6 @@ public static IEnumerable GenerateRandomUshorts(T1 min, T2? ma } } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1 min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -174,28 +77,8 @@ public static IEnumerable GenerateRandomUshorts(T1 min, T2? ma } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort GenerateRandomUshort(T1? min, T2? max) where T1 : struct where T2 : struct => min.HasValue ? GenerateRandomUshort(min.Value, max) : default; - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2? max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -204,17 +87,6 @@ public static IEnumerable GenerateRandomUshorts(T1? min, T2? m } } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1? min, T2? max, T? size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -223,11 +95,5 @@ public static IEnumerable GenerateRandomUshorts(T1? min, T2? m } } - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ushort GenerateRandomUshort(T? max) where T : struct => max.HasValue ? GenerateRandomUshort(ushort.MinValue, max.Value) : default; } diff --git a/lib/YANLib/YANNum.Ushort.cs b/lib/YANLib/YANNum.Ushort.cs index eddf4310..d4c1e37b 100644 --- a/lib/YANLib/YANNum.Ushort.cs +++ b/lib/YANLib/YANNum.Ushort.cs @@ -2,13 +2,7 @@ public static partial class YANNum { - /// - /// Converts the specified value to a unsigned short integer. - /// Returns the converted value, or if the conversion fails. - /// - /// The type of the value to be converted, which must be a value type. - /// The value to be converted. - /// The converted value, or if the conversion fails. + public static ushort ToUshort(this T num) where T : struct { try @@ -21,16 +15,6 @@ public static ushort ToUshort(this T num) where T : struct } } - /// - /// Converts an enumerable of value-type objects of type to an containing the ushort representations of the objects. - /// Returns an empty sequence if the input enumerable is , empty, or contains only objects. - /// - /// - /// The type of the value-type objects to be converted. - /// Must be a value type. - /// - /// The enumerable of value-type objects to be converted. - /// An containing the ushort representations of the objects. public static IEnumerable ToUshort(this IEnumerable nums) where T : struct { if (nums is null || !nums.Any()) @@ -43,20 +27,8 @@ public static IEnumerable ToUshort(this IEnumerable nums) where T } } - /// - /// Parses the string representation of an unsigned short integer using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The string to be parsed. - /// The parsed value, or if the parsing fails. public static ushort ToUshort(this string str) => ushort.TryParse(str, out var num) ? num : default; - /// - /// Converts an enumerable of strings to an containing the ushort representations of the strings. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// The enumerable of strings to be converted. - /// An containing the ushort representations of the strings. public static IEnumerable ToUshort(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -69,27 +41,8 @@ public static IEnumerable ToUshort(this IEnumerable strs) } } - /// - /// Parses the string representation of an unsigned short using the default format. - /// Returns the parsed value, or if the parsing fails. - /// - /// The type of the default value to be returned, which must be a value type. - /// The string to be parsed. - /// The default value to be returned if the parsing fails. - /// The parsed value, or if the parsing fails. public static ushort ToUshort(this string str, T dfltVal) where T : struct => ushort.TryParse(str, out var num) ? num : dfltVal.ToUshort(); - /// - /// Converts an enumerable of strings to an containing the ushort representations of the strings, using the specified default value for conversion failure. - /// Returns an empty sequence if the input enumerable is , empty, or contains only strings. - /// - /// - /// The type of the default value for conversion failure. - /// Must be a value type. - /// - /// The enumerable of strings to be converted. - /// The default value to be used for conversion failure. - /// An containing the ushort representations of the strings. public static IEnumerable ToUshort(this IEnumerable strs, T dfltVal) where T : struct { if (strs is null || !strs.Any()) @@ -102,15 +55,6 @@ public static IEnumerable ToUshort(this IEnumerable strs, T d } } - /// - /// Generates a random value between and . - /// If is greater than , is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static ushort GenerateRandomUshort(T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToUshort(); @@ -118,17 +62,6 @@ public static ushort GenerateRandomUshort(T1 min, T2 max) where T1 : str return minValue > maxValue ? default : new Random().Next(minValue, maxValue).ToUshort(); } - /// - /// Generates an enumerable sequence of random values between and , with the specified size. - /// If is greater than , an empty sequence is returned. - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The type of the size value, which must be a value type. - /// The minimum value. - /// The maximum value. - /// The size of the enumerable sequence. - /// An enumerable sequence of random values between and . public static IEnumerable GenerateRandomUshorts(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -137,17 +70,7 @@ public static IEnumerable GenerateRandomUshorts(T1 min, T2 ma } } - /// - /// Generates a random value between and . - /// - /// A random value between and . public static ushort GenerateRandomUshort() => GenerateRandomUshort(ushort.MinValue, ushort.MaxValue); - /// - /// Generates a random value between and . - /// - /// The type of the maximum value, which must be a value type. - /// The maximum value. - /// A random value between and . public static ushort GenerateRandomUshort(T max) where T : struct => GenerateRandomUshort(ushort.MinValue, max); } diff --git a/lib/YANLib/YANNum.cs b/lib/YANLib/YANNum.cs index b57eaec6..97f0579e 100644 --- a/lib/YANLib/YANNum.cs +++ b/lib/YANLib/YANNum.cs @@ -2,12 +2,7 @@ public static partial class YANNum { - /// - /// Finds the minimum value in an array of values that implement the interface. - /// - /// The type of the values in the array. - /// The array of values to find the minimum value in. - /// The minimum value in the array. + public static T? Min(params T[] nums) where T : IComparable { if (nums is null || nums.Length < 1) @@ -25,12 +20,6 @@ public static partial class YANNum return min; } - /// - /// Finds the maximum value in an array of values that implement the interface. - /// - /// The type of the values in the array. - /// The array of values to find the maximum value in. - /// The maximum value in the array. public static T? Max(params T[] nums) where T : IComparable { if (nums is null || nums.Length < 1) diff --git a/lib/YANLib/YANPass.cs b/lib/YANLib/YANPass.cs index d40ce15e..1428d0c7 100644 --- a/lib/YANLib/YANPass.cs +++ b/lib/YANLib/YANPass.cs @@ -24,11 +24,7 @@ public class YANPass #endregion #region Methods - /// - /// Computes the hash value of the specified password, along with a randomly generated salt and other parameters, and returns the resulting string in a specific format. - /// - /// The password to hash. - /// A string in the format "hashValue|salt|iterations|algorithm", where "hashValue" is the computed hash value of the password, "salt" is the randomly generated salt used for hashing, "iterations" is the number of iterations used for the key derivation function, and "algorithm" is the name of the key derivation function used. + public string? Hash(string password) { if (password.IsNotNullAndWhiteSpace() && SaltSize > 0 && Iterations > 0 && KeySize > 0) @@ -39,12 +35,6 @@ public class YANPass return default; } - /// - /// Verifies the provided password against a stored hash and returns a indicating whether the password is valid. - /// - /// The password to verify. - /// The hash value to verify the password against. - /// if the provided password is valid; otherwise, . public bool Verify(string password, string strHash) { if (strHash.IsNotNullAndWhiteSpace() && SegmentDelimiter.IsNotEmptyAndWhiteSpace()) @@ -59,27 +49,10 @@ public bool Verify(string password, string strHash) return false; } - /// - /// Determines whether a password meets the standard requirements for password validation, which are: it contains at least one character, has a length of at least 8, and contains at least one lowercase letter, one uppercase letter, one digit, and one special character. - /// - /// The password string to validate. - /// if the password meets the standard requirements for password validation; otherwise, . public static bool IsValidPasswordStandard(string password) => password.IsNotNullAndWhiteSpace() && password.Length >= 8 && new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).+$").IsMatch(password); - /// - /// Determines whether a password meets the requirements for password validation, which are: it contains at least one character, has a length of at least the specified value, and contains at least one lowercase letter, one uppercase letter, one digit, and one special character. - /// - /// The password string to validate. - /// The minimum length for the password. - /// if the password meets the requirements for password validation; otherwise, . public static bool IsValidPassword(string password, T len) where T : struct => password.IsNotNullAndWhiteSpace() && password.Length >= len.ToByte() && new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).+$").IsMatch(password); - /// - /// Determines whether a password meets the standard requirements for password validation, which are: it contains at least one character, has a length of at least 8, and contains at least one lowercase letter, one uppercase letter, one digit, and one special character, in addition to any specified additional special characters. - /// - /// The password string to validate. - /// Additional special characters to require in the password. - /// if the password meets the standard requirements for password validation; otherwise, . public bool IsValidPassword(string password, params char[] splChars) { // has character @@ -98,12 +71,6 @@ public bool IsValidPassword(string password, params char[] splChars) return IsMatch(password, $@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[{Escape(new string(newPwdSplChar.ToArray()))}]).+$"); } - /// - /// Determines whether a password meets the standard requirements for password validation, which are: it contains at least one character, has a length of at least 8, and contains at least one lowercase letter, one uppercase letter, one digit, and one special character, in addition to any specified additional special characters. - /// - /// The password string to validate. - /// Additional special characters to require in the password. - /// if the password meets the standard requirements for password validation; otherwise, . public bool IsValidPassword(string password, IEnumerable splChars) { // has character @@ -122,13 +89,6 @@ public bool IsValidPassword(string password, IEnumerable splChars) return IsMatch(password, $@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[{Escape(new string(newPwdSplChar.ToArray()))}]).+$"); } - /// - /// Determines whether a password meets the requirements for password validation, which are: it contains at least one character, has a length of at least the specified value, and contains at least one lowercase letter, one uppercase letter, one digit, and one special character, in addition to any specified additional special characters. - /// - /// The password string to validate. - /// The minimum length for the password. - /// Additional special characters to require in the password. - /// if the password meets the requirements for password validation; otherwise, . public bool IsValidPassword(string password, T len, params char[] splChars) where T : struct { // has character @@ -147,13 +107,6 @@ public bool IsValidPassword(string password, T len, params char[] splChars) w return IsMatch(password, $@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[{Escape(new string(newPwdSplChar.ToArray()))}]).+$"); } - /// - /// Determines whether a password meets the requirements for password validation, which are: it contains at least one character, has a length of at least the specified value, and contains at least one lowercase letter, one uppercase letter, one digit, and one special character, in addition to any specified additional special characters. - /// - /// The password string to validate. - /// The minimum length for the password. - /// Additional special characters to require in the password. - /// if the password meets the requirements for password validation; otherwise, . public bool IsValidPassword(string password, T len, IEnumerable splChars) where T : struct { // has character diff --git a/lib/YANLib/YANProcess.cs b/lib/YANLib/YANProcess.cs index 50ae7b9f..6a095d35 100644 --- a/lib/YANLib/YANProcess.cs +++ b/lib/YANLib/YANProcess.cs @@ -5,12 +5,7 @@ namespace YANLib; public static partial class YANProcess { - /// - /// Asynchronously kills all running processes with the specified name by first attempting to close their main window, and if that fails, force-killing them. - /// After attempting to close the processes, this method waits for one second before force-killing any remaining processes to give them a chance to exit gracefully. - /// - /// The name of the processes to kill. - /// A representing the asynchronous operation. + public static async Task KillAllProcessesByName(this string name) { if (name.IsNotNullAndWhiteSpace()) @@ -26,12 +21,6 @@ await WhenAll(GetProcessesByName(name).Select(p => } } - /// - /// Asynchronously kills all running processes with any of the specified names by first attempting to close their main window, and if that fails, force-killing them. - /// After attempting to close the processes, this method waits for one second before force-killing any remaining processes to give them a chance to exit gracefully. - /// - /// The names of the processes to kill. - /// A representing the asynchronous operation. public static async Task KillAllProcessesByName(params string[] names) { if (names.IsNotNullAndWhiteSpace()) diff --git a/lib/YANLib/YANRandom.cs b/lib/YANLib/YANRandom.cs index 9249d4bd..ced34920 100644 --- a/lib/YANLib/YANRandom.cs +++ b/lib/YANLib/YANRandom.cs @@ -2,29 +2,11 @@ public static partial class YANRandom { - /// - /// Returns a random 32-bit signed integer value. - /// - /// The object. - /// A 32-bit signed integer value between 0 and 2,147,483,647 (inclusive). + public static int NextInt32(this Random rnd) => rnd.Next(0, 1 << 4) << 28 | rnd.Next(0, 1 << 28); - /// - /// Returns the next random value. - /// - /// The object. - /// A random value. public static decimal NextDecimal(this Random rnd) => new(rnd.NextInt32(), rnd.NextInt32(), rnd.NextInt32(), rnd.Next(2) is 1, (byte)rnd.Next(29)); - /// - /// Returns a random value between and . - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The object. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static float NextSingle(this Random rnd, T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToFloat(); @@ -32,15 +14,6 @@ public static float NextSingle(this Random rnd, T1 min, T2 max) where T1 return minValue < maxValue ? rnd.NextSingle() * (maxValue - minValue) + minValue : minValue == maxValue ? minValue : default; } - /// - /// Returns a random value between and . - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The object. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static double NextDouble(this Random rnd, T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToDouble(); @@ -48,15 +21,6 @@ public static double NextDouble(this Random rnd, T1 min, T2 max) where T return minValue < maxValue ? rnd.NextDouble() * (maxValue - minValue) + minValue : minValue == maxValue ? minValue : default; } - /// - /// Returns a random value between and . - /// - /// The type of the minimum value, which must be a value type. - /// The type of the maximum value, which must be a value type. - /// The object. - /// The minimum value. - /// The maximum value. - /// A random value between and . public static decimal NextDecimal(this Random rnd, T1 min, T2 max) where T1 : struct where T2 : struct { var minValue = min.ToDecimal(); diff --git a/lib/YANLib/YANTask.cs b/lib/YANLib/YANTask.cs index 72a19359..42834eba 100644 --- a/lib/YANLib/YANTask.cs +++ b/lib/YANLib/YANTask.cs @@ -5,28 +5,9 @@ namespace YANLib; public static partial class YANTask { - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// The value that the result of the completed task should match in order to be considered valid. - /// An enumerable of objects to wait for. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// + public static async ValueTask WaitAnyWithCondition(T goodRslt, params ValueTask[] tasks) where T : IComparable => await tasks.WaitAnyWithCondition(goodRslt); - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// An enumerable of objects to wait for. - /// The value that the result of the completed task should match in order to be considered valid. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// public static async ValueTask WaitAnyWithCondition(this IEnumerable> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Any()) @@ -40,28 +21,8 @@ public static partial class YANTask return default; } - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// The value that the result of the completed task should match in order to be considered valid. - /// An enumerable of objects to wait for. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// public static async ValueTask WaitAnyWithCondition(T goodRslt, params Task[] tasks) where T : IComparable => await tasks.WaitAnyWithCondition(goodRslt); - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// An enumerable of objects to wait for. - /// The value that the result of the completed task should match in order to be considered valid. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// public static async ValueTask WaitAnyWithCondition(this IEnumerable> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Any()) @@ -72,28 +33,8 @@ public static partial class YANTask return default; } - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// The value that the result of the completed task should match in order to be considered valid. - /// An enumerable of objects to wait for. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// public static async ValueTask WhenAnyWithCondition(T goodRslt, params ValueTask[] tasks) where T : IComparable => await tasks.WhenAnyWithCondition(goodRslt); - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// An enumerable of objects to wait for. - /// The value that the result of the completed task should match in order to be considered valid. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// public static async ValueTask WhenAnyWithCondition(this IEnumerable> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Any()) @@ -113,28 +54,8 @@ public static partial class YANTask return default; } - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// The value that the result of the completed task should match in order to be considered valid. - /// An enumerable of objects to wait for. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// public static async ValueTask WhenAnyWithCondition(T goodRslt, params Task[] tasks) where T : IComparable => await tasks.WhenAnyWithCondition(goodRslt); - /// - /// Waits for any of the specified objects in an enumerable of to complete and returns a nullable result that matches the specified condition. - /// - /// The type of the value to be returned, which must be a value type. - /// An enumerable of objects to wait for. - /// The value that the result of the completed task should match in order to be considered valid. - /// - /// A that represents the asynchronous operation. - /// The result of the operation is the value of the completed task that matches the specified condition, or if no such task completed successfully. - /// public static async ValueTask WhenAnyWithCondition(this IEnumerable> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Any()) diff --git a/lib/YANLib/YANText.Char.cs b/lib/YANLib/YANText.Char.cs index a26fc893..ae7d2479 100644 --- a/lib/YANLib/YANText.Char.cs +++ b/lib/YANLib/YANText.Char.cs @@ -4,315 +4,93 @@ namespace YANLib; public static partial class YANText { - /// - /// Determines whether the specified character is the null character (). - /// - /// The character to check. - /// if the character is the null character (); otherwise, . + public static bool IsEmpty(this char c) => c is char.MinValue; - /// - /// Determines whether any of the specified characters in the enumerable is or . - /// - /// The characters to check. - /// if any of the characters in the enumerable is or ; otherwise, . public static bool IsEmpty(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotEmpty()); - /// - /// Determines whether any of the specified characters in the enumerable is or . - /// - /// The characters to check. - /// if any of the characters in the enumerable is or ; otherwise, . public static bool IsEmpty(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotEmpty()); - /// - /// Determines whether the specified character is a white space character, including space, tab, and line break characters. - /// - /// The character to check. - /// if the character is a white space character; otherwise, . public static bool IsWhiteSpace(this char c) => char.IsWhiteSpace(c); - /// - /// Determines whether any of the specified characters in the enumerable is a white space character, including space, tab, and line break characters. - /// - /// The characters to check. - /// if any of the characters in the enumerable is a white space character; otherwise, . public static bool IsWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotWhiteSpace()); - /// - /// Determines whether any of the specified characters in the enumerable is a white space character, including space, tab, and line break characters. - /// - /// The characters to check. - /// if any of the characters in the enumerable is a white space character; otherwise, . public static bool IsWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotWhiteSpace()); - /// - /// Determines whether the specified character is the null character () or white space. - /// - /// The character to check. - /// if the character is the null character () or white space; otherwise, . public static bool IsNullOrWhiteSpace(this char c) => c.IsEmpty() || c.IsWhiteSpace(); - /// - /// Determines whether any of the specified characters in the enumerable is or or whitespace. - /// - /// The characters to check. - /// if any of the characters in the enumerable is or or whitespace; otherwise, . public static bool IsNullOrWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace()); - /// - /// Determines whether any of the specified characters in the enumerable is or or whitespace. - /// - /// The characters to check. - /// if any of the characters in the enumerable is or or whitespace; otherwise, . public static bool IsNullOrWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace()); - /// - /// Determines whether the specified character is an alphabetic character, which includes letters from any language, or is the null character () or a white space character. - /// - /// The character to check. - /// if the character is an alphabetic character, or is the null character () or a white space character; otherwise, . public static bool IsAlphabetic(this char c) => char.IsLetter(c); - /// - /// Determines whether any of the specified characters in the enumerable is an alphabetic character, which includes letters from any language, or is , or is the null character (), or is a white space character. - /// - /// The characters to check. - /// if any of the characters in the enumerable is an alphabetic character, or is , or is the null character (), or is a white space character; otherwise, . public static bool IsAlphabetic(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotAlphabetic()); - /// - /// Determines whether any of the specified characters in the enumerable is an alphabetic character, which includes letters from any language, or is , or is the null character (), or is a white space character. - /// - /// The characters to check. - /// if any of the characters in the enumerable is an alphabetic character, or is , or is the null character (), or is a white space character; otherwise, . public static bool IsAlphabetic(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotAlphabetic()); - /// - /// Determines whether the specified character is a punctuation character, such as period, comma, exclamation mark, etc., or is the null character () or a white space character. - /// - /// The character to check. - /// if the character is a punctuation character, or is the null character () or a white space character; otherwise, . public static bool IsPunctuation(this char c) => char.IsPunctuation(c); - /// - /// Determines whether any of the specified characters in the enumerable is a punctuation character, such as period, comma, exclamation mark, etc., or is or or whitespace. - /// - /// The characters to check. - /// if any of the characters in the enumerable is a punctuation character, or is or or whitespace; otherwise, . public static bool IsPunctuation(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotPunctuation()); - /// - /// Determines whether any of the specified characters in the enumerable is a punctuation character, such as period, comma, exclamation mark, etc., or is or or whitespace. - /// - /// The characters to check. - /// if any of the characters in the enumerable is a punctuation character, or is or or whitespace; otherwise, . public static bool IsPunctuation(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotPunctuation()); - /// - /// Determines whether the specified character is a numeric character, such as 0-9, or is the null character () or a punctuation character, such as period, comma, exclamation mark, etc. - /// - /// The character to check. - /// if the character is a numeric character, or is the null character () or a punctuation character; otherwise, . public static bool IsNumber(this char c) => char.IsDigit(c); - /// - /// Determines whether any of the specified characters in the enumerable is a numeric character, such as 0-9, or is or or whitespace, or is a punctuation character, such as period, comma, exclamation mark, etc. - /// - /// The characters to check. - /// if any of the characters in the enumerable is a numeric character, or is or or whitespace, or is a punctuation character; otherwise, . public static bool IsNumber(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotNumber()); - /// - /// Determines whether any of the specified characters in the enumerable is a numeric character, such as 0-9, or is or or whitespace, or is a punctuation character, such as period, comma, exclamation mark, etc. - /// - /// The characters to check. - /// if any of the characters in the enumerable is a numeric character, or is or or whitespace, or is a punctuation character; otherwise, . public static bool IsNumber(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotNumber()); - /// - /// Determines whether the specified characters are equal, comparing their Unicode values. - /// - /// The first character to compare. - /// The second character to compare. - /// if the characters are equal, comparing their Unicode values; otherwise, . public static bool Equals(this char c1, char c2) => c1 == c2; - /// - /// Determines whether any of the specified characters in the enumerable are equal to the first character in the enumerable, comparing their Unicode values. - /// - /// The characters to compare. - /// if any of the characters in the enumerable are equal to the first character in the enumerable, comparing their Unicode values; otherwise, . public static bool Equals(params char[] cs) => cs is not null && !cs.Any(s => s.NotEquals(cs[0])); - /// - /// Determines whether any of the specified characters in the enumerable are equal to the first character in the enumerable, comparing their Unicode values. - /// - /// The characters to compare. - /// if any of the characters in the enumerable are equal to the first character in the enumerable, comparing their Unicode values; otherwise, . public static bool Equals(this IEnumerable cs) => cs is not null && !cs.Any(s => s.NotEquals(cs.First())); - /// - /// Determines whether the specified characters are equal, ignoring their casing, and comparing their Unicode values. - /// - /// The first character to compare. - /// The second character to compare. - /// if the characters are equal, ignoring their casing, and comparing their Unicode values; otherwise, . public static bool EqualsIgnoreCase(this char c1, char c2) => c1.ToLowerInvariant() == c2.ToLowerInvariant(); - /// - /// Determines whether any of the specified characters in the enumerable are equal to the first character in the enumerable, ignoring their casing, and comparing their Unicode values. - /// - /// The characters to compare. - /// if any of the characters in the enumerable are equal to the first character in the enumerable, ignoring their casing, and comparing their Unicode values; otherwise, . public static bool EqualsIgnoreCase(params char[] cs) => cs is not null && !cs.Any(s => s.NotEqualsIgnoreCase(cs[0])); - /// - /// Determines whether any of the specified characters in the enumerable are equal to the first character in the enumerable, ignoring their casing, and comparing their Unicode values. - /// - /// The characters to compare. - /// if any of the characters in the enumerable are equal to the first character in the enumerable, ignoring their casing, and comparing their Unicode values; otherwise, . public static bool EqualsIgnoreCase(this IEnumerable cs) => cs is not null && !cs.Any(s => s.NotEqualsIgnoreCase(cs.First())); - /// - /// Determines whether the specified character is not the null character (). - /// - /// The character to check. - /// if the character is not the null character (); otherwise, . public static bool IsNotEmpty(this char c) => c is not char.MinValue; - /// - /// Determines whether any of the specified characters in the enumerable is not and not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not and not ; otherwise, . public static bool IsNotEmpty(params char[] cs) => cs is not null && !cs.Any(c => c.IsEmpty()); - /// - /// Determines whether any of the specified characters in the enumerable is not and not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not and not ; otherwise, . public static bool IsNotEmpty(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsEmpty()); - /// - /// Determines whether the specified character is not a whitespace character, including space, tab, newline, carriage return, form feed, or vertical tab. - /// - /// The character to check. - /// if the character is not a whitespace character; otherwise, . public static bool IsNotWhiteSpace(this char c) => !char.IsWhiteSpace(c); - /// - /// Determines whether any of the specified characters in the enumerable is not a whitespace character, including space, tab, newline, carriage return, form feed, or vertical tab. - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a whitespace character; otherwise, . public static bool IsNotWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsWhiteSpace()); - /// - /// Determines whether any of the specified characters in the enumerable is not a whitespace character, including space, tab, newline, carriage return, form feed, or vertical tab. - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a whitespace character; otherwise, . public static bool IsNotWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsWhiteSpace()); - /// - /// Determines whether the specified character is not the null character () and is not a whitespace character. - /// - /// The character to check. - /// if the character is not the null character () and is not a whitespace character; otherwise, . public static bool IsNotEmptyAndWhiteSpace(this char c) => c.IsNotEmpty() && c.IsNotWhiteSpace(); - /// - /// Determines whether any of the specified characters in the enumerable is not a white-space character or . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a white-space character or ; otherwise, . public static bool IsNotEmptyAndWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNullOrWhiteSpace()); - /// - /// Determines whether any of the specified characters in the enumerable is not a white-space character or . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a white-space character or ; otherwise, . public static bool IsNotEmptyAndWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNullOrWhiteSpace()); - /// - /// Determines whether the specified character is not an alphabetic character and is not the null character () and is not a whitespace character. - /// - /// The character to check. - /// if the character is not an alphabetic character and is not the null character () and is not a whitespace character; otherwise, . public static bool IsNotAlphabetic(this char c) => !char.IsLetter(c); - /// - /// Determines whether any of the specified characters in the enumerable is not an alphabetic character, not a white-space character, or not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not an alphabetic character, not a white-space character, or not ; otherwise, . public static bool IsNotAlphabetic(params char[] cs) => cs is not null && !cs.Any(c => c.IsAlphabetic()); - /// - /// Determines whether any of the specified characters in the enumerable is not an alphabetic character, not a white-space character, or not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not an alphabetic character, not a white-space character, or not ; otherwise, . public static bool IsNotAlphabetic(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsAlphabetic()); - /// - /// Determines whether the specified character is not a punctuation character, not an alphabetic character, not the null character (), and not a whitespace character. - /// - /// The character to check. - /// if the character is not a punctuation character, not an alphabetic character, not the null character (), and not a whitespace character; otherwise, . public static bool IsNotPunctuation(this char c) => !char.IsPunctuation(c); - /// - /// Determines whether any of the specified characters in the enumerable is not a punctuation character, not an alphabetic character, not a white-space character, or not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a punctuation character, not an alphabetic character, not a white-space character, or not ; otherwise, . public static bool IsNotPunctuation(params char[] cs) => cs is not null && !cs.Any(c => c.IsPunctuation()); - /// - /// Determines whether any of the specified characters in the enumerable is not a punctuation character, not an alphabetic character, not a white-space character, or not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a punctuation character, not an alphabetic character, not a white-space character, or not ; otherwise, . public static bool IsNotPunctuation(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsPunctuation()); - /// - /// Determines whether the specified character is not a numeric character, not a punctuation character, not an alphabetic character, not the null character (), and not a whitespace character. - /// - /// The character to check. - /// if the character is not a numeric character, not a punctuation character, not an alphabetic character, not the null character (), and not a whitespace character; otherwise, . public static bool IsNotNumber(this char c) => !char.IsDigit(c); - /// - /// Determines whether any of the specified characters in the enumerable is not a numeric character, not a punctuation character, not an alphabetic character, not a white-space character, or not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a numeric character, not a punctuation character, not an alphabetic character, not a white-space character, or not ; otherwise, . public static bool IsNotNumber(params char[] cs) => cs is not null && !cs.Any(c => c.IsNumber()); - /// - /// Determines whether any of the specified characters in the enumerable is not a numeric character, not a punctuation character, not an alphabetic character, not a white-space character, or not . - /// - /// The characters to check. - /// if any of the characters in the enumerable is not a numeric character, not a punctuation character, not an alphabetic character, not a white-space character, or not ; otherwise, . public static bool IsNotNumber(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNumber()); - /// - /// Determines whether two specified characters are not equal, based on their Unicode values. - /// - /// The first character to compare. - /// The second character to compare. - /// if the two characters are not equal, based on their Unicode values; otherwise, . public static bool NotEquals(this char c1, char c2) => c1 != c2; - /// - /// Determines whether all the characters in the specified enumerable are distinct, based on their Unicode values. - /// - /// The characters to check. - /// if all the characters in the specified enumerable are distinct, based on their Unicode values; otherwise, . public static bool NotEquals(params char[] cs) { if (cs is null || cs.Length < 2) @@ -330,11 +108,6 @@ public static bool NotEquals(params char[] cs) return true; } - /// - /// Determines whether all the characters in the specified enumerable are distinct, based on their Unicode values. - /// - /// The characters to check. - /// if all the characters in the specified enumerable are distinct, based on their Unicode values; otherwise, . public static bool NotEquals(this IEnumerable cs) { if (cs is null || cs.Count() < 2) @@ -352,19 +125,8 @@ public static bool NotEquals(this IEnumerable cs) return true; } - /// - /// Determines whether two specified characters are not equal, ignoring their casing, based on their Unicode values. - /// - /// The first character to compare. - /// The second character to compare. - /// if the two characters are not equal, ignoring their casing, based on their Unicode values; otherwise, . public static bool NotEqualsIgnoreCase(this char c1, char c2) => c1.ToLowerInvariant() != c2.ToLowerInvariant(); - /// - /// Determines whether all the characters in the specified enumerable are distinct, ignoring their casing, based on their Unicode values. - /// - /// The characters to check. - /// if all the characters in the specified enumerable are distinct, ignoring their casing, based on their Unicode values; otherwise, . public static bool NotEqualsIgnoreCase(params char[] cs) { if (cs is null || cs.Length < 2) @@ -382,11 +144,6 @@ public static bool NotEqualsIgnoreCase(params char[] cs) return true; } - /// - /// Determines whether all the characters in the specified enumerable are distinct, ignoring their casing, based on their Unicode values. - /// - /// The characters to check. - /// if all the characters in the specified enumerable are distinct, ignoring their casing, based on their Unicode values; otherwise, . public static bool NotEqualsIgnoreCase(this IEnumerable cs) { if (cs is null || cs.Count() < 2) @@ -404,43 +161,18 @@ public static bool NotEqualsIgnoreCase(this IEnumerable cs) return true; } - /// - /// Returns the non-null character value or if it is or empty. - /// - /// The character to retrieve the value from. - /// The non-null character value or if it is or empty. public static char GetValue(this char c) => c.IsEmpty() ? char.MinValue : c; - /// - /// Returns the non-null character value or the default value if it is . - /// - /// The character to retrieve the value from. - /// The default value to return if the character is . - /// The non-null character value or the default value if it is . public static char GetValue(this char c, char dfltVal) => c.IsEmpty() ? dfltVal : c; - /// - /// Generates a random lowercase character from the English alphabet. - /// - /// A randomly generated lowercase character from the English alphabet. public static char GenerateRandomCharacter() { var chars = "abcdefghijklmnopqrstuvwxyz"; return chars[GenerateRandomByte(chars.Length)]; } - /// - /// Converts the character to lowercase if it is not empty or whitespace; otherwise, returns the original character. - /// - /// The character to convert to lowercase. - /// The lowercase version of the character if it is not empty or whitespace; otherwise, the original character. public static char ToLower(this char c) => c.IsNotEmptyAndWhiteSpace() ? char.ToLower(c) : c; - /// - /// Enumerates through an enumerable of characters and returns a new enumerable of characters converted to lowercase, ignoring their casing, based on their Unicode values. - /// - /// The characters to convert to lowercase. - /// An enumerable of characters converted to lowercase, ignoring their casing, based on their Unicode values. public static IEnumerable ToLower(this IEnumerable cs) { if (cs is null || !cs.Any()) @@ -453,10 +185,6 @@ public static IEnumerable ToLower(this IEnumerable cs) } } - /// - /// Converts the characters in the specified list to lowercase, ignoring their casing, based on their Unicode values. - /// - /// The list of characters to convert to lowercase. public static void ToLower(this IList cs) { if (cs is not null && cs.Count > 0) @@ -468,18 +196,8 @@ public static void ToLower(this IList cs) } } - /// - /// Converts the character to lowercase using the invariant culture, if it is not empty or whitespace; otherwise, returns the original character. - /// - /// The character to convert to lowercase. - /// The lowercase version of the character using the invariant culture if it is not empty or whitespace; otherwise, the original character. public static char ToLowerInvariant(this char c) => c.IsNotEmptyAndWhiteSpace() ? char.ToLowerInvariant(c) : c; - /// - /// Enumerates through an enumerable of characters and returns a new enumerable of characters converted to lowercase, ignoring their casing, based on their Unicode values using the invariant culture. - /// - /// The characters to convert to lowercase. - /// An enumerable of characters converted to lowercase, ignoring their casing, based on their Unicode values using the invariant culture. public static IEnumerable ToLowerInvariant(this IEnumerable cs) { if (cs is null || !cs.Any()) @@ -492,10 +210,6 @@ public static IEnumerable ToLowerInvariant(this IEnumerable cs) } } - /// - /// Converts all characters in the specified character list to lowercase using the invariant culture, by modifying the list in-place. - /// - /// The character list to convert to lowercase. public static void ToLowerInvariant(this IList cs) { if (cs is not null && cs.Count > 0) @@ -507,18 +221,8 @@ public static void ToLowerInvariant(this IList cs) } } - /// - /// Converts the character to uppercase using the invariant culture, if it is not empty or whitespace; otherwise, returns the original character. - /// - /// The character to convert to uppercase. - /// The uppercase version of the character using the invariant culture if it is not empty or whitespace; otherwise, the original character. public static char ToUpper(this char c) => c.IsNotEmptyAndWhiteSpace() ? char.ToUpper(c) : c; - /// - /// Enumerates through an enumerable of characters and returns a new enumerable of characters converted to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. - /// - /// The characters to convert to uppercase. - /// An enumerable of characters converted to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. public static IEnumerable ToUpper(this IEnumerable cs) { if (cs is null || !cs.Any()) @@ -531,10 +235,6 @@ public static IEnumerable ToUpper(this IEnumerable cs) } } - /// - /// Converts all characters in the specified character list to uppercase, by modifying the list in-place. - /// - /// The character list to convert to uppercase. public static void ToUpper(this IList cs) { if (cs is not null && cs.Count > 0) @@ -546,18 +246,8 @@ public static void ToUpper(this IList cs) } } - /// - /// Converts the character to uppercase using the invariant culture, if it is not empty or whitespace; otherwise, returns the original character. - /// - /// The character to convert to uppercase. - /// The uppercase version of the character using the invariant culture if it is not empty or whitespace; otherwise, the original character. public static char ToUpperInvariant(this char c) => c.IsNotEmptyAndWhiteSpace() ? char.ToUpperInvariant(c) : c; - /// - /// Enumerates through an enumerable of characters and returns a new enumerable of characters converted to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. - /// - /// The characters to convert to uppercase. - /// An enumerable of characters converted to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. public static IEnumerable ToUpperInvariant(this IEnumerable cs) { if (cs is null || !cs.Any()) @@ -570,10 +260,6 @@ public static IEnumerable ToUpperInvariant(this IEnumerable cs) } } - /// - /// Converts all characters in the specified character list to uppercase using the invariant culture, by modifying the list in-place. - /// - /// The character list to convert to uppercase. public static void ToUpperInvariant(this IList cs) { if (cs is not null && cs.Count > 0) diff --git a/lib/YANLib/YANText.String.cs b/lib/YANLib/YANText.String.cs index 962ce4c9..ad3b952b 100644 --- a/lib/YANLib/YANText.String.cs +++ b/lib/YANLib/YANText.String.cs @@ -1,193 +1,62 @@ using System.Globalization; using static System.StringComparison; +using static System.Globalization.CultureInfo; namespace YANLib; public static partial class YANText { - /// - /// Determines whether the specified string is . - /// - /// The string to check. - /// if the string is ; otherwise, . + public static bool IsNull(this string str) => str is null; - /// - /// Determines whether any of the specified strings in the enumerable is . - /// - /// The strings to check. - /// if any of the strings in the enumerable is ; otherwise, . public static bool IsNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNull()); - /// - /// Determines whether any of the specified strings in the enumerable is . - /// - /// The strings to check. - /// if any of the strings in the enumerable is ; otherwise, . public static bool IsNull(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNull()); - /// - /// Determines whether the specified string is or . - /// - /// The string to check. - /// if the string is or ; otherwise, . public static bool IsNullOrEmpty(this string str) => string.IsNullOrEmpty(str); - /// - /// Determines whether any of the specified strings in the enumerable is or . - /// - /// The strings to check. - /// if any of the strings in the enumerable is or ; otherwise, . public static bool IsNullOrEmpty(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNullAndEmpty()); - /// - /// Determines whether any of the specified strings in the enumerable is or . - /// - /// The strings to check. - /// if any of the strings in the enumerable is or ; otherwise, . public static bool IsNullOrEmpty(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNullAndEmpty()); - /// - /// Determines whether the specified string is , , or consists only of white-space characters. - /// - /// The string to check. - /// if the string is , , or consists only of white-space characters; otherwise, . public static bool IsNullOrWhiteSpace(this string str) => string.IsNullOrWhiteSpace(str); - /// - /// Determines whether any of the specified strings in the enumerable is , , or consists only of white-space characters. - /// - /// The strings to check. - /// if any of the strings in the enumerable is , , or consists only of white-space characters; otherwise, . public static bool IsNullOrWhiteSpace(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNullAndWhiteSpace()); - /// - /// Determines whether any of the specified strings in the enumerable is , , or consists only of white-space characters. - /// - /// The strings to check. - /// if any of the strings in the enumerable is , , or consists only of white-space characters; otherwise, . public static bool IsNullOrWhiteSpace(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNullAndWhiteSpace()); - /// - /// Determines whether the specified strings are equal, comparing their values. - /// - /// The first string to compare. - /// The second string to compare. - /// if the strings are equal, comparing their values; otherwise, . public static bool Equals(this string str1, string str2) => str1 == str2; - /// - /// Determines whether any of the specified strings in the enumerable are equal to the first string in the enumerable, comparing their values. - /// - /// The strings to compare. - /// if any of the strings in the enumerable are equal to the first string in the enumerable, comparing their values; otherwise, . public static bool Equals(params string[] strs) => strs is not null && !strs.Any(s => s.NotEquals(strs[0])); - /// - /// Determines whether any of the specified strings in the enumerable are equal to the first string in the enumerable, comparing their values. - /// - /// The strings to compare. - /// if any of the strings in the enumerable are equal to the first string in the enumerable, comparing their values; otherwise, . public static bool Equals(this IEnumerable strs) => strs is not null && !strs.Any(s => s.NotEquals(strs.First())); - /// - /// Determines whether the specified strings are equal, ignoring their casing, and comparing their values using ordinal comparison. - /// - /// The first string to compare. - /// The second string to compare. - /// if the strings are equal, ignoring their casing, and comparing their values using ordinal comparison; otherwise, . public static bool EqualsIgnoreCase(this string str1, string str2) => IsNull(str1, str2) || str1.IsNotNull() && str1.IsNotNull() && string.Equals(str1, str2, OrdinalIgnoreCase); - /// - /// Determines whether the specified strings are equal, ignoring their casing, and comparing their values using ordinal comparison. - /// - /// The strings to compare. - /// if any of the strings in the enumerable are equal to the first string in the enumerable, ignoring their casing, and comparing their values using ordinal comparison; otherwise, . public static bool EqualsIgnoreCase(params string[] strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs[0])); - /// - /// Determines whether the specified strings are equal, ignoring their casing, and comparing their values using ordinal comparison. - /// - /// The strings to compare. - /// if any of the strings in the enumerable are equal to the first string in the enumerable, ignoring their casing, and comparing their values using ordinal comparison; otherwise, . public static bool EqualsIgnoreCase(this IEnumerable strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs.First())); - /// - /// Determines whether the specified string is not . - /// - /// The string to check. - /// if the string is not ; otherwise, . public static bool IsNotNull(this string str) => str is not null; - /// - /// Determines whether the specified strings are not . - /// - /// The strings to check. - /// if all the strings in the enumerable are not ; otherwise, . public static bool IsNotNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNull()); - /// - /// Determines whether the specified strings are not . - /// - /// The strings to check. - /// if all the strings in the enumerable are not ; otherwise, . public static bool IsNotNull(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNull()); - /// - /// Determines whether the specified string is not or . - /// - /// The string to check. - /// if the string is not or ; otherwise, . public static bool IsNotNullAndEmpty(this string str) => !string.IsNullOrEmpty(str); - /// - /// Determines whether any of the specified strings is not or . - /// - /// The strings to check. - /// if any of the strings is not or ; otherwise, . public static bool IsNotNullAndEmpty(params string[] strs) => strs is not null && !strs.Any(s => s.IsNullOrEmpty()); - /// - /// Determines whether any of the specified strings in the enumerable is not or . - /// - /// The strings to check. - /// if any of the strings in the enumerable is not or ; otherwise, . public static bool IsNotNullAndEmpty(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNullOrEmpty()); - /// - /// Determines whether the specified string is not , , or consists only of whitespace characters. - /// - /// The string to check. - /// if the string is not , , or consists only of whitespace characters; otherwise, . public static bool IsNotNullAndWhiteSpace(this string str) => !string.IsNullOrWhiteSpace(str); - /// - /// Determines whether all the specified strings are not , , or consist only of whitespace characters. - /// - /// The strings to check. - /// if all the strings are not , , or consist only of whitespace characters; otherwise, . public static bool IsNotNullAndWhiteSpace(params string[] strs) => strs is not null && !strs.Any(s => s.IsNullOrWhiteSpace()); - /// - /// Determines whether all the specified strings in the enumerable are not , , or consist only of whitespace characters. - /// - /// The strings to check. - /// if all the strings in the enumerable are not , , or consist only of whitespace characters; otherwise, . public static bool IsNotNullAndWhiteSpace(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNullOrWhiteSpace()); - /// - /// Determines whether two specified strings are not equal, based on their values. - /// - /// The first string to compare. - /// The second string to compare. - /// if the two strings are not equal, based on their values; otherwise, . public static bool NotEquals(this string str1, string str2) => str1 != str2; - /// - /// Determines whether all the strings in the specified enumerable are distinct, based on their values. - /// - /// The strings to check. - /// if all the strings in the specified enumerable are distinct, based on their values; otherwise, . public static bool NotEquals(params string[] strs) { if (strs is null || strs.Length < 2) @@ -205,11 +74,6 @@ public static bool NotEquals(params string[] strs) return true; } - /// - /// Determines whether all the strings in the specified enumerable are distinct, based on their values. - /// - /// The strings to check. - /// if all the strings in the specified enumerable are distinct, based on their values; otherwise, . public static bool NotEquals(this IEnumerable strs) { if (strs is null || strs.Count() < 2) @@ -227,19 +91,8 @@ public static bool NotEquals(this IEnumerable strs) return true; } - /// - /// Determines whether two specified strings are not equal, ignoring their casing, based on their values using ordinal comparison. - /// - /// The first string to compare. - /// The second string to compare. - /// if the two strings are not equal, ignoring their casing, based on their values using ordinal comparison; otherwise, . public static bool NotEqualsIgnoreCase(this string str1, string str2) => IsNotNull(str1, str2) && !string.Equals(str1, str2, OrdinalIgnoreCase); - /// - /// Determines whether all the strings in the specified enumerable are distinct, ignoring their casing, based on their values using ordinal comparison. - /// - /// The strings to check. - /// if all the strings in the specified enumerable are distinct, ignoring their casing, based on their values using ordinal comparison; otherwise, . public static bool NotEqualsIgnoreCase(params string[] strs) { if (strs is null || strs.Length < 1) @@ -257,11 +110,6 @@ public static bool NotEqualsIgnoreCase(params string[] strs) return true; } - /// - /// Determines whether all the strings in the specified enumerable are distinct, ignoring their casing, based on their values using ordinal comparison. - /// - /// The strings to check. - /// if all the strings in the specified enumerable are distinct, ignoring their casing, based on their values using ordinal comparison; otherwise, . public static bool NotEqualsIgnoreCase(this IEnumerable strs) { if (strs is null || strs.Count() < 2) @@ -279,44 +127,14 @@ public static bool NotEqualsIgnoreCase(this IEnumerable strs) return true; } - /// - /// Returns the non-null string value or if it is . - /// - /// The string to retrieve the value from. - /// The non-null string value or if it is . public static string GetValue(this string str) => str ?? string.Empty; - /// - /// Returns the non-null string value or the default value if it is . - /// - /// The string to retrieve the value from. - /// The default value to return if the string is . - /// The non-null string value or the default value if it is . public static string GetValue(this string str, string dfltVal) => str ?? dfltVal; - /// - /// Returns the non-null string value or the default value if it is . - /// - /// The string to retrieve the value from. - /// The default character value to return if the string is . - /// - /// The non-null string value or the default value if it is . - /// If the default character value is not a valid character, an empty string is returned. - /// public static string GetValue(this string str, char dfltVal) => str ?? (dfltVal.IsNotEmpty() ? dfltVal.ToString() : string.Empty); - /// - /// Converts the string to lowercase if it is not empty or whitespace; otherwise, returns the original string. - /// - /// The string to convert to lowercase. - /// The lowercase version of the string if it is not empty or whitespace; otherwise, the original string. public static string ToLower(this string str) => str.IsNotNullAndWhiteSpace() ? str.ToLower() : str; - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings converted to lowercase, ignoring their casing, based on their Unicode values. - /// - /// The strings to convert to lowercase. - /// An enumerable of strings converted to lowercase, ignoring their casing, based on their Unicode values. public static IEnumerable ToLower(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -329,10 +147,6 @@ public static IEnumerable ToLower(this IEnumerable strs) } } - /// - /// Converts the strings in the specified list to lowercase, ignoring their casing, based on their Unicode values. - /// - /// The list of strings to convert to lowercase. public static void ToLower(this IList strs) { if (strs is not null && strs.Count > 0) @@ -344,18 +158,8 @@ public static void ToLower(this IList strs) } } - /// - /// Converts the string to lowercase using the invariant culture, if it is not empty or whitespace; otherwise, returns the original string. - /// - /// The string to convert to lowercase. - /// The lowercase version of the string using the invariant culture if it is not empty or whitespace; otherwise, the original string. public static string ToLowerInvariant(this string str) => str.IsNotNullAndWhiteSpace() ? str.ToLower(CultureInfo.InvariantCulture) : str; - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings converted to lowercase, ignoring their casing, based on their Unicode values using the invariant culture. - /// - /// The strings to convert to lowercase. - /// An enumerable of strings converted to lowercase, ignoring their casing, based on their Unicode values using the invariant culture. public static IEnumerable ToLowerInvariant(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -368,10 +172,6 @@ public static IEnumerable ToLowerInvariant(this IEnumerable strs } } - /// - /// Converts all strings in the specified string list to lowercase using the invariant culture, by modifying the list in-place. - /// - /// The string list to convert to lowercase. public static void ToLowerInvariant(this IList strs) { if (strs is not null && strs.Count > 0) @@ -383,18 +183,8 @@ public static void ToLowerInvariant(this IList strs) } } - /// - /// Converts the string to uppercase using the invariant culture, if it is not empty or whitespace; otherwise, returns the original string. - /// - /// The string to convert to uppercase. - /// The uppercase version of the string using the invariant culture if it is not empty or whitespace; otherwise, the original string. public static string ToUpper(this string str) => str.IsNotNullAndWhiteSpace() ? str.ToUpper() : str; - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings converted to uppercase, ignoring their casing, using the invariant culture. - /// - /// The strings to convert to uppercase. - /// An enumerable of strings converted to uppercase, ignoring their casing, using the invariant culture. public static IEnumerable ToUpper(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -407,10 +197,6 @@ public static IEnumerable ToUpper(this IEnumerable strs) } } - /// - /// Converts all strings in the specified list of strings to uppercase, by modifying the list in-place. - /// - /// The list of strings to convert to uppercase. public static void ToUpper(this IList strs) { if (strs is not null && strs.Count > 0) @@ -422,18 +208,8 @@ public static void ToUpper(this IList strs) } } - /// - /// Converts the input string to uppercase using the invariant culture, if it is not empty or whitespace; otherwise, returns the original string. - /// - /// The string to convert to uppercase. - /// The uppercase version of the input string using the invariant culture if it is not empty or whitespace; otherwise, the original string. public static string ToUpperInvariant(this string str) => str.IsNotNullAndWhiteSpace() ? str.ToUpper(CultureInfo.InvariantCulture) : str; - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings converted to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. - /// - /// The strings to convert to uppercase. - /// An enumerable of strings converted to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. public static IEnumerable ToUpperInvariant(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -446,10 +222,6 @@ public static IEnumerable ToUpperInvariant(this IEnumerable strs } } - /// - /// Converts all strings in the specified string list to uppercase using the invariant culture, by modifying the list in-place. - /// - /// The string list to convert to uppercase. public static void ToUpperInvariant(this IList strs) { if (strs is not null && strs.Count > 0) diff --git a/lib/YANLib/YANText.cs b/lib/YANLib/YANText.cs index a79021b7..cc36189d 100644 --- a/lib/YANLib/YANText.cs +++ b/lib/YANLib/YANText.cs @@ -1,22 +1,13 @@ -using System.Globalization; -using System.Text; +using System.Text; +using static System.Globalization.CultureInfo; namespace YANLib; public static partial class YANText { - /// - /// Converts the string to title case using the current culture's text info, if it is not empty or whitespace; otherwise, returns the original string. - /// - /// The string to convert to title case. - /// The title case version of the string using the current culture's text info if it is not empty or whitespace; otherwise, the original string. - public static string ToTitle(this string str) => str.IsNullOrWhiteSpace() ? str : CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str); - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings converted to title case using the current culture's text info. - /// - /// The strings to convert to title case. - /// An enumerable of strings converted to title case using the current culture's text info. + public static string ToTitle(this string str) => str.IsNullOrWhiteSpace() ? str : CurrentCulture.TextInfo.ToTitleCase(str); + public static IEnumerable ToTitle(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -29,10 +20,6 @@ public static IEnumerable ToTitle(this IEnumerable strs) } } - /// - /// Converts all strings in the specified list to title case using the current culture's text info, by modifying the list in-place. - /// - /// The list of strings to convert to title case. public static void ToTitle(this IList strs) { if (strs is not null && strs.Count > 0) @@ -44,11 +31,6 @@ public static void ToTitle(this IList strs) } } - /// - /// Converts the first character of each word in the input string to uppercase, and the remaining characters to lowercase, using the current culture's text info. - /// - /// The string to capitalize. - /// The capitalized version of the input string. public static string ToCapitalize(this string str) { if (str.IsNullOrWhiteSpace()) @@ -72,11 +54,6 @@ public static string ToCapitalize(this string str) return sb.ToString(); } - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings with the first character of each word capitalized and the remaining characters in lowercase, based on the current culture's text info. - /// - /// The strings to capitalize. - /// An enumerable of strings with the first character of each word capitalized and the remaining characters in lowercase, based on the current culture's text info. public static IEnumerable ToCapitalize(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -89,11 +66,6 @@ public static IEnumerable ToCapitalize(this IEnumerable strs) } } - /// - /// Converts all strings in the specified string list to capitalize form, by modifying the list in-place. - /// The first character of each word is capitalized and the remaining characters are converted to lowercase, based on the current culture's text info. - /// - /// The string list to convert to capitalize form. public static void ToCapitalize(this IList strs) { if (strs is not null && strs.Count > 0) @@ -105,13 +77,6 @@ public static void ToCapitalize(this IList strs) } } - /// - /// Removes excess whitespace characters from the beginning, end, and within the specified string. - /// Consecutive whitespace characters are reduced to a single space character. - /// If the input string is null or empty, it is returned unchanged. - /// - /// The string to clean up. - /// A string with excess whitespace characters removed and consecutive whitespace characters reduced to a single space character. public static string CleanSpace(this string str) { if (str.IsNullOrEmpty()) @@ -140,12 +105,6 @@ public static string CleanSpace(this string str) return sb.ToString(); } - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings with excess whitespace characters removed from the beginning, end, and within each string. - /// Consecutive whitespace characters are reduced to a single space character. - /// - /// The strings to clean up. - /// An enumerable of strings with excess whitespace characters removed. public static IEnumerable CleanSpace(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -158,11 +117,6 @@ public static IEnumerable CleanSpace(this IEnumerable strs) } } - /// - /// Removes excess whitespace characters from the beginning, end, and within each string in the specified list of strings, by modifying the list in-place. - /// Consecutive whitespace characters are reduced to a single space character. - /// - /// The list of strings to clean up. public static void CleanSpace(this IList strs) { if (strs is not null && strs.Count > 0) @@ -174,12 +128,6 @@ public static void CleanSpace(this IList strs) } } - /// - /// Formats the input string as a name by capitalizing the first letter of each word and converting the rest to lowercase, while ignoring punctuation, numbers, and consecutive whitespace characters. - /// If the input string is empty or consists of only whitespace, it is returned unchanged. - /// - /// The string to format as a name. - /// The formatted name string. public static string FormatName(this string str) { if (str.IsNullOrEmpty()) @@ -201,11 +149,6 @@ public static string FormatName(this string str) return sb.ToString(); } - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings with each string formatted by filtering out non-alphabetic characters and converting the remaining characters to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. - /// - /// The strings to format by filtering out non-alphabetic characters and converting the remaining characters to uppercase. - /// An enumerable of strings with each string formatted by filtering out non-alphabetic characters and converting the remaining characters to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. public static IEnumerable FormatName(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -218,10 +161,6 @@ public static IEnumerable FormatName(this IEnumerable strs) } } - /// - /// Formats a list of strings in place by filtering out non-alphabetic characters and converting the remaining characters to uppercase, ignoring their casing, based on their Unicode values using the invariant culture. - /// - /// The list of strings to format by filtering out non-alphabetic characters and converting the remaining characters to uppercase. public static void FormatName(this IList strs) { if (strs is not null && strs.Count > 0) @@ -233,12 +172,6 @@ public static void FormatName(this IList strs) } } - /// - /// Filters out non-alphabetic characters from a string by creating a new string containing only the alphabetic characters, and returns the result. - /// Empty or null strings are returned as is. - /// - /// The string to filter out non-alphabetic characters from. - /// A new string containing only the alphabetic characters from the input string, or the original string if it is empty or null. public static string FilterAlphabetic(this string str) { if (str.IsNullOrEmpty()) @@ -257,12 +190,6 @@ public static string FilterAlphabetic(this string str) return sb.ToString(); } - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings with all non-alphabetic characters filtered out, based on their Unicode values. - /// Empty or null strings are returned as is. - /// - /// The strings to filter out non-alphabetic characters from. - /// An enumerable of strings with all non-alphabetic characters filtered out, based on their Unicode values. public static IEnumerable FilterAlphabetic(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -275,10 +202,6 @@ public static IEnumerable FilterAlphabetic(this IEnumerable strs } } - /// - /// Filters out all non-alphabetic characters from the strings in the specified list based on their Unicode values. - /// - /// The list of strings to filter out non-alphabetic characters from. public static void FilterAlphabetic(this IList strs) { if (strs is not null && strs.Count > 0) @@ -290,11 +213,6 @@ public static void FilterAlphabetic(this IList strs) } } - /// - /// Filters out all numeric characters from the string and returns a new string containing only non-numeric characters. - /// - /// The string to filter out numeric characters from. - /// A new string containing only non-numeric characters from the original string. public static string FilterNumber(this string str) { if (str.IsNullOrEmpty()) @@ -313,12 +231,6 @@ public static string FilterNumber(this string str) return sb.ToString(); } - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings with all numeric characters filtered out, based on their Unicode values. - /// If a string is empty or whitespace, it is returned as-is. - /// - /// The strings to filter out numeric characters from. - /// An enumerable of strings with all numeric characters filtered out, based on their Unicode values. public static IEnumerable FilterNumber(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -331,11 +243,6 @@ public static IEnumerable FilterNumber(this IEnumerable strs) } } - /// - /// Filters out all numeric characters from the strings in the specified list, based on their Unicode values. - /// If a string in the list is empty or whitespace, it is left unchanged. - /// - /// The list of strings to filter out numeric characters from. public static void FilterNumber(this IList strs) { if (strs is not null && strs.Count > 0) @@ -347,11 +254,6 @@ public static void FilterNumber(this IList strs) } } - /// - /// Filters out all non-alphanumeric characters (i.e., characters that are not numbers or letters) from the string, and returns the filtered string. - /// - /// The string to filter out non-alphanumeric characters from. - /// The filtered string with only alphanumeric characters. public static string FilterAlphanumeric(this string str) { if (str.IsNullOrEmpty()) @@ -370,11 +272,6 @@ public static string FilterAlphanumeric(this string str) return sb.ToString(); } - /// - /// Enumerates through an enumerable of strings and returns a new enumerable of strings with all non-alphanumeric characters (i.e., characters that are not numbers or letters) filtered out. - /// - /// The strings to filter out non-alphanumeric characters from. - /// An enumerable of strings with all non-alphanumeric characters filtered out. public static IEnumerable FilterAlphanumeric(this IEnumerable strs) { if (strs is null || !strs.Any()) @@ -387,10 +284,6 @@ public static IEnumerable FilterAlphanumeric(this IEnumerable st } } - /// - /// Modifies the strings in the specified list by filtering out all non-alphanumeric characters (i.e., characters that are not numbers or letters). - /// - /// The list of strings to filter out non-alphanumeric characters from. public static void FilterAlphanumeric(this IList strs) { if (strs is not null && strs.Count > 0)