DD.WellWorkover.Cloud/AsbCloudApp/Exceptions/ArgumentInvalidException.cs

47 lines
1.3 KiB
C#

using System;
namespace AsbCloudApp.Exceptions
{
/// <summary>
/// Argument validation fail Exception
/// </summary>
public class ArgumentInvalidException : Exception
{
/// <summary>
/// название аргумента
/// </summary>
public string ParamName { get; } = string.Empty;
/// <summary>
/// конструктор
/// </summary>
/// <param name="message"></param>
/// <param name="paramName"></param>
public ArgumentInvalidException(string message, string paramName)
: base(message)
{
ParamName = paramName;
}
/// <summary>
/// преобразование в объект валидации
/// </summary>
/// <returns></returns>
public object ToValaidationErrorObject()
=> MakeValidationError(ParamName, Message);
/// <summary>
/// фабрика объекта валидации
/// </summary>
/// <param name="paramName"></param>
/// <param name="errors"></param>
/// <returns></returns>
public static object MakeValidationError(string paramName, params string[] errors)
=> new
{
name = paramName,
errors,
};
}
}