Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit d51e76e

Browse files
committed
Add ConvertTo overload with defaultValue
1 parent db287ae commit d51e76e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/ServiceStack.Text/AutoMappingUtils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public static GetMemberDelegate GetConverter(Type fromType, Type toType)
7878
: null;
7979
}
8080

81+
public static T ConvertTo<T>(this object from, T defaultValue) =>
82+
from == null || (from is string s && s == string.Empty)
83+
? defaultValue
84+
: from.ConvertTo<T>();
85+
8186
public static T ConvertTo<T>(this object from) => from.ConvertTo<T>(skipConverters:false);
8287
public static T ConvertTo<T>(this object from, bool skipConverters)
8388
{

0 commit comments

Comments
 (0)