From c50c5dd6b378327a7cf56ba1f4d90cb426f7010a Mon Sep 17 00:00:00 2001 From: Yami An Date: Thu, 4 May 2023 02:54:23 +0700 Subject: [PATCH] v3.1.2 --- .../YANLib.HttpApi.Host.csproj | 1 + .../YANLibHttpApiHostModule.cs | 15 +- lib/YANLib/Nullable/YANDateTime.Nullable.cs | 66 +++++-- lib/YANLib/Nullable/YANDateTime.cs | 82 ++++++-- lib/YANLib/YANDateTime.Nullable.cs | 62 ++++-- lib/YANLib/YANDateTime.cs | 74 ++++++- lib/YANLib/YANEnumerable.cs | 22 ++- lib/YANLib/YANLib.csproj | 13 +- lib/YANLib/YANModel.Property.cs | 186 ++++-------------- lib/YANLib/YANProcess.cs | 4 +- lib/YANLib/YANText.Char.cs | 170 +++++++++------- lib/YANLib/YANText.String.cs | 124 ++++++------ lib/YANLib/nuget.config | 2 +- .../Dtos/JsonDto.cs | 8 + .../Dtos/JsonTestDto.cs | 11 -- .../Services/IYANJsonService.cs | 8 +- .../Services/YANJsonService.cs | 72 +++---- .../Controllers/YANJsonController.cs | 65 +++++- src/YANLib.HttpApi/YANLib.HttpApi.csproj | 2 + 19 files changed, 546 insertions(+), 441 deletions(-) create mode 100644 src/YANLib.Application.Contracts/Dtos/JsonDto.cs delete mode 100644 src/YANLib.Application.Contracts/Dtos/JsonTestDto.cs diff --git a/host/YANLib.HttpApi.Host/YANLib.HttpApi.Host.csproj b/host/YANLib.HttpApi.Host/YANLib.HttpApi.Host.csproj index 1df6fe47..0edb19bb 100644 --- a/host/YANLib.HttpApi.Host/YANLib.HttpApi.Host.csproj +++ b/host/YANLib.HttpApi.Host/YANLib.HttpApi.Host.csproj @@ -16,6 +16,7 @@ + diff --git a/host/YANLib.HttpApi.Host/YANLibHttpApiHostModule.cs b/host/YANLib.HttpApi.Host/YANLibHttpApiHostModule.cs index e2536af6..6b9a69dc 100644 --- a/host/YANLib.HttpApi.Host/YANLibHttpApiHostModule.cs +++ b/host/YANLib.HttpApi.Host/YANLibHttpApiHostModule.cs @@ -29,11 +29,11 @@ using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.VirtualFileSystem; using static System.IO.Path; +using Swashbuckle.AspNetCore.SwaggerUI; namespace YANLib; - [DependsOn( - typeof(YANLibHttpApiModule), +typeof(YANLibHttpApiModule), typeof(AbpAutofacModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(YANLibApplicationModule), @@ -136,14 +136,16 @@ private static void ConfigureSwaggerServices(ServiceConfigurationContext context configuration["AuthServer:Authority"], new Dictionary { - {"YANLib", "YANLib API"} + {"YANLib", "YANLib API"}, + {"YANJson", "YANJson API"} }, options => { - options.SwaggerDoc("v1", new OpenApiInfo { Title = "YANLib API", Version = "v1" }); - options.DocInclusionPredicate((docName, description) => true); + options.SwaggerDoc("main", new OpenApiInfo { Title = "YANLib API", Version = "main" }); + options.SwaggerDoc("json", new OpenApiInfo { Title = "YANJson API", Version = "json" }); options.CustomSchemaIds(type => type.FullName); options.HideAbpEndpoints(); + options.EnableAnnotations(); }); } @@ -231,7 +233,8 @@ public override void OnApplicationInitialization(ApplicationInitializationContex app.UseSwagger(); app.UseAbpSwaggerUI(c => { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "YANLib API"); + c.SwaggerEndpoint("/swagger/main/swagger.json", "YANLib API"); + c.SwaggerEndpoint("/swagger/json/swagger.json", "YANJson API"); var configuration = context.ServiceProvider.GetRequiredService(); c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); diff --git a/lib/YANLib/Nullable/YANDateTime.Nullable.cs b/lib/YANLib/Nullable/YANDateTime.Nullable.cs index f56620f2..ad309cba 100644 --- a/lib/YANLib/Nullable/YANDateTime.Nullable.cs +++ b/lib/YANLib/Nullable/YANDateTime.Nullable.cs @@ -4,13 +4,27 @@ namespace YANLib.Nullable; public static partial class YANDateTime { - + /// + /// Converts the specified string representation of a date and time to its equivalent using the specified format. + /// Returns the resulting object if the conversion is successful, otherwise returns the specified default value. + /// + /// The string to be converted to . + /// The format of the input string. + /// The default value to return if the conversion fails. + /// The equivalent of the input string in the specified format, or the specified default value if the conversion fails. public static DateTime? ToDateTime(this string str, string fmt, DateTime? dfltVal) => dfltVal.HasValue ? str.ToDateTime(fmt, dfltVal.Value) : default; - + /// + /// Converts a collection of string representations of dates and times to their equivalents using the specified format. + /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// The format of the input strings. + /// The default value to return for any strings that fail to convert. + /// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert. public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -20,10 +34,37 @@ public static partial class YANDateTime } } - + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : default; - + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. + public static DateTime? GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default; + + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. + public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max); + + /// + /// Generates a random object between the minimum value and the specified maximum value. + /// + /// The maximum value that can be generated. + /// A randomly generated object between the minimum value and the specified maximum value. + public static DateTime? GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default; + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -32,7 +73,6 @@ public static partial class YANDateTime } } - public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -41,10 +81,6 @@ public static partial class YANDateTime } } - - public static DateTime? GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default; - - public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -53,7 +89,6 @@ public static partial class YANDateTime } } - public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T? size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -62,10 +97,6 @@ public static partial class YANDateTime } } - - public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max); - - public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -74,7 +105,6 @@ public static partial class YANDateTime } } - public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -83,10 +113,6 @@ public static partial class YANDateTime } } - - public static DateTime? GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default; - - public static int? GetWeekOfYear(this DateTime? dt) => dt.HasValue ? dt.Value.GetWeekOfYear() : default; diff --git a/lib/YANLib/Nullable/YANDateTime.cs b/lib/YANLib/Nullable/YANDateTime.cs index d8162276..6b78c6ed 100644 --- a/lib/YANLib/Nullable/YANDateTime.cs +++ b/lib/YANLib/Nullable/YANDateTime.cs @@ -9,13 +9,23 @@ namespace YANLib.Nullable; public static partial class YANDateTime { - + /// + /// Converts the specified string representation of a date and time to its equivalent. + /// Returns the resulting object if the conversion is successful, otherwise returns default. + /// + /// The string to be converted to . + /// The equivalent of the input string, or default if the conversion fails. public static DateTime? ToDateTime(this string str) => TryParse(str, out var dt) ? dt : default; - + /// + /// Converts a collection of string representations of dates and times to their equivalents. + /// Returns an enumerable collection of objects for each successfully converted input string, and skips any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// An enumerable collection of objects for each successfully converted input string. public static IEnumerable ToDateTime(this IEnumerable strs) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -25,13 +35,25 @@ public static partial class YANDateTime } } - + /// + /// Converts the specified string representation of a date and time to its equivalent using the specified format. + /// Returns the resulting object if the conversion is successful, otherwise returns default. + /// + /// The string to be converted to . + /// The format of the input string. + /// The equivalent of the input string in the specified format, or default if the conversion fails. public static DateTime? ToDateTime(this string str, string fmt) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : default; - + /// + /// Converts a collection of string representations of dates and times to their equivalents using the specified format. + /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and skips any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// The format of the input strings. + /// An enumerable collection of objects for each successfully converted input string in the specified format. public static IEnumerable ToDateTime(this IEnumerable strs, string fmt) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -41,13 +63,27 @@ public static partial class YANDateTime } } - + /// + /// Converts the specified string representation of a date and time to its equivalent using the specified format. + /// Returns the resulting object if the conversion is successful, otherwise returns the specified default value. + /// + /// The string to be converted to . + /// The format of the input string. + /// The default value to return if the conversion fails. + /// The equivalent of the input string in the specified format, or the specified default value if the conversion fails. public static DateTime? ToDateTime(this string str, string fmt, DateTime dfltVal) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : dfltVal; - + /// + /// Converts a collection of string representations of dates and times to their equivalents using the specified format. + /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// The format of the input strings. + /// The default value to return for any strings that fail to convert. + /// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert. public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -57,10 +93,27 @@ public static partial class YANDateTime } } - + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. public static DateTime? GenerateRandomDateTime(DateTime min, DateTime max) => min > max ? default : min.AddTicks(GenerateRandomLong((max - min).Ticks)); - + /// + /// Generates a random object between the minimum value of and maximum value of . + /// + /// A randomly generated object between the minimum value of and maximum value of . + public static DateTime? GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue); + + /// + /// Generates a random object between the minimum value and the specified maximum value. + /// + /// The maximum value that can be generated. + /// A randomly generated object between the minimum value and the specified maximum value. + public static DateTime? GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max); + public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime max, T size) where T : struct { for (var i = 0ul; i < YANNum.ToUlong(size); i++) @@ -69,13 +122,6 @@ public static partial class YANDateTime } } - - public static DateTime? GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue); - - - public static DateTime? GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max); - - public static int? GetWeekOfYear(this DateTime dt) => CurrentInfo.Calendar.GetWeekOfYear(dt, CurrentInfo.CalendarWeekRule, CurrentInfo.FirstDayOfWeek); diff --git a/lib/YANLib/YANDateTime.Nullable.cs b/lib/YANLib/YANDateTime.Nullable.cs index 4cf2d76f..ee22acae 100644 --- a/lib/YANLib/YANDateTime.Nullable.cs +++ b/lib/YANLib/YANDateTime.Nullable.cs @@ -4,12 +4,27 @@ namespace YANLib; public static partial class YANDateTime { - + /// + /// Converts the specified string representation of a date and time to its equivalent using the specified format. + /// Returns the resulting object if the conversion is successful, otherwise returns the specified default value. + /// + /// The string to be converted to . + /// The format of the input string. + /// The default value to return if the conversion fails. + /// The equivalent of the input string in the specified format, or the specified default value if the conversion fails. public static DateTime ToDateTime(this string str, string fmt, DateTime? dfltVal) => dfltVal.HasValue ? str.ToDateTime(fmt, dfltVal.Value) : default; + /// + /// Converts a collection of string representations of dates and times to their equivalents using the specified format. + /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// The format of the input strings. + /// The default value to return for any strings that fail to convert. + /// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert. public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -19,9 +34,38 @@ public static IEnumerable ToDateTime(this IEnumerable strs, st } } + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. public static DateTime GenerateRandomDateTime(DateTime? min, DateTime max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : default; - public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. + public static DateTime GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default; + + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. + public static DateTime GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max); + + /// + /// Generates a random object between the minimum value and the specified maximum value. + /// + /// The maximum value that can be generated. + /// A randomly generated object between the minimum value and the specified maximum value. + public static DateTime GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default; + + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) { @@ -29,7 +73,7 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) { @@ -37,8 +81,6 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - public static DateTime GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default; - public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) @@ -55,9 +97,7 @@ public static IEnumerable GenerateRandomDateTimes(DateTime min, Dat } } - public static DateTime GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max); - - public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) { @@ -65,7 +105,7 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct + public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct { for (var i = 0ul; i < size.ToUlong(); i++) { @@ -73,8 +113,6 @@ public static IEnumerable GenerateRandomDateTimes(DateTime? min, Da } } - public static DateTime GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default; - public static int GetWeekOfYear(this DateTime? dt) => dt.HasValue ? dt.Value.GetWeekOfYear() : default; public static IEnumerable GetWeekOfYear(this IEnumerable dts) diff --git a/lib/YANLib/YANDateTime.cs b/lib/YANLib/YANDateTime.cs index c4b3c845..9c17504e 100644 --- a/lib/YANLib/YANDateTime.cs +++ b/lib/YANLib/YANDateTime.cs @@ -9,12 +9,23 @@ namespace YANLib; public static partial class YANDateTime { - + /// + /// Converts the specified string representation of a date and time to its equivalent. + /// Returns the resulting object if the conversion is successful, otherwise returns default. + /// + /// The string to be converted to . + /// The equivalent of the input string, or default if the conversion fails. public static DateTime ToDateTime(this string str) => TryParse(str, out var dt) ? dt : default; + /// + /// Converts a collection of string representations of dates and times to their equivalents. + /// Returns an enumerable collection of objects for each successfully converted input string, and skips any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// An enumerable collection of objects for each successfully converted input string. public static IEnumerable ToDateTime(this IEnumerable strs) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -24,11 +35,25 @@ public static IEnumerable ToDateTime(this IEnumerable strs) } } + /// + /// Converts the specified string representation of a date and time to its equivalent using the specified format. + /// Returns the resulting object if the conversion is successful, otherwise returns default. + /// + /// The string to be converted to . + /// The format of the input string. + /// The equivalent of the input string in the specified format, or default if the conversion fails. public static DateTime ToDateTime(this string str, string fmt) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : default; + /// + /// Converts a collection of string representations of dates and times to their equivalents using the specified format. + /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and skips any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// The format of the input strings. + /// An enumerable collection of objects for each successfully converted input string in the specified format. public static IEnumerable ToDateTime(this IEnumerable strs, string fmt) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -38,11 +63,27 @@ public static IEnumerable ToDateTime(this IEnumerable strs, st } } + /// + /// Converts the specified string representation of a date and time to its equivalent using the specified format. + /// Returns the resulting object if the conversion is successful, otherwise returns the specified default value. + /// + /// The string to be converted to . + /// The format of the input string. + /// The default value to return if the conversion fails. + /// The equivalent of the input string in the specified format, or the specified default value if the conversion fails. public static DateTime ToDateTime(this string str, string fmt, DateTime dfltVal) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : dfltVal; + /// + /// Converts a collection of string representations of dates and times to their equivalents using the specified format. + /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert. + /// + /// The collection of strings to be converted to . + /// The format of the input strings. + /// The default value to return for any strings that fail to convert. + /// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert. public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal) { - if (strs.IsNullOrWhiteSpace()) + if (strs.AllNullOrWhiteSpace()) { yield break; } @@ -52,7 +93,26 @@ public static IEnumerable ToDateTime(this IEnumerable strs, st } } - public static DateTime GenerateRandomDateTime(DateTime min, DateTime max) => min > max ? default : min.AddTicks(GenerateRandomLong((max - min).Ticks)); + /// + /// Generates a random object between the specified minimum and maximum values. + /// + /// The minimum value that can be generated. + /// The maximum value that can be generated. + /// A randomly generated object between the specified minimum and maximum values. + public static DateTime GenerateRandomDateTime(DateTime min, DateTime max) => min > max ? default : min.AddTicks((long)GenerateRandomUlong((max - min).Ticks)); + + /// + /// Generates a random object between the minimum value of and maximum value of . + /// + /// A randomly generated object between the minimum value of and maximum value of . + public static DateTime GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue); + + /// + /// Generates a random object between the minimum value and the specified maximum value. + /// + /// The maximum value that can be generated. + /// A randomly generated object between the minimum value and the specified maximum value. + public static DateTime GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max); public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime max, T size) where T : struct { @@ -62,10 +122,6 @@ public static IEnumerable GenerateRandomDateTimes(DateTime min, Dat } } - public static DateTime GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue); - - public static DateTime GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max); - public static int GetWeekOfYear(this DateTime dt) => CurrentInfo.Calendar.GetWeekOfYear(dt, CurrentInfo.CalendarWeekRule, CurrentInfo.FirstDayOfWeek); public static IEnumerable GetWeekOfYear(this IEnumerable dts) diff --git a/lib/YANLib/YANEnumerable.cs b/lib/YANLib/YANEnumerable.cs index eb91848f..e5a0650d 100644 --- a/lib/YANLib/YANEnumerable.cs +++ b/lib/YANLib/YANEnumerable.cs @@ -10,7 +10,7 @@ public static partial class YANEnumerable public static IEnumerable> ChunkBySize(this List srcs, T1 chunkSize) where T1 : struct { var size = chunkSize.ToInt(); - if (srcs is null || srcs.Count < 1 && size < 1) + if (srcs.IsNullOrEmpty() && size < 1) { yield break; } @@ -23,7 +23,7 @@ public static IEnumerable> ChunkBySize(this List srcs, T1 chun public static IEnumerable Clean(this IEnumerable srcs) { - if (srcs is null || !srcs.Any()) + if (srcs.IsNullOrEmpty()) { yield break; } @@ -49,7 +49,7 @@ public static IEnumerable Clean(this IEnumerable srcs) public static void Clean(this ICollection srcs) { - if (srcs is not null && srcs.Any()) + if (srcs.IsNotNullAndEmpty()) { var t = typeof(T); if (t.IsClass || GetUnderlyingType(t) is not null) @@ -93,4 +93,20 @@ public static void Clean(this ICollection srcs) } } } + + public static bool IsNullOrEmpty(this IEnumerable srcs) => srcs is null || !srcs.Any(); + + public static bool IsNullOrEmpty(this IReadOnlyCollection srcs) => srcs is null || srcs.Count < 1; + + public static bool IsNotNullAndEmpty(this IEnumerable srcs) => srcs is not null && srcs.Any(); + + public static bool IsNotNullAndEmpty(this IReadOnlyCollection srcs) => srcs is not null && srcs.Count > 0; + + public static bool AllNullOrEmpty(IEnumerable srcs) where T : class => !srcs.Any(x => x is not null || x.AnyPropertiesNotDefault()); + + public static bool AnyNullOrEmpty(IEnumerable srcs) where T : class => srcs.Any(x => x is null || x.AllPropertiesDefault()); + + public static bool AllNotNullAndEmpty(IEnumerable srcs) where T : class => !srcs.Any(x => x is null || x.AllPropertiesDefault()); + + public static bool AnyNotNullAndEmpty(IEnumerable srcs) where T : class => srcs.Any(x => x is not null || x.AnyPropertiesNotDefault()); } diff --git a/lib/YANLib/YANLib.csproj b/lib/YANLib/YANLib.csproj index 5ec2590b..bf294cc8 100644 --- a/lib/YANLib/YANLib.csproj +++ b/lib/YANLib/YANLib.csproj @@ -9,12 +9,7 @@ YANLib Yami An YAN - Update: -- YANEnumarable -- YANProcess -- YANText -- YANModel -- YANPass + Beta Copyright © 2023 icon.png https://github.com/Tynab @@ -23,13 +18,11 @@ False README.md git - Fix: -- Method name -- FilterAlphabetic return + Beta MIT False Tynab.YANLib - 3.1.1 + 3.1.2 diff --git a/lib/YANLib/YANModel.Property.cs b/lib/YANLib/YANModel.Property.cs index cfcd51a4..4666fa3e 100644 --- a/lib/YANLib/YANModel.Property.cs +++ b/lib/YANLib/YANModel.Property.cs @@ -5,8 +5,8 @@ namespace YANLib; public static partial class YANModel { - - public static bool AllPropertiesNotDefault(this T mdl) where T : class + + public static bool AllPropertiesNotDefault(this T? mdl) where T : class { if (mdl is null) { @@ -23,19 +23,9 @@ public static bool AllPropertiesNotDefault(this T mdl) where T : class return true; } - 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(); - } - } + public static bool AllPropertiesNotDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesDefault()); - public static bool AllPropertiesDefault(this T mdl) where T : class + public static bool AllPropertiesDefault(this T? mdl) where T : class { if (mdl is null) { @@ -52,19 +42,9 @@ public static bool AllPropertiesDefault(this T mdl) where T : class return true; } - 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(); - } - } + public static bool AllPropertiesDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesNotDefault()); - public static bool AnyPropertiesNotDefault(this T mdl) where T : class + public static bool AnyPropertiesNotDefault(this T? mdl) where T : class { if (mdl is null) { @@ -81,19 +61,9 @@ public static bool AnyPropertiesNotDefault(this T mdl) where T : class return false; } - 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(); - } - } + public static bool AnyPropertiesNotDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesNotDefault()); - public static bool AnyPropertiesDefault(this T mdl) where T : class + public static bool AnyPropertiesDefault(this T? mdl) where T : class { if (mdl is null) { @@ -110,21 +80,11 @@ public static bool AnyPropertiesDefault(this T mdl) where T : class return false; } - 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(); - } - } + public static bool AnyPropertiesDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesDefault()); - public static bool AllPropertiesNotDefault(this T mdl, params string[] names) where T : class + public static bool AllPropertiesNotDefault(this T? mdl, params string[] names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -139,21 +99,11 @@ public static bool AllPropertiesNotDefault(this T mdl, params string[] names) return true; } - 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); - } - } + public static bool AllPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesDefault(names)); - public static bool AllPropertiesDefault(this T mdl, params string[] names) where T : class + public static bool AllPropertiesDefault(this T? mdl, params string[] names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -168,21 +118,11 @@ public static bool AllPropertiesDefault(this T mdl, params string[] names) wh return true; } - 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); - } - } + public static bool AllPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesNotDefault(names)); - public static bool AnyPropertiesNotDefault(this T mdl, params string[] names) where T : class + public static bool AnyPropertiesNotDefault(this T? mdl, params string[] names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -197,21 +137,11 @@ public static bool AnyPropertiesNotDefault(this T mdl, params string[] names) return false; } - 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); - } - } + public static bool AnyPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesNotDefault(names)); - public static bool AnyPropertiesDefault(this T mdl, params string[] names) where T : class + public static bool AnyPropertiesDefault(this T? mdl, params string[] names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -226,21 +156,11 @@ public static bool AnyPropertiesDefault(this T mdl, params string[] names) wh return false; } - 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); - } - } + public static bool AnyPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesDefault(names)); - public static bool AllPropertiesNotDefault(this T mdl, IEnumerable names) where T : class + public static bool AllPropertiesNotDefault(this T? mdl, IEnumerable names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -255,21 +175,11 @@ public static bool AllPropertiesNotDefault(this T mdl, IEnumerable na return true; } - 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); - } - } + public static bool AllPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesDefault(names)); - public static bool AllPropertiesDefault(this T mdl, IEnumerable names) where T : class + public static bool AllPropertiesDefault(this T? mdl, IEnumerable names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -284,21 +194,11 @@ public static bool AllPropertiesDefault(this T mdl, IEnumerable names return true; } - 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); - } - } + public static bool AllPropertiesDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesNotDefault(names)); - public static bool AnyPropertiesNotDefault(this T mdl, IEnumerable names) where T : class + public static bool AnyPropertiesNotDefault(this T? mdl, IEnumerable names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -313,21 +213,11 @@ public static bool AnyPropertiesNotDefault(this T mdl, IEnumerable na return false; } - 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); - } - } + public static bool AnyPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesNotDefault(names)); - public static bool AnyPropertiesDefault(this T mdl, IEnumerable names) where T : class + public static bool AnyPropertiesDefault(this T? mdl, IEnumerable names) where T : class { - if (mdl is null || names.IsNullOrWhiteSpace()) + if (mdl is null || names.AllNullOrWhiteSpace()) { return false; } @@ -342,15 +232,5 @@ public static bool AnyPropertiesDefault(this T mdl, IEnumerable names return false; } - 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); - } - } + public static bool AnyPropertiesDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesDefault(names)); } diff --git a/lib/YANLib/YANProcess.cs b/lib/YANLib/YANProcess.cs index 6a095d35..dac329fe 100644 --- a/lib/YANLib/YANProcess.cs +++ b/lib/YANLib/YANProcess.cs @@ -23,7 +23,7 @@ await WhenAll(GetProcessesByName(name).Select(p => public static async Task KillAllProcessesByName(params string[] names) { - if (names.IsNotNullAndWhiteSpace()) + if (names.AllNotNullAndWhiteSpace()) { await WhenAll(names.SelectMany(name => GetProcessesByName(name)).Select(p => { @@ -38,7 +38,7 @@ await WhenAll(names.SelectMany(name => GetProcessesByName(name)).Select(p => public static async Task KillAllProcessesByName(this IEnumerable names) { - if (names.IsNotNullAndWhiteSpace()) + if (names.AllNotNullAndWhiteSpace()) { await WhenAll(names.SelectMany(name => GetProcessesByName(name)).Select(p => { diff --git a/lib/YANLib/YANText.Char.cs b/lib/YANLib/YANText.Char.cs index ae7d2479..c5fd99d3 100644 --- a/lib/YANLib/YANText.Char.cs +++ b/lib/YANLib/YANText.Char.cs @@ -7,127 +7,137 @@ public static partial class YANText public static bool IsEmpty(this char c) => c is char.MinValue; - public static bool IsEmpty(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotEmpty()); + public static bool AllEmpty(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotEmpty()); - public static bool IsEmpty(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotEmpty()); + public static bool AnyEmpty(params char[] cs) => cs is not null && cs.Any(c => c.IsEmpty()); + + public static bool AllEmpty(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotEmpty()); + + public static bool AnyEmpty(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsEmpty()); public static bool IsWhiteSpace(this char c) => char.IsWhiteSpace(c); - public static bool IsWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotWhiteSpace()); + public static bool AllWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotWhiteSpace()); + + public static bool AnyWhiteSpace(params char[] cs) => cs is not null && cs.Any(c => c.IsWhiteSpace()); + + public static bool AllWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotWhiteSpace()); - public static bool IsWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotWhiteSpace()); + public static bool AnyWhiteSpace(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsWhiteSpace()); public static bool IsNullOrWhiteSpace(this char c) => c.IsEmpty() || c.IsWhiteSpace(); - public static bool IsNullOrWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace()); + public static bool AllNullOrWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace()); - public static bool IsNullOrWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace()); + public static bool AnyNullOrWhiteSpace(params char[] cs) => cs is not null && cs.Any(c => c.IsNullOrWhiteSpace()); + + public static bool AllNullOrWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace()); + + public static bool AnyNullOrWhiteSpace(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNullOrWhiteSpace()); public static bool IsAlphabetic(this char c) => char.IsLetter(c); - public static bool IsAlphabetic(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotAlphabetic()); + public static bool AllAlphabetic(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotAlphabetic()); + + public static bool AnyAlphabetic(params char[] cs) => cs is not null && cs.Any(c => c.IsAlphabetic()); + + public static bool AllAlphabetic(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotAlphabetic()); - public static bool IsAlphabetic(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotAlphabetic()); + public static bool AnyAlphabetic(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsAlphabetic()); public static bool IsPunctuation(this char c) => char.IsPunctuation(c); - public static bool IsPunctuation(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotPunctuation()); + public static bool AllPunctuation(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotPunctuation()); - public static bool IsPunctuation(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotPunctuation()); + public static bool AnyPunctuation(params char[] cs) => cs is not null && cs.Any(c => c.IsPunctuation()); - public static bool IsNumber(this char c) => char.IsDigit(c); + public static bool AllPunctuation(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotPunctuation()); + + public static bool AnyPunctuation(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsPunctuation()); - public static bool IsNumber(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotNumber()); + public static bool IsNumber(this char c) => char.IsDigit(c); - public static bool IsNumber(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotNumber()); + public static bool AllNumber(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotNumber()); - public static bool Equals(this char c1, char c2) => c1 == c2; + public static bool AnyNumber(params char[] cs) => cs is not null && cs.Any(c => c.IsNumber()); - public static bool Equals(params char[] cs) => cs is not null && !cs.Any(s => s.NotEquals(cs[0])); + public static bool AllNumber(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNotNumber()); - public static bool Equals(this IEnumerable cs) => cs is not null && !cs.Any(s => s.NotEquals(cs.First())); + public static bool AnyNumber(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNumber()); public static bool EqualsIgnoreCase(this char c1, char c2) => c1.ToLowerInvariant() == c2.ToLowerInvariant(); - public static bool EqualsIgnoreCase(params char[] cs) => cs is not null && !cs.Any(s => s.NotEqualsIgnoreCase(cs[0])); + public static bool AllEqualsIgnoreCase(params char[] cs) => cs is not null && !cs.Any(s => s.NotEqualsIgnoreCase(cs[0])); + + public static bool AnyEqualsIgnoreCase(params char[] cs) => !cs.AllNotEqualsIgnoreCase(); - public static bool EqualsIgnoreCase(this IEnumerable cs) => cs is not null && !cs.Any(s => s.NotEqualsIgnoreCase(cs.First())); + public static bool AllEqualsIgnoreCase(this IEnumerable cs) => cs is not null && !cs.Any(s => s.NotEqualsIgnoreCase(cs.First())); + + public static bool AnyEqualsIgnoreCase(this IEnumerable cs) => !cs.AllNotEqualsIgnoreCase(); public static bool IsNotEmpty(this char c) => c is not char.MinValue; - public static bool IsNotEmpty(params char[] cs) => cs is not null && !cs.Any(c => c.IsEmpty()); + public static bool AllNotEmpty(params char[] cs) => cs is not null && !cs.Any(c => c.IsEmpty()); + + public static bool AnyNotEmpty(params char[] cs) => cs is not null && cs.Any(c => c.IsNotEmpty()); + + public static bool AllNotEmpty(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsEmpty()); - public static bool IsNotEmpty(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsEmpty()); + public static bool AnyNotEmpty(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNotEmpty()); public static bool IsNotWhiteSpace(this char c) => !char.IsWhiteSpace(c); - public static bool IsNotWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsWhiteSpace()); + public static bool AllNotWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsWhiteSpace()); - public static bool IsNotWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsWhiteSpace()); + public static bool AnyNotWhiteSpace(params char[] cs) => cs is not null && cs.Any(c => c.IsNotWhiteSpace()); + + public static bool AllNotWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsWhiteSpace()); + + public static bool AnyNotWhiteSpace(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNotWhiteSpace()); public static bool IsNotEmptyAndWhiteSpace(this char c) => c.IsNotEmpty() && c.IsNotWhiteSpace(); - public static bool IsNotEmptyAndWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNullOrWhiteSpace()); + public static bool AllNotEmptyAndWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsNullOrWhiteSpace()); + + public static bool AnyNotEmptyAndWhiteSpace(params char[] cs) => cs is not null && cs.Any(c => c.IsNotEmptyAndWhiteSpace()); + + public static bool AllNotEmptyAndWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNullOrWhiteSpace()); - public static bool IsNotEmptyAndWhiteSpace(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNullOrWhiteSpace()); + public static bool AnyNotEmptyAndWhiteSpace(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNotEmptyAndWhiteSpace()); public static bool IsNotAlphabetic(this char c) => !char.IsLetter(c); - public static bool IsNotAlphabetic(params char[] cs) => cs is not null && !cs.Any(c => c.IsAlphabetic()); + public static bool AllNotAlphabetic(params char[] cs) => cs is not null && !cs.Any(c => c.IsAlphabetic()); - public static bool IsNotAlphabetic(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsAlphabetic()); + public static bool AnyNotAlphabetic(params char[] cs) => cs is not null && cs.Any(c => c.IsNotAlphabetic()); + + public static bool AllNotAlphabetic(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsAlphabetic()); + + public static bool AnyNotAlphabetic(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNotAlphabetic()); public static bool IsNotPunctuation(this char c) => !char.IsPunctuation(c); - public static bool IsNotPunctuation(params char[] cs) => cs is not null && !cs.Any(c => c.IsPunctuation()); + public static bool AllNotPunctuation(params char[] cs) => cs is not null && !cs.Any(c => c.IsPunctuation()); - public static bool IsNotPunctuation(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsPunctuation()); + public static bool AnyNotPunctuation(params char[] cs) => cs is not null && cs.Any(c => c.IsNotPunctuation()); - public static bool IsNotNumber(this char c) => !char.IsDigit(c); + public static bool AllNotPunctuation(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsPunctuation()); - public static bool IsNotNumber(params char[] cs) => cs is not null && !cs.Any(c => c.IsNumber()); + public static bool AnyNotPunctuation(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNotPunctuation()); - public static bool IsNotNumber(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNumber()); + public static bool IsNotNumber(this char c) => !char.IsDigit(c); - public static bool NotEquals(this char c1, char c2) => c1 != c2; + public static bool AllNotNumber(params char[] cs) => cs is not null && !cs.Any(c => c.IsNumber()); - public static bool NotEquals(params char[] cs) - { - if (cs is null || cs.Length < 2) - { - return false; - } - var hashSet = new HashSet(cs.Length); - for (var i = 0; i < cs.Length; i++) - { - if (!hashSet.Add(cs[i])) - { - return false; - } - } - return true; - } + public static bool AnyNotNumber(params char[] cs) => cs is not null && cs.Any(c => c.IsNotNumber()); - public static bool NotEquals(this IEnumerable cs) - { - if (cs is null || cs.Count() < 2) - { - return false; - } - var hashSet = new HashSet(cs.Count()); - foreach (var c in cs) - { - if (!hashSet.Add(c)) - { - return false; - } - } - return true; - } + public static bool AllNotNumber(this IEnumerable cs) => cs is not null && !cs.Any(c => c.IsNumber()); + + public static bool AnyNotNumber(this IEnumerable cs) => cs is not null && cs.Any(c => c.IsNotNumber()); public static bool NotEqualsIgnoreCase(this char c1, char c2) => c1.ToLowerInvariant() != c2.ToLowerInvariant(); - public static bool NotEqualsIgnoreCase(params char[] cs) + public static bool AllNotEqualsIgnoreCase(params char[] cs) { if (cs is null || cs.Length < 2) { @@ -144,7 +154,9 @@ public static bool NotEqualsIgnoreCase(params char[] cs) return true; } - public static bool NotEqualsIgnoreCase(this IEnumerable cs) + public static bool AnyNotEqualsIgnoreCase(params char[] cs) => !cs.AllEqualsIgnoreCase(); + + public static bool AllNotEqualsIgnoreCase(this IEnumerable cs) { if (cs is null || cs.Count() < 2) { @@ -161,6 +173,8 @@ public static bool NotEqualsIgnoreCase(this IEnumerable cs) return true; } + public static bool AnyNotEqualsIgnoreCase(this IEnumerable cs) => !cs.AllEqualsIgnoreCase(); + public static char GetValue(this char c) => c.IsEmpty() ? char.MinValue : c; public static char GetValue(this char c, char dfltVal) => c.IsEmpty() ? dfltVal : c; @@ -171,11 +185,19 @@ public static char GenerateRandomCharacter() return chars[GenerateRandomByte(chars.Length)]; } + public static IEnumerable GenerateRandomCharacters(T size) where T : struct + { + for (var i = 0ul; i < size.ToUlong(); i++) + { + yield return GenerateRandomCharacter(); + } + } + public static char ToLower(this char c) => c.IsNotEmptyAndWhiteSpace() ? char.ToLower(c) : c; public static IEnumerable ToLower(this IEnumerable cs) { - if (cs is null || !cs.Any()) + if (cs.IsNullOrEmpty()) { yield break; } @@ -187,7 +209,7 @@ public static IEnumerable ToLower(this IEnumerable cs) public static void ToLower(this IList cs) { - if (cs is not null && cs.Count > 0) + if (cs.IsNotNullAndEmpty()) { for (var i = 0; i < cs.Count; i++) { @@ -200,7 +222,7 @@ public static void ToLower(this IList cs) public static IEnumerable ToLowerInvariant(this IEnumerable cs) { - if (cs is null || !cs.Any()) + if (cs.IsNullOrEmpty()) { yield break; } @@ -212,7 +234,7 @@ public static IEnumerable ToLowerInvariant(this IEnumerable cs) public static void ToLowerInvariant(this IList cs) { - if (cs is not null && cs.Count > 0) + if (cs.IsNotNullAndEmpty()) { for (var i = 0; i < cs.Count; i++) { @@ -225,7 +247,7 @@ public static void ToLowerInvariant(this IList cs) public static IEnumerable ToUpper(this IEnumerable cs) { - if (cs is null || !cs.Any()) + if (cs.IsNullOrEmpty()) { yield break; } @@ -237,7 +259,7 @@ public static IEnumerable ToUpper(this IEnumerable cs) public static void ToUpper(this IList cs) { - if (cs is not null && cs.Count > 0) + if (cs.IsNotNullAndEmpty()) { for (var i = 0; i < cs.Count; i++) { @@ -250,7 +272,7 @@ public static void ToUpper(this IList cs) public static IEnumerable ToUpperInvariant(this IEnumerable cs) { - if (cs is null || !cs.Any()) + if (cs.IsNullOrEmpty()) { yield break; } @@ -262,7 +284,7 @@ public static IEnumerable ToUpperInvariant(this IEnumerable cs) public static void ToUpperInvariant(this IList cs) { - if (cs is not null && cs.Count > 0) + if (cs.IsNotNullAndEmpty()) { for (var i = 0; i < cs.Count; i++) { diff --git a/lib/YANLib/YANText.String.cs b/lib/YANLib/YANText.String.cs index ad3b952b..8db3206e 100644 --- a/lib/YANLib/YANText.String.cs +++ b/lib/YANLib/YANText.String.cs @@ -9,93 +9,79 @@ public static partial class YANText public static bool IsNull(this string str) => str is null; - public static bool IsNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNull()); + public static bool AllNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNull()); - public static bool IsNull(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNull()); + public static bool AnyNull(params string[] strs) => strs is not null && strs.Any(s => s.IsNull()); + + public static bool AllNull(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNull()); + + public static bool AnyNull(this IEnumerable strs) => strs is not null && strs.Any(s => s.IsNull()); public static bool IsNullOrEmpty(this string str) => string.IsNullOrEmpty(str); - public static bool IsNullOrEmpty(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNullAndEmpty()); + public static bool AllNullOrEmpty(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNullAndEmpty()); + + public static bool AnyNullOrEmpty(params string[] strs) => strs is not null && strs.Any(s => s.IsNullOrEmpty()); - public static bool IsNullOrEmpty(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNullAndEmpty()); + public static bool AllNullOrEmpty(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNullAndEmpty()); + + public static bool AnyNullOrEmpty(this IEnumerable strs) => strs is not null && strs.Any(s => s.IsNullOrEmpty()); public static bool IsNullOrWhiteSpace(this string str) => string.IsNullOrWhiteSpace(str); - public static bool IsNullOrWhiteSpace(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNullAndWhiteSpace()); + public static bool AllNullOrWhiteSpace(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNullAndWhiteSpace()); + + public static bool AnyNullOrWhiteSpace(params string[] strs) => strs is not null && strs.Any(s => s.IsNullOrWhiteSpace()); - public static bool IsNullOrWhiteSpace(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNullAndWhiteSpace()); + public static bool AllNullOrWhiteSpace(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNotNullAndWhiteSpace()); - public static bool Equals(this string str1, string str2) => str1 == str2; + public static bool AnyNullOrWhiteSpace(this IEnumerable strs) => strs is not null && strs.Any(s => s.IsNullOrWhiteSpace()); - public static bool Equals(params string[] strs) => strs is not null && !strs.Any(s => s.NotEquals(strs[0])); + public static bool EqualsIgnoreCase(this string str1, string str2) => AllNull(str1, str2) || str1.IsNotNull() && str1.IsNotNull() && string.Equals(str1, str2, OrdinalIgnoreCase); - public static bool Equals(this IEnumerable strs) => strs is not null && !strs.Any(s => s.NotEquals(strs.First())); + public static bool AllEqualsIgnoreCase(params string[] strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs[0])); - public static bool EqualsIgnoreCase(this string str1, string str2) => IsNull(str1, str2) || str1.IsNotNull() && str1.IsNotNull() && string.Equals(str1, str2, OrdinalIgnoreCase); + public static bool AnyEqualsIgnoreCase(params string[] strs) => !strs.AllNotEqualsIgnoreCase(); - public static bool EqualsIgnoreCase(params string[] strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs[0])); + public static bool AllEqualsIgnoreCase(this IEnumerable strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs.First())); - public static bool EqualsIgnoreCase(this IEnumerable strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs.First())); + public static bool AnyEqualsIgnoreCase(this IEnumerable strs) => !strs.AllNotEqualsIgnoreCase(); public static bool IsNotNull(this string str) => str is not null; - public static bool IsNotNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNull()); + public static bool AllNotNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNull()); + + public static bool AnyNotNull(params string[] strs) => strs is not null && strs.Any(s => s.IsNotNull()); - public static bool IsNotNull(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNull()); + public static bool AllNotNull(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNull()); + + public static bool AnyNotNull(this IEnumerable strs) => strs is not null && strs.Any(s => s.IsNotNull()); public static bool IsNotNullAndEmpty(this string str) => !string.IsNullOrEmpty(str); - public static bool IsNotNullAndEmpty(params string[] strs) => strs is not null && !strs.Any(s => s.IsNullOrEmpty()); + public static bool AllNotNullAndEmpty(params string[] strs) => strs is not null && !strs.Any(s => s.IsNullOrEmpty()); - public static bool IsNotNullAndEmpty(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNullOrEmpty()); + public static bool AnyNotNullAndEmpty(params string[] strs) => strs is not null && strs.Any(s => s.IsNotNullAndEmpty()); - public static bool IsNotNullAndWhiteSpace(this string str) => !string.IsNullOrWhiteSpace(str); + public static bool AllNotNullAndEmpty(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNullOrEmpty()); - public static bool IsNotNullAndWhiteSpace(params string[] strs) => strs is not null && !strs.Any(s => s.IsNullOrWhiteSpace()); + public static bool AnyNotNullAndEmpty(this IEnumerable strs) => strs is not null && strs.Any(s => s.IsNotNullAndEmpty()); - public static bool IsNotNullAndWhiteSpace(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNullOrWhiteSpace()); + public static bool IsNotNullAndWhiteSpace(this string str) => !string.IsNullOrWhiteSpace(str); - public static bool NotEquals(this string str1, string str2) => str1 != str2; + public static bool AllNotNullAndWhiteSpace(params string[] strs) => strs is not null && !strs.Any(s => s.IsNullOrWhiteSpace()); - public static bool NotEquals(params string[] strs) - { - if (strs is null || strs.Length < 2) - { - return false; - } - var hashSet = new HashSet(strs.Length); - for (var i = 0; i < strs.Length; i++) - { - if (!hashSet.Add(strs[i])) - { - return false; - } - } - return true; - } + public static bool AnyNotNullAndWhiteSpace(params string[] strs) => strs is not null && strs.Any(s => s.IsNotNullAndWhiteSpace()); - public static bool NotEquals(this IEnumerable strs) - { - if (strs is null || strs.Count() < 2) - { - return false; - } - var hashSet = new HashSet(strs.Count()); - foreach (var str in strs) - { - if (!hashSet.Add(str)) - { - return false; - } - } - return true; - } + public static bool AllNotNullAndWhiteSpace(this IEnumerable strs) => strs is not null && !strs.Any(s => s.IsNullOrWhiteSpace()); - public static bool NotEqualsIgnoreCase(this string str1, string str2) => IsNotNull(str1, str2) && !string.Equals(str1, str2, OrdinalIgnoreCase); + public static bool AnyNotNullAndWhiteSpace(this IEnumerable strs) => strs is not null && strs.Any(s => s.IsNotNullAndWhiteSpace()); - public static bool NotEqualsIgnoreCase(params string[] strs) + public static bool NotEqualsIgnoreCase(this string str1, string str2) => AllNotNull(str1, str2) && !string.Equals(str1, str2, OrdinalIgnoreCase); + + public static bool AllNotEqualsIgnoreCase(params string[] strs) { - if (strs is null || strs.Length < 1) + if (strs is null || strs.Length < 2) { return false; } @@ -110,7 +96,9 @@ public static bool NotEqualsIgnoreCase(params string[] strs) return true; } - public static bool NotEqualsIgnoreCase(this IEnumerable strs) + public static bool AnyNotEqualsIgnoreCase(params string[] strs) => !strs.AllEqualsIgnoreCase(); + + public static bool AllNotEqualsIgnoreCase(this IEnumerable strs) { if (strs is null || strs.Count() < 2) { @@ -127,6 +115,8 @@ public static bool NotEqualsIgnoreCase(this IEnumerable strs) return true; } + public static bool AnyNotEqualsIgnoreCase(this IEnumerable strs) => !strs.AllEqualsIgnoreCase(); + public static string GetValue(this string str) => str ?? string.Empty; public static string GetValue(this string str, string dfltVal) => str ?? dfltVal; @@ -137,7 +127,7 @@ public static bool NotEqualsIgnoreCase(this IEnumerable strs) public static IEnumerable ToLower(this IEnumerable strs) { - if (strs is null || !strs.Any()) + if (strs.IsNullOrEmpty()) { yield break; } @@ -147,13 +137,13 @@ public static IEnumerable ToLower(this IEnumerable strs) } } - public static void ToLower(this IList strs) + public static void ToLower(this ICollection strs) { - if (strs is not null && strs.Count > 0) + if (strs.IsNotNullAndEmpty()) { - for (var i = 0; i < strs.Count; i++) + foreach (var str in strs) { - strs[i] = ToLower(strs[i]); + _ = ToLower(str); } } } @@ -162,7 +152,7 @@ public static void ToLower(this IList strs) public static IEnumerable ToLowerInvariant(this IEnumerable strs) { - if (strs is null || !strs.Any()) + if (strs.IsNullOrEmpty()) { yield break; } @@ -174,7 +164,7 @@ public static IEnumerable ToLowerInvariant(this IEnumerable strs public static void ToLowerInvariant(this IList strs) { - if (strs is not null && strs.Count > 0) + if (strs.IsNotNullAndEmpty()) { for (var i = 0; i < strs.Count; i++) { @@ -187,7 +177,7 @@ public static void ToLowerInvariant(this IList strs) public static IEnumerable ToUpper(this IEnumerable strs) { - if (strs is null || !strs.Any()) + if (strs.IsNullOrEmpty()) { yield break; } @@ -199,7 +189,7 @@ public static IEnumerable ToUpper(this IEnumerable strs) public static void ToUpper(this IList strs) { - if (strs is not null && strs.Count > 0) + if (strs.IsNotNullAndEmpty()) { for (var i = 0; i < strs.Count; i++) { @@ -212,7 +202,7 @@ public static void ToUpper(this IList strs) public static IEnumerable ToUpperInvariant(this IEnumerable strs) { - if (strs is null || !strs.Any()) + if (strs.IsNullOrEmpty()) { yield break; } @@ -224,7 +214,7 @@ public static IEnumerable ToUpperInvariant(this IEnumerable strs public static void ToUpperInvariant(this IList strs) { - if (strs is not null && strs.Count > 0) + if (strs.IsNotNullAndEmpty()) { for (var i = 0; i < strs.Count; i++) { diff --git a/lib/YANLib/nuget.config b/lib/YANLib/nuget.config index 4169063b..25709287 100644 --- a/lib/YANLib/nuget.config +++ b/lib/YANLib/nuget.config @@ -7,7 +7,7 @@ - + diff --git a/src/YANLib.Application.Contracts/Dtos/JsonDto.cs b/src/YANLib.Application.Contracts/Dtos/JsonDto.cs new file mode 100644 index 00000000..6b0e780a --- /dev/null +++ b/src/YANLib.Application.Contracts/Dtos/JsonDto.cs @@ -0,0 +1,8 @@ +using System; + +namespace YANLib.Dtos; + +public class JsonDto +{ + public Guid Id { get; set; } +} diff --git a/src/YANLib.Application.Contracts/Dtos/JsonTestDto.cs b/src/YANLib.Application.Contracts/Dtos/JsonTestDto.cs deleted file mode 100644 index 261ba4eb..00000000 --- a/src/YANLib.Application.Contracts/Dtos/JsonTestDto.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace YANLib.Dtos; - -public class JsonTestDto -{ - public Guid Id { get; set; } - public string Name { get; set; } - public uint Income { get; set; } - public bool IsRisk { get; set; } -} diff --git a/src/YANLib.Application.Contracts/Services/IYANJsonService.cs b/src/YANLib.Application.Contracts/Services/IYANJsonService.cs index cd678be7..61d26cb3 100644 --- a/src/YANLib.Application.Contracts/Services/IYANJsonService.cs +++ b/src/YANLib.Application.Contracts/Services/IYANJsonService.cs @@ -1,13 +1,9 @@ -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Threading.Tasks; using Volo.Abp.Application.Services; -using YANLib.Dtos; namespace YANLib.Services; public interface IYANJsonService : IApplicationService { - public ValueTask Serializes(List requests); - public ValueTask CamelSerializes(List requests); - public ValueTask> Deserializes(byte quantity); + public ValueTask DuoVsStandard(uint quantity); } diff --git a/src/YANLib.Application/Services/YANJsonService.cs b/src/YANLib.Application/Services/YANJsonService.cs index e5214126..bfbbf5de 100644 --- a/src/YANLib.Application/Services/YANJsonService.cs +++ b/src/YANLib.Application/Services/YANJsonService.cs @@ -1,56 +1,42 @@ -using System.Collections.Generic; -using System.Linq; +using System.Diagnostics; using System.Threading.Tasks; using YANLib.Dtos; using static System.Guid; -using static System.Threading.Tasks.ValueTask; -using static YANLib.YANBool; -using static YANLib.YANNum; -using static YANLib.YANText; +using static System.Threading.Tasks.Task; namespace YANLib.Services; public class YANJsonService : YANLibAppService, IYANJsonService { - // Serialize - public async ValueTask Serializes(List requests) => await FromResult(requests.Serialize()); - - // Serialize camel case - public async ValueTask CamelSerializes(List requests) => await FromResult(requests.SerializeCamel()); - - // Deserialize - public async ValueTask> Deserializes(byte quantity) => quantity == 0 ? default : await FromResult(ModData(quantity).Clean().ToList()); - - // Generate data - private static IEnumerable GenData(byte quantity) + public async ValueTask DuoVsStandard(uint quantity) { - for (var i = 0; i < quantity; i++) + var json = new JsonDto { - yield return i % 2 == 0 - ? new JsonTestDto - { - Id = NewGuid(), - Name = $"nguyễn văn {GenerateRandomCharacter()}".ToTitle(), - Income = GenerateRandomUshort(), - IsRisk = GenerateRandomBool() - }.SerializeCamel() - : new JsonTestDto - { - Id = NewGuid(), - Name = $"đoàn thị {GenerateRandomCharacter()}".ToTitle(), - Income = GenerateRandomUshort(), - IsRisk = GenerateRandomBool() - }.Serialize(); - } - } - - // Modified data - private static IEnumerable ModData(byte quantity) - { - foreach (var dto in GenData(quantity).DeserializeDuo()) + Id = NewGuid() + }.Serialize(); + var duoTask = Run(() => + { + var sw = new Stopwatch(); + sw.Start(); + for (var i = 0; i < quantity; i++) + { + _ = json.DeserializeDuo(); + } + sw.Stop(); + return sw.Elapsed.TotalMilliseconds; + }); + var stdTask = Run(() => { - dto.Income *= 1000; - yield return dto; - } + var sw = new Stopwatch(); + sw.Start(); + for (var i = 0; i < quantity; i++) + { + _ = json.DeserializeStandard(); + } + sw.Stop(); + return sw.Elapsed.TotalMilliseconds; + }); + _ = await WhenAll(duoTask, stdTask); + return $"Standard: {stdTask.Result}\nDuo: {duoTask.Result}"; } } diff --git a/src/YANLib.HttpApi/Controllers/YANJsonController.cs b/src/YANLib.HttpApi/Controllers/YANJsonController.cs index d8474d3c..d9d3024b 100644 --- a/src/YANLib.HttpApi/Controllers/YANJsonController.cs +++ b/src/YANLib.HttpApi/Controllers/YANJsonController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; using System.Collections.Generic; using System.Threading.Tasks; using YANLib.Dtos; @@ -6,25 +7,77 @@ namespace YANLib.Controllers; +[ApiExplorerSettings(GroupName = "json")] [Route("api/tynab/yanlib/yanjson")] public class YANJsonController : YANLibController { #region Fields - private readonly IYANJsonService _yanJsonService; + private readonly IYANJsonService _service; #endregion #region Constructors - public YANJsonController(IYANJsonService yanJsonService) => _yanJsonService = yanJsonService; + public YANJsonController(IYANJsonService service) => _service = service; #endregion #region Methods + [HttpGet("duo-vs-standard")] + [SwaggerOperation(Summary = "Deserialize speed test (Duo vs Standard)")] + public async ValueTask DuoVsStandard(uint quantity = 10000) => Ok(await _service.DuoVsStandard(quantity)); + + [HttpPost("serialize")] + [SwaggerOperation(Summary = "Serialize n-1 Pascal case")] + public IActionResult Serialize([FromBody] List request) => Ok(request.Serialize()); + + [HttpPost("camel-serialize")] + [SwaggerOperation(Summary = "Serialize n-1 Camel case")] + public IActionResult SerializeCamel([FromBody] List request) => Ok(request.SerializeCamel()); + + [HttpGet("deserialize")] + [SwaggerOperation(Summary = "Deserialize 1-1 Pascal case")] + public IActionResult Deserializes(string text) => Ok(text.Deserialize()); + + [HttpGet("camel-deserialize")] + [SwaggerOperation(Summary = "Deserialize 1-1 Camel case")] + public IActionResult DeserializeCamel(string text) => Ok(text.DeserializeCamel()); + + [HttpGet("standard-deserialize")] + [SwaggerOperation(Summary = "Deserialize 1-1 ignore case")] + public IActionResult DeserializeStandard(string text) => Ok(text.DeserializeStandard()); + + [HttpGet("duo-deserialize")] + [SwaggerOperation(Summary = "Deserialize 1-1 ignore case (Pascal priority)")] + public IActionResult DeserializeDuo(string text) => Ok(text.DeserializeDuo()); + + [HttpGet("duo-camel-priority-deserialize")] + [SwaggerOperation(Summary = "Deserialize 1-1 ignore case (Camel priority)")] + public IActionResult DeserializeDuoCamelPriority(string text) => Ok(text.DeserializeDuoCamelPriority()); + [HttpPost("serializes")] - public async ValueTask Serialize([FromBody] List request) => Ok(await _yanJsonService.Serializes(request)); + [SwaggerOperation(Summary = "Serialize n-n Pascal case")] + public IActionResult Serializes([FromBody] List request) => Ok(request.Serializes()); [HttpPost("camel-serializes")] - public async ValueTask SerializeCamel([FromBody] List request) => Ok(await _yanJsonService.CamelSerializes(request)); + [SwaggerOperation(Summary = "Serialize n-n Camel case")] + public IActionResult SerializeCamels([FromBody] List request) => Ok(request.SerializeCamels()); + + [HttpPost("deserializes")] + [SwaggerOperation(Summary = "Deserialize n-n Pascal case")] + public IActionResult Deserializes([FromBody] List text) => Ok(text.Deserializes()); + + [HttpPost("camel-deserializes")] + [SwaggerOperation(Summary = "Deserialize n-n Camel case")] + public IActionResult DeserializeCamels([FromBody] List text) => Ok(text.DeserializeCamels()); + + [HttpPost("standard-deserializes")] + [SwaggerOperation(Summary = "Deserialize n-n ignore case")] + public IActionResult DeserializeStandards([FromBody] List text) => Ok(text.DeserializeStandards()); + + [HttpPost("duo-deserializes")] + [SwaggerOperation(Summary = "Deserialize n-n ignore case (Pascal priority)")] + public IActionResult DeserializeDuos([FromBody] List text) => Ok(text.DeserializeDuos()); - [HttpGet("deserializes")] - public async ValueTask Deserialize(byte quantity = 1) => Ok(await _yanJsonService.Deserializes(quantity)); + [HttpPost("duo-camel-priority-deserializes")] + [SwaggerOperation(Summary = "Deserialize n-n ignore case (Camel priority)")] + public IActionResult DeserializeDuoCamelPriorities([FromBody] List text) => Ok(text.DeserializeDuoCamelPriorities()); #endregion } diff --git a/src/YANLib.HttpApi/YANLib.HttpApi.csproj b/src/YANLib.HttpApi/YANLib.HttpApi.csproj index f31be28e..c9ee0a13 100644 --- a/src/YANLib.HttpApi/YANLib.HttpApi.csproj +++ b/src/YANLib.HttpApi/YANLib.HttpApi.csproj @@ -8,10 +8,12 @@ + +