Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ internal static class PropertyAccessor
converterInput = Expression.Convert(getterExpression, converterParamType);
}

getterExpression = Expression.Invoke(converter, converterInput);
var invokeConverter = Expression.Invoke(converter, converterInput);

if (propertyType.IsClass)
{
var nullCondition = Expression.Equal(getterExpression, Expression.Constant(null, propertyType));
var nullResult = Expression.Constant(null, converter.ReturnType);
getterExpression = Expression.Condition(nullCondition, nullResult, invokeConverter);
}
else
{
getterExpression = invokeConverter;
}

propertyType = getterExpression.Type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ public class TestEntityWithConverters : TestEntityBase

[Column("created_at")]
public DateTime CreatedAt { get; set; }

[Column("uri")]
public Uri? Uri { get; set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public async Task InsertEntities_AndReturn_WithEntityWithValueConverters(InsertS

var entities = new List<TestEntityWithConverters>
{
new TestEntityWithConverters() { Name = $"{_run}_Entity1", CreatedAt = now },
new TestEntityWithConverters() { Name = $"{_run}_Entity2", CreatedAt = now.AddDays(-1) }
new TestEntityWithConverters() { Name = $"{_run}_Entity1", CreatedAt = now, Uri = null },
new TestEntityWithConverters() { Name = $"{_run}_Entity2", CreatedAt = now.AddDays(-1), Uri = new Uri("http://example.com/test") }
};

// Act
Expand Down
Loading