When a mapping for a generic type is configured like described here TypeAdapterConfig.GlobalSettings.Compile() throws a Mapster.CompileException: 'Operation is not valid due to the current state of the object.' with an inner ArgumentException: Type ClassA`1[T] is a generic type definition (Parameter 'type').
Minimal working example:
using Mapster;
TypeAdapterConfig.GlobalSettings.ForType(typeof(ClassA<>), typeof(ClassB<>));
TypeAdapterConfig.GlobalSettings.Compile();
var classA = new ClassA<int> { Variable = 15 };
var classB = classA.Adapt<ClassB<int>>();
class ClassA<T> { public T? Variable { get; set; } = default; }
class ClassB<T> { public T? Variable { get; set; } = default; }
When removing TypeAdapterConfig.GlobalSettings.Compile(); the mapping works just fine.
The exception is thrown in Mapster.Adapters.BaseAdapter.CreateAdaptFunc(CompileArgument arg) when calling Expression.Parameter(arg.SourceType).
Mapster version 10.0.7
When a mapping for a generic type is configured like described here
TypeAdapterConfig.GlobalSettings.Compile()throws a Mapster.CompileException: 'Operation is not valid due to the current state of the object.' with an inner ArgumentException: Type ClassA`1[T] is a generic type definition (Parameter 'type').Minimal working example:
When removing
TypeAdapterConfig.GlobalSettings.Compile();the mapping works just fine.The exception is thrown in
Mapster.Adapters.BaseAdapter.CreateAdaptFunc(CompileArgument arg)when callingExpression.Parameter(arg.SourceType).Mapster version 10.0.7