| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="TranslatableException.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Runtime.InteropServices; |
| | | 10 | | |
| | | 11 | | namespace MyNet.Primitives.Exceptions; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Represents an exception that contains a resource key and format parameters intended for localization. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <remarks> |
| | | 17 | | /// The message passed to base <see cref="Exception"/> is formatted using the current culture and the provided parameter |
| | | 18 | | /// </remarks> |
| | | 19 | | [ComVisible(true)] |
| | | 20 | | public class TranslatableException : Exception |
| | | 21 | | { |
| | | 22 | | /// <summary> |
| | | 23 | | /// Initializes a new instance of the <see cref="TranslatableException"/> class with a specified resource key and fo |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="resourceKey">The resource key that identifies the localized message associated with this exception. |
| | | 26 | | /// <param name="parameters">The parameters to be used for formatting the resource string associated with the Resour |
| | 6 | 27 | | public TranslatableException(string resourceKey, params object?[] parameters) |
| | | 28 | | { |
| | | 29 | | ResourceKey = resourceKey; |
| | | 30 | | Parameters = parameters; |
| | 6 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Initializes a new instance of the <see cref="TranslatableException"/> class with a specified resource key, inner |
| | | 35 | | /// </summary> |
| | | 36 | | /// <param name="resourceKey">The resource key that identifies the localized message associated with this exception. |
| | | 37 | | /// <param name="innerException">The exception that is the cause of the current exception.</param> |
| | | 38 | | /// <param name="parameters">The parameters to be used for formatting the resource string associated with the Resour |
| | | 39 | | public TranslatableException(string resourceKey, Exception? innerException, params object?[] parameters) |
| | 3 | 40 | | : base(null, innerException) |
| | | 41 | | { |
| | | 42 | | ResourceKey = resourceKey; |
| | | 43 | | Parameters = parameters; |
| | 3 | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Initializes a new instance of the <see cref="TranslatableException"/> class with default values for ResourceKey |
| | | 48 | | /// </summary> |
| | 0 | 49 | | internal TranslatableException() |
| | | 50 | | { |
| | | 51 | | ResourceKey = string.Empty; |
| | | 52 | | Parameters = []; |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Initializes a new instance of the <see cref="TranslatableException"/> class with a specified error message. |
| | | 57 | | /// </summary> |
| | | 58 | | /// <param name="message">The error message that explains the reason for the exception.</param> |
| | | 59 | | internal TranslatableException(string message) |
| | 0 | 60 | | : base(message) |
| | | 61 | | { |
| | | 62 | | ResourceKey = string.Empty; |
| | | 63 | | Parameters = []; |
| | 0 | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Initializes a new instance of the <see cref="TranslatableException"/> class with a specified error message and a |
| | | 68 | | /// </summary> |
| | | 69 | | /// <param name="message">The error message that explains the reason for the exception.</param> |
| | | 70 | | /// <param name="innerException">The exception that is the cause of the current exception.</param> |
| | | 71 | | internal TranslatableException(string message, Exception innerException) |
| | 0 | 72 | | : base(message, innerException) |
| | | 73 | | { |
| | | 74 | | ResourceKey = string.Empty; |
| | | 75 | | Parameters = []; |
| | 0 | 76 | | } |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Gets the resource key that identifies the localized message associated with this exception. This key will be use |
| | | 80 | | /// </summary> |
| | | 81 | | public string ResourceKey { get; } |
| | | 82 | | |
| | | 83 | | /// <summary> |
| | | 84 | | /// Gets the parameters to be used for formatting the resource string associated with the ResourceKey. These paramet |
| | | 85 | | /// </summary> |
| | | 86 | | public IReadOnlyList<object?> Parameters { get; } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Gets the localized message by formatting the resource string associated with the ResourceKey using the provided |
| | | 90 | | /// </summary> |
| | 3 | 91 | | public override string Message => ResourceKey; |
| | | 92 | | } |
| | | 93 | | |