Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sakya committed Aug 24, 2022
1 parent 0d94ff2 commit 3641169
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions CmdLineArgsParser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}

/// <summary>
/// Get the default value for a <see cref="Type"/>
/// </summary>
Expand Down

0 comments on commit 3641169

Please sign in to comment.