diff --git a/Directory.Build.props b/Directory.Build.props
index 62138898..e685ba38 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -43,10 +43,10 @@
-
+
-
+
\ No newline at end of file
diff --git a/docs/CodeDoc/Atc/Atc.Helpers.md b/docs/CodeDoc/Atc/Atc.Helpers.md
index 106f9d9b..9c997452 100644
--- a/docs/CodeDoc/Atc/Atc.Helpers.md
+++ b/docs/CodeDoc/Atc/Atc.Helpers.md
@@ -690,6 +690,21 @@ DateTimeHelper.
>
>Returns: `true` if the parsing was successful; otherwise, `false`.
+#### TryParseShortDateUsingSpecificCulture
+>```csharp
+>bool TryParseShortDateUsingSpecificCulture(string value, CultureInfo cultureInfo, out DateTime result)
+>```
+>Summary: Tries to parse a string representation of a short date using a specific culture's date format.
+>
+>Parameters:
+> `value` - The string to parse.
+> `cultureInfo` - The culture info to use for parsing.
+> `result` -
+ When this method returns, contains the parsed DateTime,
+ if the parse operation was successful; otherwise, contains the default DateTime.
+
+>
+>Returns: `true` if the parsing was successful; otherwise, `false`.
#### TryParseShortTimeUsingCurrentUiCulture
>```csharp
>bool TryParseShortTimeUsingCurrentUiCulture(string value, out DateTime result)
@@ -718,6 +733,36 @@ DateTimeHelper.
>
>Returns: `true` if the parsing was successful; otherwise, `false`.
+#### TryParseShortTimeUsingSpecificCulture
+>```csharp
+>bool TryParseShortTimeUsingSpecificCulture(string value, CultureInfo cultureInfo, out DateTime result)
+>```
+>Summary: Tries to parse a string representation of a short time using a specific culture's time format (12-hour or 24-hour).
+>
+>Parameters:
+> `value` - The string to parse.
+> `cultureInfo` - The culture info to use for parsing.
+> `result` -
+ When this method returns, contains the parsed DateTime,
+ if the parse operation was successful; otherwise, contains the default DateTime.
+
+>
+>Returns: `true` if the parsing was successful; otherwise, `false`.
+#### TryParseShortTimeUsingSpecificCultureUtc
+>```csharp
+>bool TryParseShortTimeUsingSpecificCultureUtc(string value, CultureInfo cultureInfo, out DateTime result)
+>```
+>Summary: Tries to parse a string representation of a short UTC time using a specific culture's time format (12-hour or 24-hour).
+>
+>Parameters:
+> `value` - The string to parse.
+> `cultureInfo` - The culture info to use for parsing.
+> `result` -
+ When this method returns, contains the parsed DateTime in UTC,
+ if the parse operation was successful; otherwise, contains the default DateTime.
+
+>
+>Returns: `true` if the parsing was successful; otherwise, `false`.
#### TryParseUsingCurrentUiCulture
>```csharp
>bool TryParseUsingCurrentUiCulture(string value, out DateTime result)
@@ -732,6 +777,21 @@ DateTimeHelper.
>
>Returns: `true` if the parsing was successful; otherwise, `false`.
+#### TryParseUsingSpecificCulture
+>```csharp
+>bool TryParseUsingSpecificCulture(string value, CultureInfo cultureInfo, out DateTime result)
+>```
+>Summary: Tries to parse a string representation of a DateTime using a specific culture's date and time format.
+>
+>Parameters:
+> `value` - The string to parse.
+> `cultureInfo` - The culture info to use for parsing.
+> `result` -
+ When this method returns, contains the parsed DateTime,
+ if the parse operation was successful; otherwise, contains the default DateTime.
+
+>
+>Returns: `true` if the parsing was successful; otherwise, `false`.
@@ -2002,16 +2062,80 @@ Provides utility methods for working with stack traces.
### Static Methods
-#### ContainsConstructorWithinFrameCount
+#### ContainsConstructor
+>```csharp
+>bool ContainsConstructor()
+>```
+>Summary: Checks if the current stack trace contains a constructor call.
+>
+>Returns: True if a constructor call is found; otherwise, false.
+#### ContainsConstructor
+>```csharp
+>bool ContainsConstructor(int drillDownFrameMax)
+>```
+>Summary: Checks if the current stack trace contains a constructor call.
+>
+>Returns: True if a constructor call is found; otherwise, false.
+#### ContainsPropertyGetterName
+>```csharp
+>bool ContainsPropertyGetterName(string propertyName)
+>```
+>Summary: Checks if the current stack trace contains a property getter call for a specified property name.
+>
+>Parameters:
+> `propertyName` - The name of the property to check.
+>
+>Returns: True if a getter call is found for the specified property; otherwise, false.
+#### ContainsPropertyGetterName
+>```csharp
+>bool ContainsPropertyGetterName(string propertyName, int drillDownFrameMax)
+>```
+>Summary: Checks if the current stack trace contains a property getter call for a specified property name.
+>
+>Parameters:
+> `propertyName` - The name of the property to check.
+>
+>Returns: True if a getter call is found for the specified property; otherwise, false.
+#### ContainsPropertyName
+>```csharp
+>bool ContainsPropertyName(string propertyName)
+>```
+>Summary: Checks if the current stack trace contains a property call for a specified property name.
+>
+>Parameters:
+> `propertyName` - The name of the property to check.
+>
+>Returns: True if a call is found for the specified property; otherwise, false.
+#### ContainsPropertyName
+>```csharp
+>bool ContainsPropertyName(string propertyName, int drillDownFrameMax)
+>```
+>Summary: Checks if the current stack trace contains a property call for a specified property name.
+>
+>Parameters:
+> `propertyName` - The name of the property to check.
+>
+>Returns: True if a call is found for the specified property; otherwise, false.
+#### ContainsPropertySetterName
+>```csharp
+>bool ContainsPropertySetterName(string propertyName)
+>```
+>Summary: Checks if the current stack trace contains a property setter call for a specified property name.
+>
+>Parameters:
+> `propertyName` - The name of the property to check.
+>
+>Returns: True if a setter call is found for the specified property; otherwise, false.
+#### ContainsPropertySetterName
>```csharp
->bool ContainsConstructorWithinFrameCount(int drillDownFrameMax)
+>bool ContainsPropertySetterName(string propertyName, int drillDownFrameMax)
>```
->Summary: Determines whether any of the stack frames within the specified frame count contains a constructor.
+>Summary: Checks if the current stack trace contains a property setter call for a specified property name.
>
>Parameters:
-> `drillDownFrameMax` - The maximum number of frames to inspect in the stack trace.
+> `propertyName` - The name of the property to check.
>
->Returns: `true` if a constructor is found within the specified number of frames; otherwise, `false`.
+>Returns: True if a setter call is found for the specified property; otherwise, false.
diff --git a/docs/CodeDoc/Atc/IndexExtended.md b/docs/CodeDoc/Atc/IndexExtended.md
index 0e0fd6e3..86c2f2c8 100644
--- a/docs/CodeDoc/Atc/IndexExtended.md
+++ b/docs/CodeDoc/Atc/IndexExtended.md
@@ -4484,9 +4484,13 @@
- [DateTimeHelper](Atc.Helpers.md#datetimehelper)
- Static Methods
- TryParseShortDateUsingCurrentUiCulture(string value, out DateTime result)
+ - TryParseShortDateUsingSpecificCulture(string value, CultureInfo cultureInfo, out DateTime result)
- TryParseShortTimeUsingCurrentUiCulture(string value, out DateTime result)
- TryParseShortTimeUsingCurrentUiCultureUtc(string value, out DateTime result)
+ - TryParseShortTimeUsingSpecificCulture(string value, CultureInfo cultureInfo, out DateTime result)
+ - TryParseShortTimeUsingSpecificCultureUtc(string value, CultureInfo cultureInfo, out DateTime result)
- TryParseUsingCurrentUiCulture(string value, out DateTime result)
+ - TryParseUsingSpecificCulture(string value, CultureInfo cultureInfo, out DateTime result)
- [DateTimeOffsetHelper](Atc.Helpers.md#datetimeoffsethelper)
- Static Methods
- TryParseShortDateUsingCurrentUiCulture(string value, out DateTime result)
@@ -4678,7 +4682,14 @@
- IsSimpleType(string value, StringComparison comparison = Ordinal)
- [StackTraceHelper](Atc.Helpers.md#stacktracehelper)
- Static Methods
- - ContainsConstructorWithinFrameCount(int drillDownFrameMax)
+ - ContainsConstructor()
+ - ContainsConstructor(int drillDownFrameMax)
+ - ContainsPropertyGetterName(string propertyName)
+ - ContainsPropertyGetterName(string propertyName, int drillDownFrameMax)
+ - ContainsPropertyName(string propertyName)
+ - ContainsPropertyName(string propertyName, int drillDownFrameMax)
+ - ContainsPropertySetterName(string propertyName)
+ - ContainsPropertySetterName(string propertyName, int drillDownFrameMax)
- [TaskHelper](Atc.Helpers.md#taskhelper)
- Static Methods
- Execute(Func<CancellationToken, Task<TResult>> taskToRun, TimeSpan timeout, CancellationToken cancellationToken = null)
@@ -4986,12 +4997,16 @@
- ToIso8601UtcDate(this DateTime dateTime)
- ToLongDateString(this DateTime dateTime, DateTimeFormatInfo dateTimeFormatInfo)
- ToLongDateStringUsingCurrentUiCulture(this DateTime dateTime)
+ - ToLongDateStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
- ToLongTimeString(this DateTime dateTime, DateTimeFormatInfo dateTimeFormatInfo)
- ToLongTimeStringUsingCurrentUiCulture(this DateTime dateTime)
+ - ToLongTimeStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
- ToShortDateString(this DateTime dateTime, DateTimeFormatInfo dateTimeFormatInfo)
- ToShortDateStringUsingCurrentUiCulture(this DateTime dateTime)
+ - ToShortDateStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
- ToShortTimeString(this DateTime dateTime, DateTimeFormatInfo dateTimeFormatInfo)
- ToShortTimeStringUsingCurrentUiCulture(this DateTime dateTime)
+ - ToShortTimeStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
- [DateTimeOffsetExtensions](System.md#datetimeoffsetextensions)
- Static Methods
- DateTimeDiff(this DateTimeOffset startDate, DateTimeOffset endDate, DateTimeDiffCompareType howToCompare)
diff --git a/docs/CodeDoc/Atc/System.md b/docs/CodeDoc/Atc/System.md
index c50ade2c..f94772a6 100644
--- a/docs/CodeDoc/Atc/System.md
+++ b/docs/CodeDoc/Atc/System.md
@@ -520,6 +520,10 @@ Extensions for the `System.DateTime` class.
> `dateTime` - The DateTime to format.
>
>Returns: A string representation of the DateTime using the long date pattern of the current UI culture.
+#### ToLongDateStringUsingSpecificCulture
+>```csharp
+>string ToLongDateStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
+>```
#### ToLongTimeString
>```csharp
>string ToLongTimeString(this DateTime dateTime, DateTimeFormatInfo dateTimeFormatInfo)
@@ -541,6 +545,10 @@ Extensions for the `System.DateTime` class.
> `dateTime` - The DateTime to format.
>
>Returns: A string representation of the DateTime using the long time pattern of the current UI culture.
+#### ToLongTimeStringUsingSpecificCulture
+>```csharp
+>string ToLongTimeStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
+>```
#### ToShortDateString
>```csharp
>string ToShortDateString(this DateTime dateTime, DateTimeFormatInfo dateTimeFormatInfo)
@@ -562,6 +570,10 @@ Extensions for the `System.DateTime` class.
> `dateTime` - The DateTime to format.
>
>Returns: A string representation of the DateTime using the short date pattern of the current UI culture.
+#### ToShortDateStringUsingSpecificCulture
+>```csharp
+>string ToShortDateStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
+>```
#### ToShortTimeString
>```csharp
>string ToShortTimeString(this DateTime dateTime, DateTimeFormatInfo dateTimeFormatInfo)
@@ -583,6 +595,10 @@ Extensions for the `System.DateTime` class.
> `dateTime` - The DateTime to format.
>
>Returns: A string representation of the DateTime using the short time pattern of the current UI culture.
+#### ToShortTimeStringUsingSpecificCulture
+>```csharp
+>string ToShortTimeStringUsingSpecificCulture(this DateTime dateTime, CultureInfo cultureInfo)
+>```
diff --git a/sample/Demo.Atc.Console.Spectre.Cli/Demo.Atc.Console.Spectre.Cli.csproj b/sample/Demo.Atc.Console.Spectre.Cli/Demo.Atc.Console.Spectre.Cli.csproj
index 53bc2a56..88f0c641 100644
--- a/sample/Demo.Atc.Console.Spectre.Cli/Demo.Atc.Console.Spectre.Cli.csproj
+++ b/sample/Demo.Atc.Console.Spectre.Cli/Demo.Atc.Console.Spectre.Cli.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/sample/Demo.Atc.Dotnet.Cli/Demo.Atc.Dotnet.Cli.csproj b/sample/Demo.Atc.Dotnet.Cli/Demo.Atc.Dotnet.Cli.csproj
index 59b94ba1..581ee4e3 100644
--- a/sample/Demo.Atc.Dotnet.Cli/Demo.Atc.Dotnet.Cli.csproj
+++ b/sample/Demo.Atc.Dotnet.Cli/Demo.Atc.Dotnet.Cli.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/Atc.OpenApi/Atc.OpenApi.csproj b/src/Atc.OpenApi/Atc.OpenApi.csproj
index 9f8130e8..7f6f3897 100644
--- a/src/Atc.OpenApi/Atc.OpenApi.csproj
+++ b/src/Atc.OpenApi/Atc.OpenApi.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/src/Atc.Rest.Extended/Atc.Rest.Extended.csproj b/src/Atc.Rest.Extended/Atc.Rest.Extended.csproj
index 607c2816..143cbd88 100644
--- a/src/Atc.Rest.Extended/Atc.Rest.Extended.csproj
+++ b/src/Atc.Rest.Extended/Atc.Rest.Extended.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/Atc.Rest/Atc.Rest.csproj b/src/Atc.Rest/Atc.Rest.csproj
index c2571963..5258c6c0 100644
--- a/src/Atc.Rest/Atc.Rest.csproj
+++ b/src/Atc.Rest/Atc.Rest.csproj
@@ -12,7 +12,7 @@
-
+
diff --git a/src/Atc.XUnit/Atc.XUnit.csproj b/src/Atc.XUnit/Atc.XUnit.csproj
index c7c62081..c4289ff1 100644
--- a/src/Atc.XUnit/Atc.XUnit.csproj
+++ b/src/Atc.XUnit/Atc.XUnit.csproj
@@ -12,12 +12,12 @@
-
+
NU1701
-
+
diff --git a/src/Atc/Atc.csproj b/src/Atc/Atc.csproj
index 5bd27062..e04e131a 100644
--- a/src/Atc/Atc.csproj
+++ b/src/Atc/Atc.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/src/Atc/Extensions/BaseTypes/DateTimeExtensions.cs b/src/Atc/Extensions/BaseTypes/DateTimeExtensions.cs
index cab866f1..faf3d0ff 100644
--- a/src/Atc/Extensions/BaseTypes/DateTimeExtensions.cs
+++ b/src/Atc/Extensions/BaseTypes/DateTimeExtensions.cs
@@ -118,6 +118,18 @@ public static string ToLongDateStringUsingCurrentUiCulture(
this DateTime dateTime)
=> dateTime.ToLongDateString(Thread.CurrentThread.CurrentUICulture.DateTimeFormat);
+ public static string ToLongDateStringUsingSpecificCulture(
+ this DateTime dateTime,
+ CultureInfo cultureInfo)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
+ return dateTime.ToLongDateString(cultureInfo.DateTimeFormat);
+ }
+
///
/// Converts a DateTime to a string using the long date pattern of the provided DateTimeFormatInfo.
///
@@ -152,6 +164,18 @@ public static string ToLongTimeStringUsingCurrentUiCulture(
this DateTime dateTime)
=> dateTime.ToLongTimeString(Thread.CurrentThread.CurrentUICulture.DateTimeFormat);
+ public static string ToLongTimeStringUsingSpecificCulture(
+ this DateTime dateTime,
+ CultureInfo cultureInfo)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
+ return dateTime.ToLongTimeString(cultureInfo.DateTimeFormat);
+ }
+
///
/// Converts a DateTime to a string using the long time pattern of the provided DateTimeFormatInfo.
///
@@ -185,6 +209,18 @@ public static string ToShortDateStringUsingCurrentUiCulture(
this DateTime dateTime)
=> dateTime.ToShortDateString(Thread.CurrentThread.CurrentUICulture.DateTimeFormat);
+ public static string ToShortDateStringUsingSpecificCulture(
+ this DateTime dateTime,
+ CultureInfo cultureInfo)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
+ return dateTime.ToShortDateString(cultureInfo.DateTimeFormat);
+ }
+
///
/// Converts a DateTime to a string using the short date pattern of the provided DateTimeFormatInfo.
///
@@ -218,6 +254,18 @@ public static string ToShortTimeStringUsingCurrentUiCulture(
this DateTime dateTime)
=> dateTime.ToShortTimeString(Thread.CurrentThread.CurrentUICulture.DateTimeFormat);
+ public static string ToShortTimeStringUsingSpecificCulture(
+ this DateTime dateTime,
+ CultureInfo cultureInfo)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
+ return dateTime.ToShortTimeString(cultureInfo.DateTimeFormat);
+ }
+
///
/// Converts a DateTime to a string using the short time pattern of the provided DateTimeFormatInfo.
///
diff --git a/src/Atc/Helpers/DateTimeHelper.cs b/src/Atc/Helpers/DateTimeHelper.cs
index 6eeb9647..3ffdd36e 100644
--- a/src/Atc/Helpers/DateTimeHelper.cs
+++ b/src/Atc/Helpers/DateTimeHelper.cs
@@ -25,6 +25,38 @@ public static bool TryParseUsingCurrentUiCulture(
string value,
out DateTime result)
{
+ result = default;
+ if (!TryParseUsingSpecificCulture(value, Thread.CurrentThread.CurrentUICulture, out var res))
+ {
+ return false;
+ }
+
+ result = res;
+ return true;
+ }
+
+ ///
+ /// Tries to parse a string representation of a DateTime using a specific culture's date and time format.
+ ///
+ /// The string to parse.
+ /// The culture info to use for parsing.
+ ///
+ /// When this method returns, contains the parsed DateTime,
+ /// if the parse operation was successful; otherwise, contains the default DateTime.
+ ///
+ ///
+ /// true if the parsing was successful; otherwise, false.
+ ///
+ public static bool TryParseUsingSpecificCulture(
+ string value,
+ CultureInfo cultureInfo,
+ out DateTime result)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
result = default;
if (string.IsNullOrWhiteSpace(value) ||
value.Length < DateLength)
@@ -34,7 +66,7 @@ public static bool TryParseUsingCurrentUiCulture(
if (!DateTime.TryParse(
value,
- Thread.CurrentThread.CurrentUICulture.DateTimeFormat,
+ cultureInfo.DateTimeFormat,
DateTimeStyles.None,
out var res))
{
@@ -61,6 +93,38 @@ public static bool TryParseShortDateUsingCurrentUiCulture(
string value,
out DateTime result)
{
+ result = default;
+ if (!TryParseShortDateUsingSpecificCulture(value, Thread.CurrentThread.CurrentUICulture, out var res))
+ {
+ return false;
+ }
+
+ result = res;
+ return true;
+ }
+
+ ///
+ /// Tries to parse a string representation of a short date using a specific culture's date format.
+ ///
+ /// The string to parse.
+ /// The culture info to use for parsing.
+ ///
+ /// When this method returns, contains the parsed DateTime,
+ /// if the parse operation was successful; otherwise, contains the default DateTime.
+ ///
+ ///
+ /// true if the parsing was successful; otherwise, false.
+ ///
+ public static bool TryParseShortDateUsingSpecificCulture(
+ string value,
+ CultureInfo cultureInfo,
+ out DateTime result)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
result = default;
if (string.IsNullOrWhiteSpace(value) ||
value.Length > DateLength)
@@ -70,7 +134,7 @@ public static bool TryParseShortDateUsingCurrentUiCulture(
if (!DateTime.TryParse(
value,
- Thread.CurrentThread.CurrentUICulture.DateTimeFormat,
+ cultureInfo.DateTimeFormat,
DateTimeStyles.None,
out var res))
{
@@ -97,10 +161,42 @@ public static bool TryParseShortTimeUsingCurrentUiCulture(
string value,
out DateTime result)
{
+ result = default;
+ if (!TryParseShortTimeUsingSpecificCulture(value, Thread.CurrentThread.CurrentUICulture, out var res))
+ {
+ return false;
+ }
+
+ result = res;
+ return true;
+ }
+
+ ///
+ /// Tries to parse a string representation of a short time using a specific culture's time format (12-hour or 24-hour).
+ ///
+ /// The string to parse.
+ /// The culture info to use for parsing.
+ ///
+ /// When this method returns, contains the parsed DateTime,
+ /// if the parse operation was successful; otherwise, contains the default DateTime.
+ ///
+ ///
+ /// true if the parsing was successful; otherwise, false.
+ ///
+ public static bool TryParseShortTimeUsingSpecificCulture(
+ string value,
+ CultureInfo cultureInfo,
+ out DateTime result)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
result = default;
- var use24Hours = !(Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern.StartsWith("h:", StringComparison.Ordinal) ||
- Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern.StartsWith("h.", StringComparison.Ordinal));
+ var use24Hours = !(cultureInfo.DateTimeFormat.ShortTimePattern.StartsWith("h:", StringComparison.Ordinal) ||
+ cultureInfo.DateTimeFormat.ShortTimePattern.StartsWith("h.", StringComparison.Ordinal));
var maxLength = use24Hours ? MaxTimeLengthFor24Hours : MaxTimeLengthFor12Hours;
@@ -110,10 +206,10 @@ public static bool TryParseShortTimeUsingCurrentUiCulture(
return false;
}
- var dateTimeValue = $"{DateTime.Now.ToShortDateStringUsingCurrentUiCulture()} {value}";
+ var dateTimeValue = $"{DateTime.Now.ToShortDateStringUsingSpecificCulture(cultureInfo)} {value}";
if (!DateTime.TryParse(
dateTimeValue,
- Thread.CurrentThread.CurrentUICulture.DateTimeFormat,
+ cultureInfo.DateTimeFormat,
DateTimeStyles.None,
out var res))
{
@@ -140,10 +236,42 @@ public static bool TryParseShortTimeUsingCurrentUiCultureUtc(
string value,
out DateTime result)
{
+ result = default;
+ if (!TryParseShortTimeUsingSpecificCultureUtc(value, Thread.CurrentThread.CurrentUICulture, out var res))
+ {
+ return false;
+ }
+
+ result = res;
+ return true;
+ }
+
+ ///
+ /// Tries to parse a string representation of a short UTC time using a specific culture's time format (12-hour or 24-hour).
+ ///
+ /// The string to parse.
+ /// The culture info to use for parsing.
+ ///
+ /// When this method returns, contains the parsed DateTime in UTC,
+ /// if the parse operation was successful; otherwise, contains the default DateTime.
+ ///
+ ///
+ /// true if the parsing was successful; otherwise, false.
+ ///
+ public static bool TryParseShortTimeUsingSpecificCultureUtc(
+ string value,
+ CultureInfo cultureInfo,
+ out DateTime result)
+ {
+ if (cultureInfo is null)
+ {
+ throw new ArgumentNullException(nameof(cultureInfo));
+ }
+
result = default;
- var use24Hours = !(Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern.StartsWith("h:", StringComparison.Ordinal) ||
- Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern.StartsWith("h.", StringComparison.Ordinal));
+ var use24Hours = !(cultureInfo.DateTimeFormat.ShortTimePattern.StartsWith("h:", StringComparison.Ordinal) ||
+ cultureInfo.DateTimeFormat.ShortTimePattern.StartsWith("h.", StringComparison.Ordinal));
var maxLength = use24Hours ? MaxTimeLengthFor24Hours : MaxTimeLengthFor12Hours;
@@ -153,10 +281,10 @@ public static bool TryParseShortTimeUsingCurrentUiCultureUtc(
return false;
}
- var dateTimeValue = $"{DateTime.UtcNow.ToShortDateStringUsingCurrentUiCulture()} {value}";
+ var dateTimeValue = $"{DateTime.UtcNow.ToShortDateStringUsingSpecificCulture(cultureInfo)} {value}";
if (!DateTime.TryParse(
dateTimeValue,
- Thread.CurrentThread.CurrentUICulture.DateTimeFormat,
+ cultureInfo.DateTimeFormat,
DateTimeStyles.None,
out var res))
{
diff --git a/src/Atc/Helpers/StackTraceHelper.cs b/src/Atc/Helpers/StackTraceHelper.cs
index 3f89728f..bf38adcc 100644
--- a/src/Atc/Helpers/StackTraceHelper.cs
+++ b/src/Atc/Helpers/StackTraceHelper.cs
@@ -5,33 +5,137 @@ namespace Atc.Helpers;
///
public static class StackTraceHelper
{
+ private const int DrillDownFrameDefaultMax = 250;
+ private const int DrillDownFrameDefault = 25;
+
+ ///
+ /// Checks if the current stack trace contains a constructor call.
+ ///
+ /// True if a constructor call is found; otherwise, false.
+ public static bool ContainsConstructor()
+ => ContainsConstructor(DrillDownFrameDefault);
+
+ ///
+ /// Checks if the current stack trace contains a constructor call.
+ ///
+ /// The maximum number of frames to inspect.
+ /// True if a constructor call is found within the specified frames; otherwise, false.
+ public static bool ContainsConstructor(
+ int drillDownFrameMax)
+ => ContainsNameWithinFrameCount(
+ ".ctor",
+ drillDownFrameMax);
+
+ ///
+ /// Checks if the current stack trace contains a property call for a specified property name.
+ ///
+ /// The name of the property to check.
+ /// True if a call is found for the specified property; otherwise, false.
+ public static bool ContainsPropertyName(
+ string propertyName)
+ => ContainsPropertyName(
+ propertyName,
+ DrillDownFrameDefault);
+
///
- /// Determines whether any of the stack frames within the specified frame count contains a constructor.
+ /// Checks if the current stack trace contains a property call for a specified property name within a specified number of frames.
///
- /// The maximum number of frames to inspect in the stack trace.
- ///
- /// true if a constructor is found within the specified number of frames; otherwise, false.
- ///
- public static bool ContainsConstructorWithinFrameCount(
+ /// The name of the property to check.
+ /// The maximum number of frames to inspect.
+ /// True if a call is found for the specified property within the specified frames; otherwise, false.
+ public static bool ContainsPropertyName(
+ string propertyName,
int drillDownFrameMax)
{
- var stackFrames = new StackTrace().GetFrames();
+ if (propertyName is null)
+ {
+ throw new ArgumentNullException(nameof(propertyName));
+ }
+
+ return ContainsNameWithinFrameCount(
+ propertyName,
+ drillDownFrameMax);
+ }
+
+ ///
+ /// Checks if the current stack trace contains a property getter call for a specified property name.
+ ///
+ /// The name of the property to check.
+ /// True if a getter call is found for the specified property; otherwise, false.
+ public static bool ContainsPropertyGetterName(
+ string propertyName)
+ => ContainsPropertyGetterName(
+ propertyName,
+ DrillDownFrameDefault);
+
+ ///
+ /// Checks if the current stack trace contains a property getter call for a specified property name within a specified number of frames.
+ ///
+ /// The name of the property to check.
+ /// The maximum number of frames to inspect.
+ /// True if a getter call is found for the specified property within the specified frames; otherwise, false.
+ public static bool ContainsPropertyGetterName(
+ string propertyName,
+ int drillDownFrameMax)
+ => ContainsNameWithinFrameCount(
+ $"get_{propertyName}",
+ drillDownFrameMax);
+
+ ///
+ /// Checks if the current stack trace contains a property setter call for a specified property name.
+ ///
+ /// The name of the property to check.
+ /// True if a setter call is found for the specified property; otherwise, false.
+ public static bool ContainsPropertySetterName(
+ string propertyName)
+ => ContainsPropertySetterName(
+ propertyName,
+ DrillDownFrameDefault);
+
+ ///
+ /// Checks if the current stack trace contains a property setter call for a specified property name within a specified number of frames.
+ ///
+ /// The name of the property to check.
+ /// The maximum number of frames to inspect.
+ /// True if a setter call is found for the specified property within the specified frames; otherwise, false.
+ public static bool ContainsPropertySetterName(
+ string propertyName,
+ int drillDownFrameMax)
+ => ContainsNameWithinFrameCount(
+ $"set_{propertyName}",
+ drillDownFrameMax);
+
+ ///
+ /// Checks if the current stack trace contains a method with a specified name within a specified number of frames.
+ ///
+ /// The name of the method to check.
+ /// The maximum number of frames to inspect.
+ /// True if the method is found within the specified frames; otherwise, false.
+ private static bool ContainsNameWithinFrameCount(
+ string name,
+ int drillDownFrameMax)
+ {
+ var stackFrames = new StackTrace()
+ .GetFrames()?
+ .Take(DrillDownFrameDefaultMax)
+ .ToArray();
+
if (stackFrames is null)
{
return false;
}
- var stackFrameLengthMax = stackFrames.Length;
- if (stackFrameLengthMax > drillDownFrameMax)
+ var stackFrameDepthMax = stackFrames.Length;
+ if (stackFrameDepthMax > drillDownFrameMax)
{
- stackFrameLengthMax = drillDownFrameMax;
+ stackFrameDepthMax = drillDownFrameMax;
}
- for (var i = 0; i < stackFrameLengthMax; i++)
+ for (var i = 0; i < stackFrameDepthMax; i++)
{
- var methodBase = stackFrames[i].GetMethod();
- if (methodBase is not null &&
- ".ctor".Equals(methodBase.Name, StringComparison.Ordinal))
+ var methodName = stackFrames[i].GetMethod()?.Name;
+ if (methodName is not null &&
+ name.Equals(methodName, StringComparison.Ordinal))
{
return true;
}
diff --git a/test/Atc.CodeAnalysis.CSharp.Tests/Atc.CodeAnalysis.CSharp.Tests.csproj b/test/Atc.CodeAnalysis.CSharp.Tests/Atc.CodeAnalysis.CSharp.Tests.csproj
index 71326c8e..fde66036 100644
--- a/test/Atc.CodeAnalysis.CSharp.Tests/Atc.CodeAnalysis.CSharp.Tests.csproj
+++ b/test/Atc.CodeAnalysis.CSharp.Tests/Atc.CodeAnalysis.CSharp.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.CodeDocumentation.Tests/Atc.CodeDocumentation.Tests.csproj b/test/Atc.CodeDocumentation.Tests/Atc.CodeDocumentation.Tests.csproj
index 58d684c6..cf2f0efe 100644
--- a/test/Atc.CodeDocumentation.Tests/Atc.CodeDocumentation.Tests.csproj
+++ b/test/Atc.CodeDocumentation.Tests/Atc.CodeDocumentation.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.Console.Spectre.Tests/Atc.Console.Spectre.Tests.csproj b/test/Atc.Console.Spectre.Tests/Atc.Console.Spectre.Tests.csproj
index d6f74bef..ffc26f6d 100644
--- a/test/Atc.Console.Spectre.Tests/Atc.Console.Spectre.Tests.csproj
+++ b/test/Atc.Console.Spectre.Tests/Atc.Console.Spectre.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.DotNet.Tests/Atc.DotNet.Tests.csproj b/test/Atc.DotNet.Tests/Atc.DotNet.Tests.csproj
index 085fe298..8a348b3a 100644
--- a/test/Atc.DotNet.Tests/Atc.DotNet.Tests.csproj
+++ b/test/Atc.DotNet.Tests/Atc.DotNet.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.OpenApi.Tests/Atc.OpenApi.Tests.csproj b/test/Atc.OpenApi.Tests/Atc.OpenApi.Tests.csproj
index 67e546f4..efa2d095 100644
--- a/test/Atc.OpenApi.Tests/Atc.OpenApi.Tests.csproj
+++ b/test/Atc.OpenApi.Tests/Atc.OpenApi.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.Rest.Extended.Tests/Atc.Rest.Extended.Tests.csproj b/test/Atc.Rest.Extended.Tests/Atc.Rest.Extended.Tests.csproj
index ae5fa9a8..15fc1af4 100644
--- a/test/Atc.Rest.Extended.Tests/Atc.Rest.Extended.Tests.csproj
+++ b/test/Atc.Rest.Extended.Tests/Atc.Rest.Extended.Tests.csproj
@@ -7,13 +7,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.Rest.FluentAssertions.Tests/Atc.Rest.FluentAssertions.Tests.csproj b/test/Atc.Rest.FluentAssertions.Tests/Atc.Rest.FluentAssertions.Tests.csproj
index aff0a2ae..e222ce2a 100644
--- a/test/Atc.Rest.FluentAssertions.Tests/Atc.Rest.FluentAssertions.Tests.csproj
+++ b/test/Atc.Rest.FluentAssertions.Tests/Atc.Rest.FluentAssertions.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.Rest.HealthChecks.Tests/Atc.Rest.HealthChecks.Tests.csproj b/test/Atc.Rest.HealthChecks.Tests/Atc.Rest.HealthChecks.Tests.csproj
index 15539fbc..0bc978ba 100644
--- a/test/Atc.Rest.HealthChecks.Tests/Atc.Rest.HealthChecks.Tests.csproj
+++ b/test/Atc.Rest.HealthChecks.Tests/Atc.Rest.HealthChecks.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.Rest.Tests/Atc.Rest.Tests.csproj b/test/Atc.Rest.Tests/Atc.Rest.Tests.csproj
index 7acb9269..0d64b37c 100644
--- a/test/Atc.Rest.Tests/Atc.Rest.Tests.csproj
+++ b/test/Atc.Rest.Tests/Atc.Rest.Tests.csproj
@@ -7,14 +7,14 @@
-
+
-
-
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.Tests/Atc.Tests.csproj b/test/Atc.Tests/Atc.Tests.csproj
index 706d2e2d..816e4c48 100644
--- a/test/Atc.Tests/Atc.Tests.csproj
+++ b/test/Atc.Tests/Atc.Tests.csproj
@@ -7,13 +7,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Atc.Tests/Helpers/DateTimeHelperTests.cs b/test/Atc.Tests/Helpers/DateTimeHelperTests.cs
index 15dbb250..0cbcfa0b 100644
--- a/test/Atc.Tests/Helpers/DateTimeHelperTests.cs
+++ b/test/Atc.Tests/Helpers/DateTimeHelperTests.cs
@@ -33,6 +33,24 @@ public void TryParseUsingCurrentUiCulture(
Assert.Equal(expected, actual);
}
+ [Theory]
+ [InlineData(true, GlobalizationLcidConstants.UnitedStates, "10/15/2023")]
+ [InlineData(true, GlobalizationLcidConstants.GreatBritain, "15/10/2023")]
+ [InlineData(true, GlobalizationLcidConstants.Denmark, "15.10.2023")]
+ [InlineData(false, GlobalizationLcidConstants.Germany, "15.20.2023")]
+ public void TryParseUsingSpecificCulture(
+ bool expected, int cultureLcid, string value)
+ {
+ // Arrange
+ var cultureInfo = new CultureInfo(cultureLcid);
+
+ // Act
+ var actual = DateTimeHelper.TryParseUsingSpecificCulture(value, cultureInfo, out _);
+
+ // Assert
+ Assert.Equal(expected, actual);
+ }
+
[Theory]
[InlineData(true, GlobalizationLcidConstants.UnitedStates, "10/15/2023")]
[InlineData(true, GlobalizationLcidConstants.UnitedStates, "10-15-2023")]
@@ -63,6 +81,24 @@ public void TryParseShortDateUsingCurrentUiCulture(
Assert.Equal(expected, actual);
}
+ [Theory]
+ [InlineData(true, GlobalizationLcidConstants.UnitedStates, "10/15/2023")]
+ [InlineData(true, GlobalizationLcidConstants.GreatBritain, "15/10/2023")]
+ [InlineData(true, GlobalizationLcidConstants.Denmark, "15.10.2023")]
+ [InlineData(false, GlobalizationLcidConstants.Germany, "15.20.2023")]
+ public void TryParseShortDateUsingSpecificCulture(
+ bool expected, int cultureLcid, string value)
+ {
+ // Arrange
+ var cultureInfo = new CultureInfo(cultureLcid);
+
+ // Act
+ var actual = DateTimeHelper.TryParseShortDateUsingSpecificCulture(value, cultureInfo, out _);
+
+ // Assert
+ Assert.Equal(expected, actual);
+ }
+
[Theory]
[InlineData(true, GlobalizationLcidConstants.UnitedStates, "3:30 AM")]
[InlineData(true, GlobalizationLcidConstants.UnitedStates, "3:30 PM")]
@@ -93,6 +129,24 @@ public void TryParseShortTimeUsingCurrentUiCulture(
Assert.Equal(expected, actual);
}
+ [Theory]
+ [InlineData(true, GlobalizationLcidConstants.UnitedStates, "3:30 AM")]
+ [InlineData(true, GlobalizationLcidConstants.GreatBritain, "03:30")]
+ [InlineData(true, GlobalizationLcidConstants.Denmark, "03.30")]
+ [InlineData(false, GlobalizationLcidConstants.Germany, "24:30")]
+ public void TryParseShortTimeUsingSpecificCulture(
+ bool expected, int cultureLcid, string value)
+ {
+ // Arrange
+ var cultureInfo = new CultureInfo(cultureLcid);
+
+ // Act
+ var actual = DateTimeHelper.TryParseShortTimeUsingSpecificCulture(value, cultureInfo, out _);
+
+ // Assert
+ Assert.Equal(expected, actual);
+ }
+
[Theory]
[InlineData(true, GlobalizationLcidConstants.UnitedStates, "3:30 AM")]
[InlineData(true, GlobalizationLcidConstants.UnitedStates, "3:30 PM")]
@@ -122,4 +176,22 @@ public void TryParseShortTimeUsingCurrentUiCultureUtc(
// Assert
Assert.Equal(expected, actual);
}
+
+ [Theory]
+ [InlineData(true, GlobalizationLcidConstants.UnitedStates, "3:30 AM")]
+ [InlineData(true, GlobalizationLcidConstants.GreatBritain, "03:30")]
+ [InlineData(true, GlobalizationLcidConstants.Denmark, "03.30")]
+ [InlineData(false, GlobalizationLcidConstants.Germany, "24:30")]
+ public void TryParseShortTimeUsingSpecificCultureUtc(
+ bool expected, int cultureLcid, string value)
+ {
+ // Arrange
+ var cultureInfo = new CultureInfo(cultureLcid);
+
+ // Act
+ var actual = DateTimeHelper.TryParseShortTimeUsingSpecificCultureUtc(value, cultureInfo, out _);
+
+ // Assert
+ Assert.Equal(expected, actual);
+ }
}
\ No newline at end of file
diff --git a/test/Atc.XUnit.Tests/Atc.XUnit.Tests.csproj b/test/Atc.XUnit.Tests/Atc.XUnit.Tests.csproj
index 58d684c6..cf2f0efe 100644
--- a/test/Atc.XUnit.Tests/Atc.XUnit.Tests.csproj
+++ b/test/Atc.XUnit.Tests/Atc.XUnit.Tests.csproj
@@ -6,13 +6,13 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/test/Directory.Build.props b/test/Directory.Build.props
index e5dadd9d..d6c2c05e 100644
--- a/test/Directory.Build.props
+++ b/test/Directory.Build.props
@@ -12,7 +12,7 @@
-
+