Skip to content

Inheriting Attributes from an abstract method #1780

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

Open
3 tasks done
gajo357 opened this issue Apr 3, 2025 · 3 comments
Open
3 tasks done

Inheriting Attributes from an abstract method #1780

gajo357 opened this issue Apr 3, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@gajo357
Copy link

gajo357 commented Apr 3, 2025

Please do the checklist before filing an issue:

  • I have read the documentation, including the FAQ
  • I can reproduce the bug using the latest prerelease version
  • I have searched existing discussion and issue to avoid duplicates

Describe the bug
A base abstract generic class declares an abstract method that is supposed to be partial in the derived class.
There are some properties of the generic type that should be ignored when mapping.
I declared them as such, but I still see RMG012.
It seems that override partial does not inherit the attribute.

According to Microsoft documentation the derived method should inherit the attributes.
MS docs

Declaration code

public class Model
{
    public int Id { get; set; }
}
public class ExactModel : Model
{
}
public class ExactTarget
{
}

public abstract class BaseA<TFrom, TTo> 
  where TFrom: Model
{
   [MapperIgnoreSource(nameof(Model.Id))]
    public abstract TTo Map(TFrom from);
}

[Mapper]
public partial class DerivedA : BaseA<ExactModel, ExactTarget>
{
    public override partial ExactTarget Map(ExactModel from);
}

Reported relevant diagnostics

  • RMG020: The member Id on the mapping source...

Environment (please complete the following information):

  • Mapperly Version: 4.1.1
  • Nullable reference types: Enabled
  • .NET Version: .NET 6.0.427
  • Target Framework: .net6.0
  • Compiler Version: [e.g. 4.8.0-3.23524.11 (f43cd10b), obtain with #error version in any .cs file]
  • C# Language Version: 11.0
  • IDE: Visual Studio v17.13.5
  • OS: Win 11
@gajo357 gajo357 added the bug Something isn't working label Apr 3, 2025
@latonz
Copy link
Contributor

latonz commented Apr 7, 2025

Source generators operate at the syntax or semantic model level, which means they don't automatically recognize inherited attributes. Is what you're trying to achieve a common configuration for a base type?

@gajo357
Copy link
Author

gajo357 commented Apr 7, 2025

Source generators operate at the syntax or semantic model level, which means they don't automatically recognize inherited attributes. Is what you're trying to achieve a common configuration for a base type?

For this yes, since in our scenario there are a number of base properties that have to be mapped manually.
So it is easier to enforce derived mappers to override the mapping of a concrete class than to call that common code all over the place.

The mapper works fine, it's just that these warnings confuse us and can hide an actual missing property.

@latonz latonz added enhancement New feature or request and removed bug Something isn't working labels Apr 7, 2025
@latonz
Copy link
Contributor

latonz commented Apr 7, 2025

#513 could help your use case. Other than that there is currently no support for this scenario. I added the enhancement label. Feel free to contribute 😉

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

No branches or pull requests

2 participants