Skip to content

Commit 38f4818

Browse files
author
Christophe Leemans
committed
refactor(serialization): use TypeHelper.ConvertType
Use TypeHelper.ConvertType to keep consistency.
1 parent 244b91f commit 38f4818

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/JsonApiDotNetCore/Models/AttrAttribute.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Reflection;
3+
using JsonApiDotNetCore.Internal;
34

45
namespace JsonApiDotNetCore.Models
56
{
@@ -27,14 +28,12 @@ public void SetValue(object entity, object newValue)
2728
.GetType()
2829
.GetProperty(InternalAttributeName);
2930

30-
if (propertyInfo != null)
31-
{
32-
Type t = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
31+
if (propertyInfo != null)
32+
{
33+
var convertedValue = TypeHelper.ConvertType(newValue, propertyInfo.PropertyType);
3334

34-
var convertedValue = (newValue == null) ? null : Convert.ChangeType(newValue, t);
35-
36-
propertyInfo.SetValue(entity, convertedValue, null);
37-
}
35+
propertyInfo.SetValue(entity, convertedValue);
36+
}
3837
}
3938
}
4039
}

0 commit comments

Comments
 (0)