Skip to content

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