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

Fix Issues #536 -> Set properties with reflection if destination has init only properties. #545

Merged
merged 7 commits into from
Feb 21, 2023

Conversation

stormaref
Copy link
Contributor

I've fixed #536 and wrote a test that regenerates the exact issue
The test has been passed
I add a method to "ClassAdapter" in this commit to generate reflection code for setting init only properties

The result is like this:

public _UserDto MapTo(_User p3, _UserDto p4)
        {
            if (p3 == null)
            {
                return null;
            }
            _UserDto result = p4 ?? new _UserDto();
            
            typeof(_UserDto).GetProperty("Id").SetValue(result, (object)p3.Id);
            typeof(_UserDto).GetProperty("Name").SetValue(result, p3.Name);
            return result;
            
        }
  • I did not update the package version in csproj

@andrerav andrerav merged commit 0e31a0b into MapsterMapper:master Feb 21, 2023
@andrerav
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error mapping with existing object and init properties
2 participants