initial commit
This commit is contained in:
36
DigitalData.Core.Exceptions/MappingResultNullException.cs
Normal file
36
DigitalData.Core.Exceptions/MappingResultNullException.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using AutoMapper;
|
||||
using AutoMapper.Internal;
|
||||
|
||||
namespace DigitalData.Core.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents errors that occur during mapping when the result is unexpectedly null.
|
||||
/// This exception is specifically used to indicate that an AutoMapper mapping operation
|
||||
/// resulted in a null object, which may suggest a misconfiguration or an issue with the source data.
|
||||
/// </summary>
|
||||
public class MappingResultNullException : AutoMapperMappingException
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MappingResultNullException"/> class with the source and destination types causing the error.
|
||||
/// </summary>
|
||||
/// <param name="sourceType">The source type of the mapping operation.</param>
|
||||
/// <param name="destinationType">The destination type of the mapping operation.</param>
|
||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
||||
public MappingResultNullException(Type sourceType, Type destinationType, Exception? innerException = null)
|
||||
: base(FormatMessage(sourceType, destinationType), innerException, new TypePair(sourceType, destinationType))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats the exception message to include detailed information about the mapping operation that failed.
|
||||
/// </summary>
|
||||
/// <param name="sourceType">The source type involved in the mapping operation.</param>
|
||||
/// <param name="destinationType">The destination type involved in the mapping operation.</param>
|
||||
/// <returns>A formatted string containing the error message.</returns>
|
||||
private static string FormatMessage(Type sourceType, Type destinationType)
|
||||
{
|
||||
return $"Mapping from {sourceType.FullName} to {destinationType.FullName} resulted in a null object. " +
|
||||
"Hint: Ensure that the AutoMapper profile configuration for this mapping is correct.";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user