Replies: 1 comment
|
Instead of editing the existing post, I'm going to add a new comment, because I've found a lot here... First, there appear to be two possible bugs, and one instance of unexpected behavior (not sure if intentional or not). first of all, some minor boilerplate: namespace Mapping.SourceGen.Test {
public interface ITestContainer<TValue> {
TValue Value { get; set; }
}
}namespace Mapping.SourceGen.Test {
public class TestContainer<TValue> : ITestContainer<TValue> {
public required TValue Value { get; set; }
}
}Possible Bug 1: Generator Crash (CS8785)This occurs when using both the existing-target generic dispatcher and user-defined existing-target generic mapping. If either of these is missing, it compiles just fine. When both are present, it crashes the source generator, and all generated mappings fail across the project. I say it's possibly a bug because I don't know 100% that it's not intentional, but it seems more than likely not. namespace Mapping.SourceGen.Test {
[Mapper]
public partial class GenericMapToExistingCrashesGenerator {
public partial TDestination Map<TSource, TDestination>(TSource source);
public partial void Map<TSource, TDestination>(TSource source, TDestination destination); // (A) existing-target dispatcher — required ingredient
public void MapContainer<TSource, TDestination>(ITestContainer<TSource> source, ITestContainer<TDestination> destination) { // (B) existing-target generic mapping — required ingredient; this pairing crashes the generator
destination.Value = Map<TSource, TDestination>(source.Value);
}
public partial long Map(int source);
}
}Possible Bug 2: RMG013 Fires Before Generic User-Mapping Delegation is ConsideredGoal is to map ITestContainer -> TestContainer by reusing a single generic user-implemented mapping that knows how to build the wrapper. A concrete closed partial is declared to create the entry point, intending Mapperly to satisfy it by delegating to the generic user mapping above it. The code shows an error at namespace Mapping.SourceGen.Test {
[Mapper]
public partial class GenericAddToNewFails {
public partial TDestination Map<TSource, TDestination>(TSource source);
public partial long Map(int source);
// Generic user mapping intended to satisfy the concrete partial below via delegation.
public ITestContainer<TDestination> Map<TSource, TDestination>(ITestContainer<TSource> source) {
return new TestContainer<TDestination> {
Value = Map<TSource, TDestination>(source.Value)
};
}
public partial ITestContainer<long> Map(ITestContainer<int> source); // triggers RMG013: Mapperly tries to construct ITestContainer<long> instead of delegating to the generic mapping above
}
}Unexpected Behavior: Generic User-Defined Mapping Inconsistently RenderedIn the I can go ahead and move these to the issues list if they're valid problems. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to get the generic user implemented mappings from 5.0.0-next.5 working, but am having some trouble. I can create the mapping method just fine, but none of the generated methods seem to reference it.
I have the following mapping method...
From what I'm seeing in the documentation, the implementation for the following should include a reference to it, as it should just have a big switch to every registered type.
But there is no reference to
MapServiceResultGenericin the generated source. It has references to everything else in it. I also created a mapping for the non-generic versionAnd that non-generic version is included in the generated source. From what I'm seeing in the documentation, I shouldn't need to use any special attributes or anything, so I'm a bit stumped.
Edit: Here's the documentation I'm looking at: Generic User Implemented Mapping Methods
Edit 2: AI is suggesting the issue has to do with Mapperly trying to auto-generate the mapping. It sees an interface and yells that it can't instantiate it instead of using the user-defined generic mapping that would handle the situation (the above MapServiceResultGeneric). Is this an issue with resolution order when generating code?
All reactions