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 ///