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

Computed read-only properties causing RMG066 warning #1402

Closed
RichardD2 opened this issue Jul 19, 2024 · 2 comments · Fixed by #1413
Closed

Computed read-only properties causing RMG066 warning #1402

RichardD2 opened this issue Jul 19, 2024 · 2 comments · Fixed by #1413
Labels
bug Something isn't working

Comments

@RichardD2
Copy link

Describe the bug
Creating a mapping between two entities, both of which contain the same read-only computed property of a nullable value type, produces an erroneous RMG066 warning.

Declaration code

namespace Db
{
    public class Foo
    {
        public int? CategoryId { get; set; }
        public bool? IsSpecialCategory => CategoryId == 42;
    }
}

namespace Dto
{
    public class Foo
    {
        public int? CategoryId { get; set; }
        public bool? IsSpecialCategory => CategoryId == 42;
    }
}

namespace Mapping
{
    [Mapper]
    public static partial class FooMapping
    {
        public static partial Dto.Foo MapToDto(this Db.Foo source);
    }
}

Actual relevant generated code

namespace Mapping
{
    public static partial class FooMapping
    {
        [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "3.6.0.0")]
        public static partial global::Dto.Foo MapToDto(global::Db.Foo source)
        {
            var target = new global::Dto.Foo();
            target.CategoryId = source.CategoryId;
            return target;
        }
    }
}

Expected relevant generated code
The actual generated code is correct. However, the mapping is flagged with:

RMG066 No members are mapped in the object mapping from bool? to bool?

Environment (please complete the following information):

  • Mapperly Version: 3.6.0
  • Nullable reference types: enabled
  • .NET Version: .NET 8.0.303
  • Target Framework: .net8.0
  • Compiler Version: 4.10.0-3.24324.8 (04fb3916)
  • C# Language Version: 12.0
  • IDE: Visual Studio v17.10.4
  • OS: Windows 11 23H2

Additional context
Explicitly adding a MapperIgnoreSource for the computed property makes the warning go away:

[Mapper]
public static partial class FooMapping
{
    [MapperIgnoreSource(nameof(Db.Foo.IsSpecialCategory))]
    public static partial Dto.Foo MapToDto(this Db.Foo source);
}
@RichardD2 RichardD2 added the bug Something isn't working label Jul 19, 2024
@latonz
Copy link
Contributor

latonz commented Jul 22, 2024

Thanks for reporting. I cannot reproduce the RMG066, I always get RMG020 for Value and HasValue of the bool? (which isn't optimal either). Do you have any properties set on the MapperAttribute or do you have a MapperDefaultsAttribute for your assembly?

@RichardD2
Copy link
Author

No additional settings. I'm getting the two RMG020 hints and the RMG066 warning with just the code shown.

image

image

I've attached the sample project I'm using:
Mapperly1402.zip

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.

2 participants