Skip to content

Commit

Permalink
option for dealing with nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Jun 20, 2024
1 parent 531551a commit d7b5cd9
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static FieldType FieldTypeToNative(object fieldType)
{
try
{
static T? GetValue<T>(string? s, Func<string, T> func) => s is null ? default : func(s);
return fieldType switch
{
FieldType.String => Convert.ToString(value),
Expand All @@ -102,9 +103,9 @@ public static FieldType FieldTypeToNative(object fieldType)
FieldType.BigInteger => Convert.ToInt64(value),
FieldType.SmallInteger => Convert.ToInt16(value),
FieldType.Double => Convert.ToDouble(value),
FieldType.Date => DateTime.Parse((string)value, null),
FieldType.DateOnly => DateOnly.Parse((string)value),
FieldType.TimeOnly => TimeOnly.Parse((string)value),
FieldType.Date => GetValue(value.ToString(), s => DateTime.Parse(s , null)),
FieldType.DateOnly => GetValue(value.ToString(), s => DateOnly.Parse(s, null)),
FieldType.TimeOnly => GetValue(value.ToString(), s => TimeOnly.Parse(s, null)),
_ => value,
};
}
Expand Down

0 comments on commit d7b5cd9

Please sign in to comment.