Bug
ForgeMap v1.6 correctly applies nullable-safe collection coercion (via .ToDictionary() adapter) for property assignments, but does NOT apply it for constructor parameter expressions. This causes CS8620 under TreatWarningsAsErrors.
Reproduction
// Source (no nullable annotations):
public class Source
{
public IDictionary<string, object> Metadata { get; set; }
}
// Destination (constructor-based, with nullable annotations):
public class Dest
{
public Dest(IReadOnlyDictionary<string, object?>? metadata = null)
{
Metadata = metadata ?? new Dictionary<string, object?>();
}
public IReadOnlyDictionary<string, object?> Metadata { get; }
}
[ForgeMap(NullPropertyHandling = NullPropertyHandling.CoalesceToNew)]
public partial class TestForger
{
public partial Dest Forge(Source source);
}
Generated code (constructor path):
return new Dest(
metadata: new ReadOnlyDictionary<string, object>(source.Metadata) // CS8620!
);
Expected: Should apply the same .ToDictionary() nullable adapter as property assignment:
return new Dest(
metadata: Enumerable.ToDictionary(
Enumerable.Select(source.Metadata, kv => new KeyValuePair<string, object?>(kv.Key, (object?)kv.Value)),
kv => kv.Key, kv => kv.Value)
);
Impact
This prevents using constructor mapping for types with IReadOnlyDictionary<string, object?> constructor parameters when the source uses IDictionary<string, object>. The user must keep a manual mapping method.
Environment
- ForgeMap 1.6.0
- .NET 8.0 with
TreatWarningsAsErrors
Bug
ForgeMap v1.6 correctly applies nullable-safe collection coercion (via
.ToDictionary()adapter) for property assignments, but does NOT apply it for constructor parameter expressions. This causes CS8620 underTreatWarningsAsErrors.Reproduction
Generated code (constructor path):
Expected: Should apply the same
.ToDictionary()nullable adapter as property assignment:Impact
This prevents using constructor mapping for types with
IReadOnlyDictionary<string, object?>constructor parameters when the source usesIDictionary<string, object>. The user must keep a manual mapping method.Environment
TreatWarningsAsErrors