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

43 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudApp.Exceptions
{
/// <summary>
/// Argument validation fail Exception
/// </summary>
public class ArgumentInvalidException : Exception
{
2022-06-02 12:35:51 +05:00
/// <summary>
/// словарь с ошибками, где ключ - имя аргумента, а значение - массив из одного сообщения
2022-06-02 12:35:51 +05:00
/// </summary>
public IDictionary<string, string[]> ErrorState { get; } = null!;
2024-02-12 13:58:02 +05:00
// TODO: swap arguments, inherit from ArgumentException
2022-06-02 12:35:51 +05:00
/// <summary>
/// конструктор
/// </summary>
/// <param name="paramName"></param>
2023-09-29 12:06:46 +05:00
/// <param name="message"></param>
public ArgumentInvalidException(string paramName, string message)
2022-04-11 18:00:34 +05:00
: 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 });
}
}
}