| | | 1 | | #region Usings |
| | | 2 | | using System.Globalization; |
| | | 3 | | using System.Resources; |
| | | 4 | | #endregion |
| | | 5 | | |
| | | 6 | | namespace ZhEaIsNsAaBn.Utilities; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Reads error messages from <c>.resx</c> files: resource name = <see cref="Error.Code"/>. The neutral file (<c>Errors. |
| | | 10 | | /// English; each language adds its own (<c>Errors.ar.resx</c>, <c>Errors.fr.resx</c>). |
| | | 11 | | /// </summary> |
| | | 12 | | /// <example> |
| | | 13 | | /// <code> |
| | | 14 | | /// var source = new ResourceErrorMessageSource( AppErrors.ResourceManager ); // AppErrors = the .resx designer class |
| | | 15 | | /// </code> |
| | | 16 | | /// </example> |
| | | 17 | | public sealed class ResourceErrorMessageSource : IErrorMessageSource |
| | | 18 | | { |
| | | 19 | | private readonly ResourceManager _resourceManager; |
| | | 20 | | |
| | | 21 | | |
| | | 22 | | /// <summary>Creates the source.</summary> |
| | | 23 | | /// <param name="resourceManager">The resources, e.g. the <c>ResourceManager</c> of a <c>.resx</c> designer class.</ |
| | | 24 | | /// <exception cref="ArgumentNullException"><paramref name="resourceManager"/> is <see langword="null"/>.</exception |
| | 0 | 25 | | public ResourceErrorMessageSource( ResourceManager resourceManager ) |
| | | 26 | | { |
| | 0 | 27 | | ArgumentNullException.ThrowIfNull( resourceManager ); |
| | | 28 | | |
| | 0 | 29 | | _resourceManager = resourceManager; |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | /// <exception cref="ArgumentNullException"><paramref name="code"/> or <paramref name="culture"/> is <see langword=" |
| | | 35 | | public string? Find( string code, CultureInfo culture ) |
| | | 36 | | { |
| | 0 | 37 | | ArgumentNullException.ThrowIfNull( code ); |
| | 0 | 38 | | ArgumentNullException.ThrowIfNull( culture ); |
| | | 39 | | |
| | 0 | 40 | | return _resourceManager.GetResourceSet( culture, createIfNotExists: true, tryParents: false )?.GetString( code ) |
| | | 41 | | } |
| | | 42 | | } |