Dapper-FluentMap
Dapper-FluentMap copied to clipboard
Throws InvalidCastException when a string property has a name that conflicts with the String Type built in function members
I have an Entity with a property named "Format". When mapping, FluentMap throws:
InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.PropertyInfo'. Dapper.FluentMap.Mapping.EntityMapBase<TEntity, TPropertyMap>.Map(Expression<Func<TEntity, object>> expression)
This is caused probably because in the ReflectionHelper.cs in line 70 you have the following code:
return paramType.GetMember(member.Name)[0]
It takes the first Member with the name given. I believe that if you change it so that it uses only Property members like below, the problem will be solved:
return paramType.GetMember(member.Name).Where(a=> a.MemberType == MemberTypes.Property).First();
Thanks!
Would you like to send A PR?
Same problem exists with other types. For example, mapping TimeSpan Duration { get; set; } property fails with same error message, I guess because TimeSpan type has Duration() function.