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

Commit 206032f

Browse files
committed
Add IsDefaultValue Utils
1 parent 81a062b commit 206032f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ServiceStack.Text/AutoMappingUtils.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ private static object PopulateObjectInternal(object obj, Dictionary<Type, int> r
416416

417417
public static object GetDefaultValue(this Type type)
418418
{
419-
if (!type.IsValueType) return null;
419+
if (!type.IsValueType)
420+
return null;
420421

421422
if (DefaultValueTypes.TryGetValue(type, out var defaultValue))
422423
return defaultValue;
@@ -435,6 +436,10 @@ public static object GetDefaultValue(this Type type)
435436
return defaultValue;
436437
}
437438

439+
public static bool IsDefaultValue(object value) => IsDefaultValue(value, value?.GetType());
440+
public static bool IsDefaultValue(object value, Type valueType) => value == null
441+
|| (valueType.IsValueType && value.Equals(valueType.GetDefaultValue()));
442+
438443
private static readonly ConcurrentDictionary<string, AssignmentDefinition> AssignmentDefinitionCache
439444
= new ConcurrentDictionary<string, AssignmentDefinition>();
440445

0 commit comments

Comments
 (0)