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

42 lines
1.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
2024-08-19 10:01:07 +05:00
namespace AsbCloudApp.Exceptions;
/// <summary>
/// Argument validation fail Exception
/// </summary>
public class ArgumentInvalidException : Exception
{
/// <summary>
2024-08-19 10:01:07 +05:00
/// словарь с ошибками, где ключ - имя аргумента, а значение - массив из одного сообщения
/// </summary>
2024-08-19 10:01:07 +05:00
public IDictionary<string, string[]> ErrorState { get; } = null!;
2024-08-19 10:01:07 +05:00
// 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 } }
};
}
2024-08-19 10:01:07 +05:00
/// <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 });
}
}