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

Analyzer should ignore readonly properties in target #329

Closed
marcoatribeiro opened this issue Apr 12, 2023 · 3 comments · Fixed by #345
Closed

Analyzer should ignore readonly properties in target #329

marcoatribeiro opened this issue Apr 12, 2023 · 3 comments · Fixed by #345
Assignees
Labels
bug Something isn't working

Comments

@marcoatribeiro
Copy link

When creating a mapping method from Source to Target classes, where Target has a readonly property, analyzer shows the RMG012 warning, which doesn't make sense, as it would not be possible to map to a readonly property anyway.

To Reproduce

  1. Create Source class with any set of properties (e.g. FirstName and LastName)
  2. Create Target class with all the properties from Source plus a readonly property (e.g. FullName => FirstName + LastName)
  3. Create a Mapper class and a method to map from Source to Target
  4. Check the analyzer displays RMG012 warning

Expected behavior
As the target property is readonly (and, thus, cannot be assigned to), the aforementioned warning should not be displayed.

Environment

  • Mapperly Version: 2.7.0
  • .NET Version: .NET 7
  • IDE: Visual Studio v17.5.4
  • OS: Windows 11
@marcoatribeiro
Copy link
Author

marcoatribeiro commented May 14, 2023

Hi, @latonz !

I just upgraded Mapperly to version 2.8.0 and, although issue #345 is part of this release, this problem still occurs, as can be seen below:

image

Classes PersonEntity and PersonDto have settings just like I described above, with both having FirstName and LastName properties and PersonEntity only having FullName (readonly) property:

public class PersonEntity
{
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
    public string FullName => $"{FirstName} {LastName}";
}
public class PersonDto
{
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
}

Can you please advise?

@TimothyMakkison
Copy link
Collaborator

Hey @marcoatribeiro, is this problem present in the prerelease version?

@marcoatribeiro
Copy link
Author

Hi, @TimothyMakkison and @latonz!

Please disregard my previous comment. I just check it again (with version 2.8.0) and it is working as expected now.
Yesterday I tested right after I updated the package, so, most likely the alert was still showing because VS was still referencing the previous version (even though I had built the whole solution).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants