Skip to content

Commit

Permalink
Fix exception when null assigned to a nullable value type.
Browse files Browse the repository at this point in the history
  • Loading branch information
omaxel committed Oct 13, 2017
1 parent 4515c99 commit 7977ca9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/SimplePatch/Delta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private TEntity SetPropertiesValue(TEntity entity)
var propertyInfo = prop.PropertyInfo;
if (ContainsKey(propertyInfo.Name) && !IsExcludedProperty(typeFullName, propertyInfo.Name))
{
var propertyType = TypeHelper.GetTrueType(propertyInfo.PropertyType);
var truePropertyType = TypeHelper.GetTrueType(propertyInfo.PropertyType);
var newPropertyValue = this[propertyInfo.Name];


Expand All @@ -200,7 +200,7 @@ private TEntity SetPropertiesValue(TEntity entity)
if (prop.IgnoreNullValue) continue;

//Check if destination property allows null value
if (TypeHelper.IsNullable(propertyType))
if (TypeHelper.IsNullable(propertyInfo.PropertyType))
{
propertyInfo.SetValue(entity, null, null);
continue;
Expand All @@ -214,14 +214,14 @@ private TEntity SetPropertiesValue(TEntity entity)
var newPropertyValueType = newPropertyValue.GetType();

//Guid from string
if (propertyType == typeof(Guid) && newPropertyValueType == typeof(string))
if (truePropertyType == typeof(Guid) && newPropertyValueType == typeof(string))
{
newPropertyValue = new Guid((string)newPropertyValue);
propertyInfo.SetValue(entity, newPropertyValue, null);
}
else
{
propertyInfo.SetValue(entity, Convert.ChangeType(newPropertyValue, propertyType), null);
propertyInfo.SetValue(entity, Convert.ChangeType(newPropertyValue, truePropertyType), null);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/SimplePatch/SimplePatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

<PropertyGroup>
<TargetFrameworks>net451;netstandard1.4</TargetFrameworks>
<Version>1.2.3</Version>
<Version>1.2.4</Version>
<Authors>Omar Muscatello</Authors>
<Company>Omar Muscatello</Company>
<Description>A simple library for partial entity changes in ASP.NET and ASP.NET Core.</Description>
<Copyright>Copyright (c) Omar Muscatello 2017</Copyright>
<PackageLicenseUrl>https://github.com/OmarMuscatello/SimplePatch/blob/master/LICENSE</PackageLicenseUrl>
<PackageReleaseNotes>Added ability to ignore null value for specified properties</PackageReleaseNotes>
<PackageReleaseNotes>Fix exception when null assigned to a nullable value type.</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/OmarMuscatello/SimplePatch</PackageProjectUrl>
<RepositoryUrl>https://github.com/OmarMuscatello/SimplePatch</RepositoryUrl>
<PackageIconUrl>http://raw.github.com/OmarMuscatello/SimplePatch/master/simplepatch-icon.png</PackageIconUrl>
<RepositoryType></RepositoryType>
<PackageTags>web-api patch entity-framework update asp-net asp-net-core</PackageTags>
<ApplicationIcon></ApplicationIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>1.2.3.0</AssemblyVersion>
<FileVersion>1.2.3.0</FileVersion>
<AssemblyVersion>1.2.4.0</AssemblyVersion>
<FileVersion>1.2.4.0</FileVersion>
</PropertyGroup>

</Project>

0 comments on commit 7977ca9

Please sign in to comment.