DD.WellWorkover.Cloud/AsbCloudApp/Exceptions/ArgumentInvalidException.cs
2024-08-19 10:01:07 +05:00

42 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 });
}
}