Browse Source

Improve exception message for missing type mapper

pull/23630/head
maliming 5 months ago
parent
commit
54ad1ee666
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 34
      framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs

34
framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs

@ -9,7 +9,6 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Data;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Reflection;
namespace Volo.Abp.Mapperly;
@ -62,8 +61,7 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider
return destination;
}
throw new AbpException($"No {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpMapperlyMapper<TSource, TDestination>))} or" +
$" {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpReverseMapperlyMapper<TSource, TDestination>))} was found");
throw GetNoMapperFoundException<TSource, TDestination>();
}
public virtual TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
@ -95,8 +93,34 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider
return destination;
}
throw new AbpException($"No {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpMapperlyMapper<TSource, TDestination>))} or" +
$" {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpReverseMapperlyMapper<TSource, TDestination>))} was found");
throw GetNoMapperFoundException<TSource, TDestination>();
}
protected virtual AbpException GetNoMapperFoundException<TSource, TDestination>()
{
var newLine = Environment.NewLine;
var message = "No type mapper class was found for the given source and destination types." +
newLine +
newLine +
"Mapping types:" +
newLine +
$"{typeof(TSource).Name} -> {typeof(TDestination).Name}" +
newLine +
$"{typeof(TSource).FullName} -> {typeof(TDestination).FullName}" +
newLine +
newLine +
"Define a mapping class to resolve this issue:" +
newLine +
" - Use MapperBase<TSource, TDestination> for one-way mapping." +
newLine +
" - Use TwoWayMapperBase<TDestination, TSource> for two-way mapping." +
newLine +
newLine +
"See the Mapperly documentation for details:" +
newLine +
"https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration";
return new AbpException(message);
}
protected virtual bool TryToMapCollection<TSource, TDestination>(TSource source, TDestination? destination, out TDestination collectionResult)

Loading…
Cancel
Save