Add support for mappings with a class/struct target and a source implementing IReadOnlyDictionary<string, TValue> or IDictionary<string, TValue> with TValue beeing either object or object?.
Questions to be discussed:
What type conversions should be supported? => For now only casting.
What happens with required but unmapped members? => throw an exception
What happens if a value is provided for a member but it cannot be converted to the target type? => throw an exception
How to map nested objects?
Example
Definition
```csharp
public class Fruit
{
public required string Name { get; init; }
public int Weight { get; set; }
public Color Color { get; set; }
}
public enum Color { Red, Green }
[Mapper]
public partial class MyMapper
{
public partial Apple Map(IReadOnlyDictionary source);
}
```
Generated code
```csharp
public partial class MyMapper
{
public partial Apple Map(IReadOnlyDictionary source)
{
var target = new Apple
{
Name = (string)source.GetValueOrDefault(nameof(Apple.Name)) ?? throw ...
};
if (source.TryGetValue(nameof(Apple.Weight), out var weight))
{
target.Weight = (int)weight;
}
if (source.TryGetValue(nameof(Apple.Color), out var color))
{
target.Color = (Color)color;
}
return weight;
}
private partial int ParseString(string source)
{
return int.Parse(source);
}
private partial Color ParseColor(string source)
{
return source switch
{
nameof(Color.Red) => Color.Red,
nameof(Color.Green) => Color.Green,
_ => throw ...
};
}
}
```
Add support for mappings with a class/struct target and a source implementing
IReadOnlyDictionary<string, TValue>
orIDictionary<string, TValue>
withTValue
beeing eitherobject
orobject?
.Questions to be discussed:
Example
Definition
```csharp public class Fruit { public required string Name { get; init; } public int Weight { get; set; } public Color Color { get; set; } } public enum Color { Red, Green } [Mapper] public partial class MyMapper { public partial Apple Map(IReadOnlyDictionaryGenerated code
```csharp public partial class MyMapper { public partial Apple Map(IReadOnlyDictionaryRel. https://github.com/riok/mapperly/issues/1041 and https://github.com/riok/mapperly/discussions/1039