mapperly
mapperly copied to clipboard
Ignore Properties on Multiple Derived Types and Base Class Simultaneously
Describe the bug This is related to: https://github.com/riok/mapperly/issues/694
To Reproduce Have ignores set up on separate derive types + the base class for a given mapping structure.
Results in RMG021: IgnoredSourceMember was not found
There is currently no way to Ignore base mappings due to the inability to apply the MapDerivedType
logic to an existing mapping.
Expected behavior
A clear and concise description of what you expected to happen.
I would expect the ability to separately ignore members at the base class level, and at each of the derived types without introducing errors or suppressions.
Code snippets
public class SourceBase
{
public int BaseId { get; set; }
}
public class Source : SourceBase
{
public int Id { get; set; }
}
public class AnotherSource: SourceBase
{
public int NewProp { get; set; }
}
public class TargetBase // missing ID
{ }
public class Target : TargetBase
{ }
public class AnotherTarget : TargetBase
{}
[Mapper]
internal static partial class TestMapper
{
[MapDerivedType<Source, Target>]
[MapDerivedType<AnotherSource, AnotherTarget>]
[MapperIgnoreSource(nameof(SourceBase.BaseId))]
[MapperIgnoreSource(nameof(Source.Id))]
[MapperIgnoreSource(nameof(AnotherSource.NewProp))]
public static partial TargetBase ToTarget(this SourceBase source);
}
Environment (please complete the following information):
- Mapperly Version: e.g. 3.2.0
- .NET Version: e.g. .NET 7.0.*
- Target Framework: .net7.0
- IDE: Visual Studio v17.8
- OS: Windows 10
This would be a great enhancement. Would be happy to accept a PR, let me know if you want to contribute and need any hints 😊
The problem I see here is how to decide which configurations apply to which type mappings. Should all applied to all? Even if there is a specific mapping method for a given type pair?
Could it follow the existing precedence conventions / behaviors that already exist?
What conventions are you referring to?
Closing in favor of the new MapperIgnoreAttribute
that allows ignoring properties at source.