Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Don't fallback to default mapping when property is ignored
Browse files Browse the repository at this point in the history
Resolves #81
  • Loading branch information
henkmollema committed Mar 28, 2019
1 parent 837332b commit e32a184
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Dapper.FluentMap/TypeMaps/FluentTypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ private static PropertyInfo GetPropertyInfo(Type type, string columnName)
TypePropertyMapCache.TryAdd(cacheKey, propertyMap.PropertyInfo);
return propertyMap.PropertyInfo;
}
#if !NETSTANDARD1_3
else
{
var ignoredPropertyInfo = new IgnoredPropertyInfo();
TypePropertyMapCache.TryAdd(cacheKey, ignoredPropertyInfo);
return ignoredPropertyInfo;
}
#endif
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/Dapper.FluentMap/TypeMaps/IgnoredPropertyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if !NETSTANDARD1_3
using System;
using System.Globalization;
using System.Reflection;

namespace Dapper.FluentMap.TypeMaps
{
internal class IgnoredPropertyInfo : PropertyInfo
{
public override Type PropertyType => throw new NotImplementedException();
public override PropertyAttributes Attributes => throw new NotImplementedException();
public override bool CanRead => throw new NotImplementedException();
public override bool CanWrite => throw new NotImplementedException();
public override string Name => throw new NotImplementedException();
public override Type DeclaringType => throw new NotImplementedException();
public override ParameterInfo[] GetIndexParameters() => throw new NotImplementedException();
public override Type ReflectedType => throw new NotImplementedException();
public override MethodInfo[] GetAccessors(bool nonPublic) => throw new NotImplementedException();
public override object[] GetCustomAttributes(bool inherit) => throw new NotImplementedException();
public override object[] GetCustomAttributes(Type attributeType, bool inherit) => throw new NotImplementedException();
public override MethodInfo GetGetMethod(bool nonPublic) => throw new NotImplementedException();
public override MethodInfo GetSetMethod(bool nonPublic) => throw new NotImplementedException();
public override bool IsDefined(Type attributeType, bool inherit) => throw new NotImplementedException();
public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) => throw new NotImplementedException();
public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) => throw new NotImplementedException();
}
}
#endif
8 changes: 8 additions & 0 deletions src/Dapper.FluentMap/TypeMaps/MultiTypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public SqlMapper.IMemberMap GetMember(string columnName)
var result = mapper.GetMember(columnName);
if (result != null)
{
#if !NETSTANDARD1_3
if (result is IgnoredPropertyInfo)
{
// The property is explicitly ignored,
// return null to prevent falling back to default type map of Dapper.
return null;
}
#endif
return result;
}
}
Expand Down

0 comments on commit e32a184

Please sign in to comment.