-
Notifications
You must be signed in to change notification settings - Fork 91
Conversation
Based on the code snippet that @g-adolph put on issue henkmollema#46 discussion thread. Now we can map properties of value objects.
@nicolastakashi thanks for this! Have you verified that Dapper maps the columns to the desired value object? |
Yes @henkmollema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at the review comments.
var paramType = lambda.Parameters[0].Type; | ||
var memberInfo = paramType.GetMember(baseMember.Name)[0]; | ||
return memberInfo; | ||
paramType = lambda.Parameters.FirstOrDefault().Type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep using array indexer here:
paramType = lambda.Parameters[0].Type;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one question is there any reason not to use FirstOrDefault?
Is the idea really popping an exception if it does not have index 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reading the code FirstOrDefault
tells you that there might not be a value present or that the collection is not an array/list. Beside that, I tend to avoid overhead from LINQ as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this will throw an exception anyway, because you will be accessing Type
from a null
reference. I rather get an ArgumentOutOfRangeException
than NullReferenceException
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you FirstOrDefault()
to [0]
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolastakashi this one.
var memberInfo = paramType.GetMember(baseMember.Name)[0]; | ||
return memberInfo; | ||
paramType = lambda.Parameters.FirstOrDefault().Type; | ||
return paramType.GetMember(baseMember.Name).FirstOrDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep using array indexer here:
return paramType.GetMember(baseMember.Name)[0];
@@ -31,11 +33,22 @@ public static MemberInfo GetMemberInfo(LambdaExpression lambda) | |||
case ExpressionType.MemberAccess: | |||
var memberExpression = (MemberExpression)expr; | |||
var baseMember = memberExpression.Member; | |||
Type paramType; | |||
|
|||
while (!(memberExpression is null)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while (memberExpression != null)
paramType = memberExpression.Type; | ||
if (paramType.GetMembers().Any(member => member.Name == baseMember.Name)) | ||
{ | ||
return paramType.GetMember(baseMember.Name).FirstOrDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return paramType.GetMember(baseMember.Name)[0];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
We can continue with these suggestions.
@nicolastakashi you might want to check your Git settings because you've been committing with different usernames/email addresses. |
I did not change my username or email. I just checked and everything seems like before. |
Take a look at the two commits here: https://github.com/henkmollema/Dapper-FluentMap/pull/58/commits. They show a different user with a different email address (and profile picture). |
Ow Really! Something strange with Github, because the only thing I just did was actually change my profile picture, nothing more. Do not know exactly where to fix it? Any suggestion? |
If you search by my name you will see that only my profile appears. |
Would you like me to pull a pull request again? Do you think this is an impediment? |
No it's fine. Please fix the remaining comment and I'll merge this in. |
Which comment do you need to fix? Sorry, I do not understand very well. |
There is one |
Remove FirstOrDefault to keep code pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I Remove the FirstOrDefault funcition
var paramType = lambda.Parameters[0].Type; | ||
var memberInfo = paramType.GetMember(baseMember.Name)[0]; | ||
return memberInfo; | ||
paramType = lambda.Parameters.[0].Type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameters.[0]
should be Parameters[0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
this version is already on nuget? |
@lepiroupo @nicolastakashi I've just pushed v1.5.4 to NuGet: https://www.nuget.org/packages/Dapper.FluentMap/1.5.4. |
Based on the code snippet that @g-adolph put on issue #46 discussion thread.
Now we can map properties of value objects.