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

47 lines
1.3 KiB
C#
Raw Normal View History

using System;
namespace AsbCloudApp.Exceptions
{
/// <summary>
/// Argument validation fail Exception
/// </summary>
2022-04-11 18:00:34 +05:00
public class ArgumentInvalidException : Exception
{
2022-06-02 12:35:51 +05:00
/// <summary>
/// название аргумента
/// </summary>
2023-02-27 10:33:59 +05:00
public string ParamName { get; } = string.Empty;
2022-06-02 12:35:51 +05:00
/// <summary>
/// конструктор
/// </summary>
/// <param name="message"></param>
/// <param name="paramName"></param>
2023-02-27 10:33:59 +05:00
public ArgumentInvalidException(string message, string paramName)
2022-04-11 18:00:34 +05:00
: base(message)
{
ParamName = paramName;
}
2022-06-02 12:35:51 +05:00
/// <summary>
/// преобразование в объект валидации
/// </summary>
/// <returns></returns>
public object ToValaidationErrorObject()
=> MakeValidationError(ParamName, Message);
2022-06-02 12:35:51 +05:00
/// <summary>
/// фабрика объекта валидации
/// </summary>
/// <param name="paramName"></param>
/// <param name="errors"></param>
/// <returns></returns>
public static object MakeValidationError(string paramName, params string[] errors)
=> new
{
name = paramName,
2022-06-02 12:35:51 +05:00
errors,
};
}
}