using AutoMapper;
namespace DigitalData.Core.DTO
{
public static class AutoMapperExtension
{
///
/// Maps a source object to a destination object, or throws an exception if the mapping result is null.
///
/// The source object type.
/// The destination object type.
/// The source object to map from.
/// The mapped destination object.
/// Thrown when the mapping result is null.
public static TDestination MapOrThrow(this IMapper mapper, object source)
{
return mapper.Map(source) ?? throw new AutoMapperMappingException(
$"Mapping to {typeof(TDestination).FullName} resulted in a null object. " +
"Hint: Ensure that the AutoMapper profile configuration for this mapping is correct.");
}
}
}