Developer 02 36889df1c0 Funktion: Erweiterung von IServiceMessage mit Methoden zur Nachrichtenverwaltung
- Hinzufügen von Erweiterungsmethoden zu IServiceMessage für das Hinzufügen von Client-, Trace-, Debug-, Informations-, Warn-, Fehler- und kritischen Nachrichten.
- Einbeziehung von Methoden für direkte Nachrichten und auf Enum basierende Schlüssel, die Lokalisierung und benutzerdefinierte Formatierung unterstützen.
2024-04-19 14:08:33 +02:00

23 lines
1.1 KiB
C#

using AutoMapper;
namespace DigitalData.Core.Application
{
public static class AutoMapperExtension
{
/// <summary>
/// Maps a source object to a destination object, or throws an exception if the mapping result is null.
/// </summary>
/// <typeparam name="TSource">The source object type.</typeparam>
/// <typeparam name="TDestination">The destination object type.</typeparam>
/// <param name="source">The source object to map from.</param>
/// <returns>The mapped destination object.</returns>
/// <exception cref="MappingResultNullException">Thrown when the mapping result is null.</exception>
public static TDestination MapOrThrow<TDestination>(this IMapper mapper, object source)
{
return mapper.Map<TDestination>(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.");
}
}
}