forked from ddrilling/AsbCloudServer
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace AsbCloudApp.Exceptions;
|
||
|
||
/// <summary>
|
||
/// Argument validation fail Exception
|
||
/// </summary>
|
||
public class ArgumentInvalidException : Exception
|
||
{
|
||
/// <summary>
|
||
/// словарь с ошибками, где ключ - имя аргумента, а значение - массив из одного сообщения
|
||
/// </summary>
|
||
public IDictionary<string, string[]> ErrorState { get; } = null!;
|
||
|
||
// TODO: swap arguments, inherit from ArgumentException
|
||
/// <summary>
|
||
/// конструктор
|
||
/// </summary>
|
||
/// <param name="paramName"></param>
|
||
/// <param name="message"></param>
|
||
public ArgumentInvalidException(string paramName, string message)
|
||
: base(message)
|
||
{
|
||
ErrorState = new Dictionary<string, string[]>() {
|
||
{ paramName, new[]{ message } }
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// конструктор
|
||
/// </summary>
|
||
/// <param name="paramsNames"></param>
|
||
/// <param name="message"></param>
|
||
public ArgumentInvalidException(string[] paramsNames, string message)
|
||
: base(message)
|
||
{
|
||
ErrorState = paramsNames.ToDictionary(paramName => paramName, item => new[] { message });
|
||
}
|
||
}
|