Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made result of CustomPropertyTypeMap parameter propertySelector nullable #2012

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Dapper/CustomPropertyTypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Dapper
public sealed class CustomPropertyTypeMap : SqlMapper.ITypeMap
{
private readonly Type _type;
private readonly Func<Type, string, PropertyInfo> _propertySelector;
private readonly Func<Type, string, PropertyInfo?> _propertySelector;

/// <summary>
/// Creates custom property mapping
/// </summary>
/// <param name="type">Target entity type</param>
/// <param name="propertySelector">Property selector based on target type and DataReader column name</param>
public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propertySelector)
public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo?> propertySelector)
{
_type = type ?? throw new ArgumentNullException(nameof(type));
_propertySelector = propertySelector ?? throw new ArgumentNullException(nameof(propertySelector));
Expand Down
2 changes: 1 addition & 1 deletion Dapper/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Dapper.CommandFlags.NoCache = 4 -> Dapper.CommandFlags
Dapper.CommandFlags.None = 0 -> Dapper.CommandFlags
Dapper.CommandFlags.Pipelined = 2 -> Dapper.CommandFlags
Dapper.CustomPropertyTypeMap
Dapper.CustomPropertyTypeMap.CustomPropertyTypeMap(System.Type! type, System.Func<System.Type!, string!, System.Reflection.PropertyInfo!>! propertySelector) -> void
Dapper.CustomPropertyTypeMap.CustomPropertyTypeMap(System.Type! type, System.Func<System.Type!, string!, System.Reflection.PropertyInfo?>! propertySelector) -> void
Dapper.CustomPropertyTypeMap.FindConstructor(string![]! names, System.Type![]! types) -> System.Reflection.ConstructorInfo?
Dapper.CustomPropertyTypeMap.FindExplicitConstructor() -> System.Reflection.ConstructorInfo?
Dapper.CustomPropertyTypeMap.GetConstructorParameter(System.Reflection.ConstructorInfo! constructor, string! columnName) -> Dapper.SqlMapper.IMemberMap!
Expand Down
6 changes: 3 additions & 3 deletions tests/Dapper.Tests/TypeHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void TestChangingDefaultStringTypeMappingToAnsiStringFirstOrDefault()
public void TestCustomTypeMap()
{
// default mapping
var item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
var item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B, 'CVal' as C").Single();
Assert.Equal("AVal", item.A);
Assert.Equal("BVal", item.B);

Expand All @@ -68,13 +68,13 @@ public void TestCustomTypeMap()
(type, columnName) => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName)!);
SqlMapper.SetTypeMap(typeof(TypeWithMapping), map);

item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B, 'CVal' as C").Single();
Assert.Equal("BVal", item.A);
Assert.Equal("AVal", item.B);

// reset to default
SqlMapper.SetTypeMap(typeof(TypeWithMapping), null);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B, 'CVal' as C").Single();
Assert.Equal("AVal", item.A);
Assert.Equal("BVal", item.B);
}
Expand Down