From 36411699c8ea3bbd85ce7b02bacc85f2bdfbeeed Mon Sep 17 00:00:00 2001 From: Paolo Iommarini Date: Wed, 24 Aug 2022 14:48:54 +0200 Subject: [PATCH] Fix --- CmdLineArgsParser/Parser.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CmdLineArgsParser/Parser.cs b/CmdLineArgsParser/Parser.cs index 0e2ba6c..6ac8e90 100644 --- a/CmdLineArgsParser/Parser.cs +++ b/CmdLineArgsParser/Parser.cs @@ -235,14 +235,7 @@ private object GetValueFromString(Type propertyType, string value, out string ex if (propertyType == typeof(DateTime)) { expectedType = "DateTime"; - if (!string.IsNullOrEmpty(Settings.DateTimeFormat)) { - if (DateTime.TryParseExact(value, Settings.DateTimeFormat, null, DateTimeStyles.None, out var dtValue)) - return dtValue; - } else { - if (DateTime.TryParse(value, out var dtValue)) - return dtValue; - } - return null; + return GetDateTimeValueFromString(value); } if (propertyType == typeof(Uri)) { @@ -255,6 +248,19 @@ private object GetValueFromString(Type propertyType, string value, out string ex return null; } + private DateTime? GetDateTimeValueFromString(string value) + { + if (!string.IsNullOrEmpty(Settings.DateTimeFormat)) { + if (DateTime.TryParseExact(value, Settings.DateTimeFormat, null, DateTimeStyles.None, out var dtValue)) + return dtValue; + } else { + if (DateTime.TryParse(value, out var dtValue)) + return dtValue; + } + + return null; + } + /// /// Get the default value for a ///