class Model1
{
public Dictionary<string, string>? Items1 { get; init; }
}
class Model2
{
public IReadOnlyDictionary<int, string> Items1 { get; init; } = new Dictionary<int, string>().AsReadOnly();
}
var config = TypeAdapterConfig.GlobalSettings;
var registers = config.Scan(Assembly.GetExecutingAssembly());
config.Apply(registers);
config.NewConfig<Model2, Model1>()
.Map(destination => destination.Items1, source => source.Items1.ToDictionary(s => s.Key.ToString(), s => s.Value));
model1 = model2.Adapt(model1);
And retrieve next exception:
Mapster.CompileException : Error while compiling
source=System.Collections.Generic.IReadOnlyDictionary2[System.Int32,System.String] destination=System.Collections.Generic.Dictionary2[System.String,System.String]
type=MapToTarget
---- System.ArgumentException : Expression of type 'System.Int32' cannot be used for parameter of type 'System.String' of method 'System.String GetValueOrDefault[String,String](System.Collections.Generic.IDictionary`2[System.String,System.String], System.String)' (Parameter 'arg1')
Hello, i have:
And retrieve next exception: Mapster.CompileException : Error while compiling source=System.Collections.Generic.IReadOnlyDictionary
2[System.Int32,System.String] destination=System.Collections.Generic.Dictionary
2[System.String,System.String] type=MapToTarget ---- System.ArgumentException : Expression of type 'System.Int32' cannot be used for parameter of type 'System.String' of method 'System.String GetValueOrDefault[String,String](System.Collections.Generic.IDictionary`2[System.String,System.String], System.String)' (Parameter 'arg1')Mapster v 7.3
Thanks for response!