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