From 99238a295a1f858776abe92483cec1c7c3e18524 Mon Sep 17 00:00:00 2001 From: Yami An Date: Wed, 12 Apr 2023 18:23:09 +0700 Subject: [PATCH] 230412 --- lib/YANLib/YANBool.cs | 9 + lib/YANLib/YANDateTime.Nullable.cs | 1339 ++++++++ lib/YANLib/YANDateTime.cs | 640 ++++ lib/YANLib/YANEnumerable.cs | 92 +- lib/YANLib/YANJson.cs | 337 +- lib/YANLib/YANModel.Property.cs | 2902 +++++++++++++++++ lib/YANLib/YANModel.cs | 967 +++--- lib/YANLib/YANTask.cs | 124 +- lib/YANLib/YANText.cs | 2 +- .../Dtos/{JsonDto.cs => JsonTestDto.cs} | 2 +- .../Services/IYANJsonService.cs | 6 +- .../Services/YANJsonService.cs | 22 +- .../Controllers/YANJsonController.cs | 13 +- 13 files changed, 5577 insertions(+), 878 deletions(-) create mode 100644 lib/YANLib/YANModel.Property.cs rename src/YANLib.Application.Contracts/Dtos/{JsonDto.cs => JsonTestDto.cs} (88%) diff --git a/lib/YANLib/YANBool.cs b/lib/YANLib/YANBool.cs index 8ff24c5a..75669352 100644 --- a/lib/YANLib/YANBool.cs +++ b/lib/YANLib/YANBool.cs @@ -5,4 +5,13 @@ namespace YANLib; public static partial class YANBool { public static bool GenerateRandomBool() => GenerateRandomByte(0, 2) == 1; + + public static IEnumerable GenerateRandomBools(T size) where T : struct + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomBool(); + } + } } diff --git a/lib/YANLib/YANDateTime.Nullable.cs b/lib/YANLib/YANDateTime.Nullable.cs index 6cebe1f9..9a29f0fa 100644 --- a/lib/YANLib/YANDateTime.Nullable.cs +++ b/lib/YANLib/YANDateTime.Nullable.cs @@ -14,6 +14,96 @@ public static partial class YANDateTime /// 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 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(string fmt, DateTime? dfltVal, params string[] strs) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Length; i++) + { + yield return strs[i].ToDateTime(fmt, dfltVal); + } + } + + /// + /// 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, string fmt, DateTime? dfltVal) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt, dfltVal); + } + } + + /// + /// 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(IReadOnlyCollection strs, string fmt, DateTime? dfltVal) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt, dfltVal); + } + } + + /// + /// 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(IReadOnlyList strs, string fmt, DateTime? dfltVal) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Count; i++) + { + yield return strs[i].ToDateTime(fmt, dfltVal); + } + } + + /// + /// 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(IReadOnlySet strs, string fmt, DateTime? dfltVal) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt, dfltVal); + } + } + /// /// Generates a random value between and . /// If is greater than , is returned. @@ -23,6 +113,25 @@ public static partial class YANDateTime /// 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 + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomDateTime(min, max); + } + } + /// /// Generates a random value between and . /// If is greater than , is returned. @@ -32,6 +141,25 @@ public static partial class YANDateTime /// 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 + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomDateTime(min, max); + } + } + /// /// Generates a random value between and . /// If is greater than , is returned. @@ -41,6 +169,25 @@ public static partial class YANDateTime /// 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 + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomDateTime(min, max); + } + } + /// /// Generates a random value between and . /// @@ -48,6 +195,24 @@ public static partial class YANDateTime /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default; + /// + /// Generates an containing random DateTime values between and . + /// The maximum DateTime value to generate is determined by the value of . + /// The number of DateTime values generated is determined by the value of . + /// + /// The type of . Must be a value type. + /// The maximum DateTime value to generate. + /// The number of DateTime values to generate. + /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime? max, T size) where T : struct + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomDateTime(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. /// @@ -55,6 +220,101 @@ public static partial class YANDateTime /// The week of the year that the specified value falls in. public static int GetWeekOfYear(this DateTime? dt) => dt.HasValue ? dt.Value.GetWeekOfYear() : default; + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(params DateTime?[] dts) + { + if (dts is null || dts.Length > 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IEnumerable dts) + { + if (dts is null || !dts.Any()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IReadOnlyCollection dts) + { + if (dts is null || dts.Count > 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IReadOnlyList dts) + { + if (dts is null || dts.Count > 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IReadOnlySet dts) + { + if (dts is null || dts.Count > 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.GetWeekOfYear(); + } + } + /// /// Returns the total number of months between the two specified values, ignoring the day of the month. /// @@ -90,6 +350,121 @@ public static partial class YANDateTime /// 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(T1 tzSrc, T2 tzDst, params DateTime?[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, tzDst); + } + } + /// /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. /// @@ -101,6 +476,121 @@ public static partial class YANDateTime /// 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(T1? tzSrc, T2 tzDst, params DateTime[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, tzDst); + } + } + /// /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. /// @@ -112,6 +602,110 @@ public static partial class YANDateTime /// 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; + public static IEnumerable ChangeTimeZone(T1 tzSrc, T2? tzDst, params DateTime[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, tzDst); + } + } + /// /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. /// @@ -123,6 +717,121 @@ public static partial class YANDateTime /// 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(T1? tzSrc, T2 tzDst, params DateTime?[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, tzDst); + } + } + /// /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. /// @@ -134,6 +843,121 @@ public static partial class YANDateTime /// 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(T1 tzSrc, T2? tzDst, params DateTime?[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, tzDst); + } + } + /// /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. /// @@ -145,6 +969,121 @@ public static partial class YANDateTime /// 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(T1? tzSrc, T2? tzDst, params DateTime[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, tzDst); + } + } + /// /// Returns a new value representing the same point in time as the original value, but converted to a different time zone. /// @@ -156,6 +1095,121 @@ public static partial class YANDateTime /// 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(T1? tzSrc, T2? tzDst, params DateTime?[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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. /// @@ -165,6 +1219,101 @@ public static partial class YANDateTime /// 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(T tzDst, params DateTime?[] dts) where T : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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 IReadOnlyCollection dts, T tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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 IReadOnlyList dts, T tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(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 IReadOnlySet dts, T tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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. /// @@ -174,6 +1323,101 @@ public static partial class YANDateTime /// 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(T? tzDst, params DateTime[] dts) where T : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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 IReadOnlyCollection dts, T? tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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 IReadOnlyList dts, T? tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(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 IReadOnlySet dts, T? tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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. /// @@ -182,4 +1426,99 @@ public static partial class YANDateTime /// 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(T? tzDst, params DateTime?[] dts) where T : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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 IReadOnlyCollection dts, T? tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(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 IReadOnlyList dts, T? tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(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 IReadOnlySet dts, T? tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzDst); + } + } } diff --git a/lib/YANLib/YANDateTime.cs b/lib/YANLib/YANDateTime.cs index 31620dab..335b5b8d 100644 --- a/lib/YANLib/YANDateTime.cs +++ b/lib/YANLib/YANDateTime.cs @@ -17,6 +17,96 @@ public static partial class YANDateTime /// 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(params string[] strs) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Length; i++) + { + yield return strs[i].ToDateTime(); + } + } + + /// + /// 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) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(); + } + } + + /// + /// 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(IReadOnlyCollection strs) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(); + } + } + + /// + /// 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(IReadOnlyList strs) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Count; i++) + { + yield return strs[i].ToDateTime(); + } + } + + /// + /// 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(IReadOnlySet strs) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(); + } + } + /// /// Parses the string representation of a date and time using . /// Returns the parsed value, or if the parsing fails. @@ -26,6 +116,101 @@ public static partial class YANDateTime /// 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 format of the date/time values in the input strings. + /// The enumerable of strings to convert to DateTime values. + /// An containing the parsed DateTime values. + public static IEnumerable ToDateTime(string fmt, params string[] strs) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Length; i++) + { + yield return strs[i].ToDateTime(fmt); + } + } + + /// + /// 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 format of the date/time values in the input strings. + /// The enumerable of strings to convert to DateTime values. + /// An containing the parsed DateTime values. + public static IEnumerable ToDateTime(IEnumerable strs, string fmt) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt); + } + } + + /// + /// 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 format of the date/time values in the input strings. + /// The enumerable of strings to convert to DateTime values. + /// An containing the parsed DateTime values. + public static IEnumerable ToDateTime(IReadOnlyCollection strs, string fmt) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt); + } + } + + /// + /// 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 format of the date/time values in the input strings. + /// The enumerable of strings to convert to DateTime values. + /// An containing the parsed DateTime values. + public static IEnumerable ToDateTime(IReadOnlyList strs, string fmt) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Count; i++) + { + yield return strs[i].ToDateTime(fmt); + } + } + + /// + /// 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 format of the date/time values in the input strings. + /// The enumerable of strings to convert to DateTime values. + /// An containing the parsed DateTime values. + public static IEnumerable ToDateTime(IReadOnlySet strs, string fmt) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt); + } + } + /// /// Parses the string representation of a date and time using . /// Returns the parsed value, or if the parsing fails. @@ -36,6 +221,102 @@ public static partial class YANDateTime /// 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; + public static IEnumerable ToDateTime(string fmt, DateTime dfltVal, params string[] strs) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Length; i++) + { + yield return strs[i].ToDateTime(fmt, 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 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) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt, 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 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(IReadOnlyCollection strs, string fmt, DateTime dfltVal) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt, 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 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(IReadOnlyList strs, string fmt, DateTime dfltVal) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + for (var i = 0; i < strs.Count; i++) + { + yield return strs[i].ToDateTime(fmt, 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 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(IReadOnlySet strs, string fmt, DateTime dfltVal) + { + if (strs.IsNullOrWhiteSpace()) + { + yield break; + } + foreach (var str in strs) + { + yield return str.ToDateTime(fmt, dfltVal); + } + } + /// /// Generates a random value between and . /// If is greater than , is returned. @@ -45,12 +326,47 @@ public static partial class YANDateTime /// 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 + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomDateTime(min, max); + } + } + /// /// Generates a random value between and . /// /// A random value between and . public static DateTime GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue); + /// + /// Generates an containing random DateTime values between and . + /// The number of DateTime values generated is determined by the value of . + /// + /// The type of . Must be a value type. + /// The number of DateTime values to generate. + /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(T size) where T : struct + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomDateTime(); + } + } + /// /// Generates a random value between and . /// @@ -58,6 +374,24 @@ public static partial class YANDateTime /// A random value between and . public static DateTime GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max); + /// + /// Generates an containing random DateTime values between and . + /// The maximum DateTime value to generate is determined by the value of . + /// The number of DateTime values generated is determined by the value of . + /// + /// The type of . Must be a value type. + /// The maximum DateTime value to generate. + /// The number of DateTime values to generate. + /// An containing random DateTime values between and . + public static IEnumerable GenerateRandomDateTimes(DateTime max, T size) where T : struct + { + var cnt = size.ToUlong(); + for (var i = 0ul; i < cnt; i++) + { + yield return GenerateRandomDateTime(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. /// @@ -65,6 +399,101 @@ public static partial class YANDateTime /// 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); + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(params DateTime[] dts) + { + if (dts is null || dts.Length > 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IEnumerable dts) + { + if (dts is null || !dts.Any()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IReadOnlyCollection dts) + { + if (dts is null || dts.Count > 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IReadOnlyList dts) + { + if (dts is null || dts.Count > 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].GetWeekOfYear(); + } + } + + /// + /// Returns an containing the week of the year for each specified value. + /// The week of the year is calculated according to the ISO-8601 standard, where the first week of the year is the week that contains the first Thursday of the year. + /// If any of the input values is , no value will be returned for that input. + /// + /// The values to get the week of the year for. + /// An containing the week of the year for each specified value. + public static IEnumerable GetWeekOfYear(this IReadOnlySet dts) + { + if (dts is null || dts.Count > 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.GetWeekOfYear(); + } + } + /// /// Returns the total number of months between the two specified values, ignoring the day of the month. /// @@ -93,6 +522,121 @@ public static DateTime ChangeTimeZone(this DateTime dt, T1 tzSrc, T2 tzD }; } + /// + /// 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(T1 tzSrc, T2 tzDst, params DateTime[] dts) where T1 : struct where T2 : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyCollection dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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 IReadOnlyList dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzSrc, 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 IReadOnlySet dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzSrc, 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. /// @@ -101,4 +645,100 @@ public static DateTime ChangeTimeZone(this DateTime dt, T1 tzSrc, T2 tzD /// 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); + + public static IEnumerable ChangeTimeZone(T tzDst, params DateTime[] dts) where T : struct + { + if (dts is null || dts.Length <= 0) + { + yield break; + } + for (var i = 0; i < dts.Length; i++) + { + yield return dts[i].ChangeTimeZone(tzDst); + } + } + + /// + /// Returns an containing the values converted to a different time zone, based on the destination time zone specified. + /// The destination time zone is specified as a generic type parameter , 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 destination 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, T tzDst) where T : struct + { + if (dts is null || !dts.Any()) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzDst); + } + } + + /// + /// Returns an containing the values converted to a different time zone, based on the destination time zone specified. + /// The destination time zone is specified as a generic type parameter , 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 destination 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 IReadOnlyCollection dts, T tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzDst); + } + } + + /// + /// Returns an containing the values converted to a different time zone, based on the destination time zone specified. + /// The destination time zone is specified as a generic type parameter , 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 destination 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 IReadOnlyList dts, T tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + for (var i = 0; i < dts.Count; i++) + { + yield return dts[i].ChangeTimeZone(tzDst); + } + } + + /// + /// Returns an containing the values converted to a different time zone, based on the destination time zone specified. + /// The destination time zone is specified as a generic type parameter , 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 destination 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 IReadOnlySet dts, T tzDst) where T : struct + { + if (dts is null || dts.Count <= 0) + { + yield break; + } + foreach (var dt in dts) + { + yield return dt.ChangeTimeZone(tzDst); + } + } } diff --git a/lib/YANLib/YANEnumerable.cs b/lib/YANLib/YANEnumerable.cs index 5a547f3d..e6f94a46 100644 --- a/lib/YANLib/YANEnumerable.cs +++ b/lib/YANLib/YANEnumerable.cs @@ -29,11 +29,13 @@ public static IEnumerable> ChunkBySize(this List srcs, T1 chun } /// - /// Returns a new containing only the non-null values from the given array . + /// 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 elements in the array. - /// The array to be cleaned. - /// An containing only the non-null values from . + /// The type of the objects to clean. + /// The objects to clean. + /// An containing the non-null values. public static IEnumerable Clean(params T[] srcs) { if (srcs is null || srcs.Length <= 0) @@ -63,11 +65,13 @@ public static IEnumerable Clean(params T[] srcs) } /// - /// Returns a new containing only the non-null values from the given . + /// 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 elements in the . - /// The to be cleaned. - /// An containing only the non-null values from . + /// 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()) @@ -95,12 +99,14 @@ public static IEnumerable Clean(this IEnumerable srcs) } /// - /// Returns a new containing only the non-null values from the given . + /// 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 elements in the . - /// The to be cleaned. - /// An containing only the non-null values from . - public static IEnumerable Clean(this ICollection srcs) + /// The type of the objects to clean. + /// The objects to clean. + /// An containing the non-null values. + public static IEnumerable Clean(this IReadOnlyCollection srcs) { if (srcs is null || srcs.Count <= 0) { @@ -127,12 +133,14 @@ public static IEnumerable Clean(this ICollection srcs) } /// - /// Returns a new containing only the non-null values from the given . + /// 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 elements in the . - /// The to be cleaned. - /// An containing only the non-null values from . - public static IEnumerable Clean(this IList srcs) + /// The type of the objects to clean. + /// The objects to clean. + /// An containing the non-null values. + public static IEnumerable Clean(this IReadOnlyList srcs) { if (srcs is null || srcs.Count <= 0) { @@ -161,12 +169,14 @@ public static IEnumerable Clean(this IList srcs) } /// - /// Returns a new containing only the non-null values from the given . + /// 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 elements in the . - /// The to be cleaned. - /// An containing only the non-null values from . - public static IEnumerable Clean(this ISet srcs) + /// The type of the objects to clean. + /// The objects to clean. + /// An containing the non-null values. + public static IEnumerable Clean(this IReadOnlySet srcs) { if (srcs is null || srcs.Count <= 0) { @@ -193,10 +203,10 @@ public static IEnumerable Clean(this ISet srcs) } /// - /// Returns a new containing only the non-empty values from the given array of strings. + /// Removes values and empty strings from the specified enumerable of strings, and returns an containing the non-null and non-empty strings. /// - /// The array of strings to be cleaned. - /// An containing only the non-empty values from . + /// The enumerable of strings to clean. + /// An containing the non-null and non-empty strings. public static IEnumerable Clean(params string[] srcs) { if (srcs is null || srcs.Length <= 0) @@ -215,10 +225,10 @@ public static IEnumerable Clean(params string[] srcs) } /// - /// Returns a new containing only the non-empty values from the given of strings. + /// Removes values and empty strings from the specified enumerable of strings, and returns an containing the non-null and non-empty strings. /// - /// The of strings to be cleaned. - /// An containing only the non-empty values from . + /// 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()) @@ -235,11 +245,11 @@ public static IEnumerable Clean(this IEnumerable srcs) } /// - /// Returns a new containing only the non-empty values from the given of strings. + /// Removes values and empty strings from the specified enumerable of strings, and returns an containing the non-null and non-empty strings. /// - /// The of strings to be cleaned. - /// An containing only the non-empty values from . - public static IEnumerable Clean(this ICollection srcs) + /// The enumerable of strings to clean. + /// An containing the non-null and non-empty strings. + public static IEnumerable Clean(this IReadOnlyCollection srcs) { if (srcs is null || srcs.Count <= 0) { @@ -255,11 +265,11 @@ public static IEnumerable Clean(this ICollection srcs) } /// - /// Returns a new containing only the non-empty values from the given of strings. + /// Removes values and empty strings from the specified enumerable of strings, and returns an containing the non-null and non-empty strings. /// - /// The of strings to be cleaned. - /// An containing only the non-empty values from . - public static IEnumerable Clean(this IList srcs) + /// The enumerable of strings to clean. + /// An containing the non-null and non-empty strings. + public static IEnumerable Clean(this IReadOnlyList srcs) { if (srcs is null || srcs.Count <= 0) { @@ -277,11 +287,11 @@ public static IEnumerable Clean(this IList srcs) } /// - /// Returns a new containing only the non-empty values from the given of strings. + /// Removes values and empty strings from the specified enumerable of strings, and returns an containing the non-null and non-empty strings. /// - /// The of strings to be cleaned. - /// An containing only the non-empty values from . - public static IEnumerable Clean(this ISet srcs) + /// The enumerable of strings to clean. + /// An containing the non-null and non-empty strings. + public static IEnumerable Clean(this IReadOnlySet srcs) { if (srcs is null || srcs.Count <= 0) { diff --git a/lib/YANLib/YANJson.cs b/lib/YANLib/YANJson.cs index fd13d9c6..fcf6692e 100644 --- a/lib/YANLib/YANJson.cs +++ b/lib/YANLib/YANJson.cs @@ -7,78 +7,63 @@ public static partial class YANJson { public static string Serialize(this T mdl) where T : class => JsonSerializer.Serialize(mdl); - public static IEnumerable Serialize(this IEnumerable mdls) where T : class + public static IEnumerable Serialize(params T[] mdls) where T : class { - if (mdls is not null && mdls.Any()) + if (mdls is null || mdls.Length <= 0) { - foreach (var mdl in mdls) - { - yield return JsonSerializer.Serialize(mdl); - } + yield break; } - else + for (var i = 0; i < mdls.Length; i++) { - yield break; + yield return JsonSerializer.Serialize(mdls[i]); } } - public static IEnumerable Serialize(this IReadOnlyCollection mdls) where T : class + public static IEnumerable Serialize(this IEnumerable mdls) where T : class { - if (mdls is not null && mdls.Count > 0) + if (mdls is null || !mdls.Any()) { - foreach (var mdl in mdls) - { - yield return JsonSerializer.Serialize(mdl); - } + yield break; } - else + foreach (var mdl in mdls) { - yield break; + yield return JsonSerializer.Serialize(mdl); } } - public static IEnumerable Serialize(this IReadOnlyList mdls) where T : class + public static IEnumerable Serialize(this IReadOnlyCollection mdls) where T : class { - if (mdls is not null && mdls.Count > 0) + if (mdls is null || mdls.Count <= 0) { - for (var i = 0; i < mdls.Count; i++) - { - yield return JsonSerializer.Serialize(mdls[i]); - } + yield break; } - else + foreach (var mdl in mdls) { - yield break; + yield return JsonSerializer.Serialize(mdl); } } - public static IEnumerable Serialize(this IReadOnlySet mdls) where T : class + public static IEnumerable Serialize(this IReadOnlyList mdls) where T : class { - if (mdls is not null && mdls.Count > 0) + if (mdls is null || mdls.Count <= 0) { - foreach (var mdl in mdls) - { - yield return JsonSerializer.Serialize(mdl); - } + yield break; } - else + for (var i = 0; i < mdls.Count; i++) { - yield break; + yield return JsonSerializer.Serialize(mdls[i]); } } - public static IEnumerable Serialize(params T[] mdls) where T : class + public static IEnumerable Serialize(this IReadOnlySet mdls) where T : class { - if (mdls is not null && mdls.Length > 0) + if (mdls is null || mdls.Count <= 0) { - for (var i = 0; i < mdls.Length; i++) - { - yield return JsonSerializer.Serialize(mdls[i]); - } + yield break; } - else + foreach (var mdl in mdls) { - yield break; + yield return JsonSerializer.Serialize(mdl); } } @@ -88,78 +73,63 @@ public static IEnumerable Serialize(params T[] mdls) where T : class PropertyNameCaseInsensitive = false }); - public static IEnumerable SerializeCamel(this IEnumerable mdls) where T : class + public static IEnumerable SerializeCamel(params T[] mdls) where T : class { - if (mdls is not null && mdls.Any()) + if (mdls is null || mdls.Length <= 0) { - foreach (var mdl in mdls) - { - yield return mdl.SerializeCamel(); - } + yield break; } - else + for (var i = 0; i < mdls.Length; i++) { - yield break; + yield return mdls[i].SerializeCamel(); } } - public static IEnumerable SerializeCamel(this IReadOnlyCollection mdls) where T : class + public static IEnumerable SerializeCamel(this IEnumerable mdls) where T : class { - if (mdls is not null && mdls.Count > 0) + if (mdls is null || !mdls.Any()) { - foreach (var mdl in mdls) - { - yield return mdl.SerializeCamel(); - } + yield break; } - else + foreach (var mdl in mdls) { - yield break; + yield return mdl.SerializeCamel(); } } - public static IEnumerable SerializeCamel(this IReadOnlyList mdls) where T : class + public static IEnumerable SerializeCamel(this IReadOnlyCollection mdls) where T : class { - if (mdls is not null && mdls.Count > 0) + if (mdls is null || mdls.Count <= 0) { - for (var i = 0; i < mdls.Count; i++) - { - yield return mdls[i].SerializeCamel(); - } + yield break; } - else + foreach (var mdl in mdls) { - yield break; + yield return mdl.SerializeCamel(); } } - public static IEnumerable SerializeCamel(this IReadOnlySet mdls) where T : class + public static IEnumerable SerializeCamel(this IReadOnlyList mdls) where T : class { - if (mdls is not null && mdls.Count > 0) + if (mdls is null || mdls.Count <= 0) { - foreach (var mdl in mdls) - { - yield return mdl.SerializeCamel(); - } + yield break; } - else + for (var i = 0; i < mdls.Count; i++) { - yield break; + yield return mdls[i].SerializeCamel(); } } - public static IEnumerable SerializeCamel(params T[] mdls) where T : class + public static IEnumerable SerializeCamel(this IReadOnlySet mdls) where T : class { - if (mdls is not null && mdls.Length > 0) + if (mdls is null || mdls.Count <= 0) { - for (var i = 0; i < mdls.Length; i++) - { - yield return mdls[i].SerializeCamel(); - } + yield break; } - else + foreach (var mdl in mdls) { - yield break; + yield return mdl.SerializeCamel(); } } @@ -175,78 +145,63 @@ public static IEnumerable SerializeCamel(params T[] mdls) where T : c } } - public static IEnumerable Deserialize(this IEnumerable strs) where T : class + public static IEnumerable Deserialize(params string[] strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Length <= 0) { - foreach (var str in strs) - { - yield return str.Deserialize(); - } + yield break; } - else + for (var i = 0; i < strs.Length; i++) { - yield break; + yield return strs[i].Deserialize(); } } - public static IEnumerable Deserialize(this IReadOnlyCollection strs) where T : class + public static IEnumerable Deserialize(this IEnumerable strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || !strs.Any()) { - foreach (var str in strs) - { - yield return str.Deserialize(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.Deserialize(); } } - public static IEnumerable Deserialize(this IReadOnlyList strs) where T : class + public static IEnumerable Deserialize(this IReadOnlyCollection strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.Deserialize(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.Deserialize(); } } - public static IEnumerable Deserialize(this IReadOnlySet strs) where T : class + public static IEnumerable Deserialize(this IReadOnlyList strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.Deserialize(); - } + yield break; } - else + for (var i = 0; i < strs.Count; i++) { - yield break; + yield return strs[i].Deserialize(); } } - public static IEnumerable Deserialize(params string[] strs) where T : class + public static IEnumerable Deserialize(this IReadOnlySet strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.Deserialize(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.Deserialize(); } } @@ -266,78 +221,63 @@ public static IEnumerable SerializeCamel(params T[] mdls) where T : c } } - public static IEnumerable DeserializeCamel(this IEnumerable strs) where T : class + public static IEnumerable DeserializeCamel(params string[] strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Length <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeCamel(); - } + yield break; } - else + for (var i = 0; i < strs.Length; i++) { - yield break; + yield return strs[i].DeserializeCamel(); } } - public static IEnumerable DeserializeCamel(this IReadOnlyCollection strs) where T : class + public static IEnumerable DeserializeCamel(this IEnumerable strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || !strs.Any()) { - foreach (var str in strs) - { - yield return str.DeserializeCamel(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.DeserializeCamel(); } } - public static IEnumerable DeserializeCamel(this IReadOnlyList strs) where T : class + public static IEnumerable DeserializeCamel(this IReadOnlyCollection strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeCamel(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.DeserializeCamel(); } } - public static IEnumerable DeserializeCamel(this IReadOnlySet strs) where T : class + public static IEnumerable DeserializeCamel(this IReadOnlyList strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeCamel(); - } + yield break; } - else + for (var i = 0; i < strs.Count; i++) { - yield break; + yield return strs[i].DeserializeCamel(); } } - public static IEnumerable DeserializeCamel(params string[] strs) where T : class + public static IEnumerable DeserializeCamel(this IReadOnlySet strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeCamel(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.DeserializeCamel(); } } @@ -346,7 +286,11 @@ public static IEnumerable SerializeCamel(params T[] mdls) where T : c T? rslt; try { - rslt = JsonSerializer.Deserialize(str); + rslt = JsonSerializer.Deserialize(str, new JsonSerializerOptions + { + PropertyNamingPolicy = CamelCase, + PropertyNameCaseInsensitive = false + }); } catch { @@ -356,11 +300,7 @@ public static IEnumerable SerializeCamel(params T[] mdls) where T : c { try { - rslt = JsonSerializer.Deserialize(str, new JsonSerializerOptions - { - PropertyNamingPolicy = CamelCase, - PropertyNameCaseInsensitive = false - }); + rslt = JsonSerializer.Deserialize(str); } catch { @@ -370,78 +310,63 @@ public static IEnumerable SerializeCamel(params T[] mdls) where T : c return rslt; } - public static IEnumerable DeserializeStandard(this IEnumerable strs) where T : class + public static IEnumerable DeserializeStandard(params string[] strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Length <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeStandard(); - } + yield break; } - else + for (var i = 0; i < strs.Length; i++) { - yield break; + yield return strs[i].DeserializeStandard(); } } - public static IEnumerable DeserializeStandard(this IReadOnlyCollection strs) where T : class + public static IEnumerable DeserializeStandard(this IEnumerable strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || !strs.Any()) { - foreach (var str in strs) - { - yield return str.DeserializeStandard(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.DeserializeStandard(); } } - public static IEnumerable DeserializeStandard(this IReadOnlyList strs) where T : class + public static IEnumerable DeserializeStandard(this IReadOnlyCollection strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeStandard(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.DeserializeStandard(); } } - public static IEnumerable DeserializeStandard(this IReadOnlySet strs) where T : class + public static IEnumerable DeserializeStandard(this IReadOnlyList strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeStandard(); - } + yield break; } - else + for (var i = 0; i < strs.Count; i++) { - yield break; + yield return strs[i].DeserializeStandard(); } } - public static IEnumerable DeserializeStandard(params string[] strs) where T : class + public static IEnumerable DeserializeStandard(this IReadOnlySet strs) where T : class { - if (strs is not null && strs.Any()) + if (strs is null || strs.Count <= 0) { - foreach (var str in strs) - { - yield return str.DeserializeStandard(); - } + yield break; } - else + foreach (var str in strs) { - yield break; + yield return str.DeserializeStandard(); } } } diff --git a/lib/YANLib/YANModel.Property.cs b/lib/YANLib/YANModel.Property.cs new file mode 100644 index 00000000..08ba1694 --- /dev/null +++ b/lib/YANLib/YANModel.Property.cs @@ -0,0 +1,2902 @@ +using static System.Activator; + +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) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties()) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesNotDefault(); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(); + } + } + + /// + /// 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 IReadOnlyCollection mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(); + } + } + + /// + /// 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 IReadOnlyList mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesNotDefault(); + } + } + + /// + /// 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 IReadOnlySet mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(); + } + } + + /// + /// 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) + { + return false; + } + foreach (var prop in typeof(T).GetProperties()) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default(T))) + { + return false; + } + } + 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(params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesDefault(); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(); + } + } + + /// + /// 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 IReadOnlyCollection mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(); + } + } + + /// + /// 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 IReadOnlyList mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesDefault(); + } + } + + /// + /// 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 IReadOnlySet mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(); + } + } + + /// + /// 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) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties()) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(); + } + } + + /// + /// 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 IReadOnlyCollection mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(); + } + } + + /// + /// 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 IReadOnlyList mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(); + } + } + + /// + /// 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 IReadOnlySet mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(); + } + } + + /// + /// 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) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties()) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesDefault(); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(); + } + } + + /// + /// 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 IReadOnlyCollection mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(); + } + } + + /// + /// 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 IReadOnlyList mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesDefault(); + } + } + + /// + /// 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 AllPropertiAnyPropertiesDefaultesDefault(this IReadOnlySet mdls) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, params string[] names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IEnumerable names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IEnumerable names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IEnumerable names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IEnumerable names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IEnumerable names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IReadOnlyCollection names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IReadOnlyCollection names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IReadOnlyCollection names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IReadOnlyCollection names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyCollection names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyCollection names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IReadOnlyList names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IReadOnlyList names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IReadOnlyList names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IReadOnlyList names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlyList names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlyList names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IReadOnlySet names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return false; + } + } + 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(IReadOnlySet names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AllPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AllPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IReadOnlySet names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesNotDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesNotDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdl is null || names.IsNullOrWhiteSpace()) + { + return false; + } + foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + { + var type = prop.PropertyType; + if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) + { + return true; + } + } + 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(IReadOnlySet names, params T[] mdls) where T : class + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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, IReadOnlySet names) where T : class + { + if (mdls is null || !mdls.Any()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyCollection mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlyList mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].AnyPropertiesDefault(names); + } + } + + /// + /// 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 IReadOnlySet mdls, IReadOnlySet names) where T : class + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.AnyPropertiesDefault(names); + } + } +} diff --git a/lib/YANLib/YANModel.cs b/lib/YANLib/YANModel.cs index e5749b67..2b109540 100644 --- a/lib/YANLib/YANModel.cs +++ b/lib/YANLib/YANModel.cs @@ -1,5 +1,4 @@ using System.Collections; -using static System.Activator; using static System.Reflection.BindingFlags; namespace YANLib; @@ -70,6 +69,121 @@ 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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(T1 tzSrc, T2 tzDst, params T?[] mdls) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyCollection mdls, T1 tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyList mdls, T1 tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlySet mdls, T1 tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + /// /// 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 . @@ -134,6 +248,121 @@ 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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(T1? tzSrc, T2 tzDst, params T?[] mdls) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyCollection mdls, T1? tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyList mdls, T1? tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlySet mdls, T1? tzSrc, T2 tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + /// /// 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 . @@ -198,6 +427,121 @@ 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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(T1 tzSrc, T2? tzDst, params T?[] mdls) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Length <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Length; i++) + { + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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()) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyCollection mdls, T1 tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyList mdls, T1 tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + for (var i = 0; i < mdls.Count; i++) + { + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + + /// + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlySet mdls, T1 tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct + { + if (mdls is null || mdls.Count <= 0) + { + yield break; + } + foreach (var mdl in mdls) + { + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); + } + } + /// /// 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 . @@ -263,598 +607,117 @@ 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) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties()) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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) - { - return false; - } - foreach (var prop in typeof(T).GetProperties()) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default(T))) - { - return false; - } - } - return true; - } - - /// - /// 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) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties()) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties()) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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 . + /// 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 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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, IReadOnlyCollection names) where T : class - { - if (mdl is null || names.IsNullOrWhiteSpace()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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, IReadOnlyCollection names) where T : class - { - if (mdl is null || names.IsNullOrWhiteSpace()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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, IReadOnlyCollection names) where T : class - { - if (mdl is null || names.IsNullOrWhiteSpace()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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, IReadOnlyCollection names) where T : class - { - if (mdl is null || names.IsNullOrWhiteSpace()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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, IReadOnlyList names) where T : class - { - if (mdl is null || names.IsNullOrWhiteSpace()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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, IReadOnlyList names) where T : class - { - if (mdl is null || names.IsNullOrWhiteSpace()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } - } - return true; - } - - /// - /// 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, IReadOnlyList names) where T : class - { - if (mdl is null || names.IsNullOrWhiteSpace()) - { - return false; - } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) - { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } - } - return false; - } - - /// - /// 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, IReadOnlyList names) where T : class + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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(T1? tzSrc, T2? tzDst, params T?[] mdls) where T : class where T1 : struct where T2 : struct { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdls is null || mdls.Length <= 0) { - return false; + yield break; } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + for (var i = 0; i < mdls.Length; i++) { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); } - return false; } /// - /// 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 . + /// 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 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, IReadOnlySet names) where T : class + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 (mdl is null || names.IsNullOrWhiteSpace()) + if (mdls is null || !mdls.Any()) { - return false; + yield break; } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + foreach (var mdl in mdls) { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); } - return true; } /// - /// 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 . + /// 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 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, IReadOnlySet names) where T : class + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyCollection mdls, T1? tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdls is null || mdls.Count <= 0) { - return false; + yield break; } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + foreach (var mdl in mdls) { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return false; - } + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); } - return true; } /// - /// 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 . + /// 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 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, IReadOnlySet names) where T : class + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlyList mdls, T1? tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdls is null || mdls.Count <= 0) { - return false; + yield break; } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + for (var i = 0; i < mdls.Count; i++) { - var type = prop.PropertyType; - if (!EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } + yield return mdls[i].ChangeTimeZoneAllProperties(tzSrc, tzDst); } - return false; } /// - /// 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 . + /// 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 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, IReadOnlySet names) where T : class + /// 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 source time zone. + /// The destination time zone. + /// The nullable objects to change the 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 IReadOnlySet mdls, T1? tzSrc, T2? tzDst) where T : class where T1 : struct where T2 : struct { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdls is null || mdls.Count <= 0) { - return false; + yield break; } - foreach (var prop in mdl.GetType().GetProperties().Where(p => names.Contains(p.Name))) + foreach (var mdl in mdls) { - var type = prop.PropertyType; - if (EqualityComparer.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default)) - { - return true; - } + yield return mdl.ChangeTimeZoneAllProperties(tzSrc, tzDst); } - return false; } } diff --git a/lib/YANLib/YANTask.cs b/lib/YANLib/YANTask.cs index 4e591a06..a26a9a6b 100644 --- a/lib/YANLib/YANTask.cs +++ b/lib/YANLib/YANTask.cs @@ -5,7 +5,19 @@ namespace YANLib; public static partial class YANTask { /// - /// Waits for any of the specified objects to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an array 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 array 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 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 of objects to wait for. @@ -28,16 +40,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ICollection> tasks, T goodRslt) where T : IComparable + public static async ValueTask WaitAnyWithCondition(this IReadOnlyCollection> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -51,16 +63,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 IList> tasks, T goodRslt) where T : IComparable + public static async ValueTask WaitAnyWithCondition(this IReadOnlyList> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -74,16 +86,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ISet> tasks, T goodRslt) where T : IComparable + public static async ValueTask WaitAnyWithCondition(this IReadOnlySet> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -97,22 +109,22 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an array of to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an array 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 array of objects to wait for. + /// An array 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); + 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 to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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. @@ -129,16 +141,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ICollection> tasks, T goodRslt) where T : IComparable + public static async ValueTask WaitAnyWithCondition(this IReadOnlyCollection> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -149,16 +161,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 IList> tasks, T goodRslt) where T : IComparable + public static async ValueTask WaitAnyWithCondition(this IReadOnlyList> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -169,16 +181,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ISet> tasks, T goodRslt) where T : IComparable + public static async ValueTask WaitAnyWithCondition(this IReadOnlySet> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -198,13 +210,13 @@ public static partial class YANTask /// 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); + 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 to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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. @@ -230,16 +242,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ICollection> tasks, T goodRslt) where T : IComparable + public static async ValueTask WhenAnyWithCondition(this IReadOnlyCollection> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -259,16 +271,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 IList> tasks, T goodRslt) where T : IComparable + public static async ValueTask WhenAnyWithCondition(this IReadOnlyList> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -288,16 +300,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ISet> tasks, T goodRslt) where T : IComparable + public static async ValueTask WhenAnyWithCondition(this IReadOnlySet> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -317,22 +329,22 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an array of to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an array 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 array of objects to wait for. + /// An array 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); + 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 to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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. @@ -349,16 +361,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ICollection> tasks, T goodRslt) where T : IComparable + public static async ValueTask WhenAnyWithCondition(this IReadOnlyCollection> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -369,16 +381,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 IList> tasks, T goodRslt) where T : IComparable + public static async ValueTask WhenAnyWithCondition(this IReadOnlyList> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -389,16 +401,16 @@ public static partial class YANTask } /// - /// Waits for any of the specified objects in an to complete and returns a nullable result that matches the specified condition. + /// Waits for any of the specified objects in an 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 of objects to wait for. + /// An 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 ISet> tasks, T goodRslt) where T : IComparable + public static async ValueTask WhenAnyWithCondition(this IReadOnlySet> tasks, T goodRslt) where T : IComparable { if (tasks is not null && tasks.Count > 0) { @@ -407,16 +419,4 @@ public static partial class YANTask } return default; } - - /// - /// Waits for any of the specified objects in an array 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 array 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); } diff --git a/lib/YANLib/YANText.cs b/lib/YANLib/YANText.cs index 735d0dff..89575bc5 100644 --- a/lib/YANLib/YANText.cs +++ b/lib/YANLib/YANText.cs @@ -64,7 +64,7 @@ public static string CleanSpace(this string str) { if (!isWhtSp) { - _ = sb.Append(' '); + _ = sb.Append(str[i]); isWhtSp = true; } } diff --git a/src/YANLib.Application.Contracts/Dtos/JsonDto.cs b/src/YANLib.Application.Contracts/Dtos/JsonTestDto.cs similarity index 88% rename from src/YANLib.Application.Contracts/Dtos/JsonDto.cs rename to src/YANLib.Application.Contracts/Dtos/JsonTestDto.cs index 8c54e0af..261ba4eb 100644 --- a/src/YANLib.Application.Contracts/Dtos/JsonDto.cs +++ b/src/YANLib.Application.Contracts/Dtos/JsonTestDto.cs @@ -2,7 +2,7 @@ namespace YANLib.Dtos; -public class JsonDto +public class JsonTestDto { public Guid Id { get; set; } public string Name { get; set; } diff --git a/src/YANLib.Application.Contracts/Services/IYANJsonService.cs b/src/YANLib.Application.Contracts/Services/IYANJsonService.cs index e41836a2..cd678be7 100644 --- a/src/YANLib.Application.Contracts/Services/IYANJsonService.cs +++ b/src/YANLib.Application.Contracts/Services/IYANJsonService.cs @@ -7,7 +7,7 @@ namespace YANLib.Services; public interface IYANJsonService : IApplicationService { - public ValueTask Serialize(JsonDto request); - public ValueTask SerializeCamel(JsonDto request); - public ValueTask> Deserialize(byte quantity); + public ValueTask Serializes(List requests); + public ValueTask CamelSerializes(List requests); + public ValueTask> Deserializes(byte quantity); } diff --git a/src/YANLib.Application/Services/YANJsonService.cs b/src/YANLib.Application/Services/YANJsonService.cs index df1a9ab9..ead89d42 100644 --- a/src/YANLib.Application/Services/YANJsonService.cs +++ b/src/YANLib.Application/Services/YANJsonService.cs @@ -13,26 +13,36 @@ namespace YANLib.Services; public class YANJsonService : YANLibAppService, IYANJsonService { // Serialize - public async ValueTask Serialize(JsonDto request) => await FromResult(request.Serialize()); + public async ValueTask Serializes(List requests) => await FromResult(requests.Serialize()); // Serialize camel case - public async ValueTask SerializeCamel(JsonDto request) => await FromResult(request.SerializeCamel()); + public async ValueTask CamelSerializes(List requests) => await FromResult(requests.SerializeCamel()); // Deserialize - public async ValueTask> Deserialize(byte quantity) => quantity == 0 ? default : await FromResult(GenData(quantity).DeserializeStandard().Clean().ToList()); + public async ValueTask> Deserializes(byte quantity) => quantity == 0 ? default : await FromResult(ModData(quantity).Clean().ToList()); // Generate data private static IEnumerable GenData(byte quantity) { for (var i = 0; i < quantity; i++) { - yield return new JsonDto + yield return new JsonTestDto { Id = Guid.NewGuid(), - Name = $"Nguyễn Văn {GenerateRandomCharacter()}".ToTitle(), - Income = GenerateRandomUint(), + Name = $"Nguyễn Văn {GenerateRandomCharacter().ToUpper()}", + Income = GenerateRandomUshort(), IsRisk = GenerateRandomBool() }.SerializeCamel(); } } + + // Modified data + private static IEnumerable ModData(byte quantity) + { + foreach (var dto in GenData(quantity).DeserializeStandard()) + { + dto.Income *= 1000; + yield return dto; + } + } } diff --git a/src/YANLib.HttpApi/Controllers/YANJsonController.cs b/src/YANLib.HttpApi/Controllers/YANJsonController.cs index 878e95b1..d8474d3c 100644 --- a/src/YANLib.HttpApi/Controllers/YANJsonController.cs +++ b/src/YANLib.HttpApi/Controllers/YANJsonController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; using System.Threading.Tasks; using YANLib.Dtos; using YANLib.Services; @@ -17,13 +18,13 @@ public class YANJsonController : YANLibController #endregion #region Methods - [HttpPost("serialize")] - public async ValueTask Serialize([FromBody] JsonDto request) => Ok(await _yanJsonService.Serialize(request)); + [HttpPost("serializes")] + public async ValueTask Serialize([FromBody] List request) => Ok(await _yanJsonService.Serializes(request)); - [HttpPost("serialize-camel")] - public async ValueTask SerializeCamel([FromBody] JsonDto request) => Ok(await _yanJsonService.SerializeCamel(request)); + [HttpPost("camel-serializes")] + public async ValueTask SerializeCamel([FromBody] List request) => Ok(await _yanJsonService.CamelSerializes(request)); - [HttpGet("deserialize")] - public async ValueTask Deserialize(byte quantity = 1) => Ok(await _yanJsonService.Deserialize(quantity)); + [HttpGet("deserializes")] + public async ValueTask Deserialize(byte quantity = 1) => Ok(await _yanJsonService.Deserializes(quantity)); #endregion }