/// <summary> /// Translation.GetOrCreate(Properties.Resources.ResourceManager, nameof(Properties.Resources.SomeKey)) /// </summary> /// <param name="resourceManager"> /// The resourcemanager with the key /// </param> /// <param name="key"> /// The key to translate /// </param> /// <param name="errorHandling">Specifies how errors are handled.</param> /// <returns>A <see cref="Translation"/> that notifies when <see cref="Translator.CurrentCulture"/> changes</returns> public static Translation GetOrCreate(ResourceManager resourceManager, string key, ErrorHandling errorHandling = ErrorHandling.Inherit) { Ensure.NotNull(resourceManager, nameof(resourceManager)); Ensure.NotNull(key, nameof(key)); var rmk = new ResourceManagerAndKey(resourceManager, key, errorHandling); return Cache.GetOrAdd(rmk, x => new Translation(x.ResourceManager, x.Key, errorHandling)); }
/// <summary> /// Translation.GetOrCreate(Properties.Resources.ResourceManager, nameof(Properties.Resources.SomeKey)) /// </summary> /// <param name="resourceManager"> /// The resourcemanager with the key /// </param> /// <param name="key"> /// The key to translate /// </param> /// <param name="errorHandling">Specifies how errors are handled.</param> /// <returns>A <see cref="Translation"/> that notifies when <see cref="Translator.CurrentCulture"/> changes</returns> public static Translation GetOrCreate(ResourceManager resourceManager, string key, ErrorHandling errorHandling = ErrorHandling.Default) { Ensure.NotNull(resourceManager, nameof(resourceManager)); Ensure.NotNull(key, nameof(key)); var rmk = new ResourceManagerAndKey(resourceManager, key, errorHandling); return(Cache.GetOrAdd(rmk, x => new Translation(x.ResourceManager, x.Key, errorHandling))); }
/// <summary> /// Translation.GetOrCreate(Properties.Resources.ResourceManager, nameof(Properties.Resources.SomeKey)) /// If <paramref name="resourceManager"/> contains the resource <paramref name="key"/> an <see cref="Translation"/> is returned. /// If not a static translation is returned if error handling is not throw. /// </summary> /// <param name="resourceManager"> /// The <see cref="ResourceManager"/> with the key /// </param> /// <param name="key"> /// The key to translate /// </param> /// <param name="errorHandlingStrategy">Specifies how errors are handled.</param> /// <returns> /// A <see cref="Translation"/> that notifies when <see cref="Translator.Culture"/> changes. /// </returns> public static ITranslation GetOrCreate(ResourceManager resourceManager, string key, ErrorHandling errorHandlingStrategy = ErrorHandling.Inherit) { Ensure.NotNull(resourceManager, nameof(resourceManager)); Ensure.NotNull(key, nameof(key)); errorHandlingStrategy = errorHandlingStrategy.Coerce(); var rmk = new ResourceManagerAndKey(resourceManager, key, errorHandlingStrategy); return(Cache.GetOrAdd(rmk, x => CreateTranslation(x.ResourceManager, x.Key, errorHandlingStrategy))); }
/// <summary> /// Translation.GetOrCreate(Properties.Resources.ResourceManager, nameof(Properties.Resources.SomeKey)) /// If <paramref name="resourceManager"/> contains the resource <paramref name="key"/> an <see cref="Translation"/> is returned. /// If not a static translation is returned if error handling is not throw. /// </summary> /// <param name="resourceManager"> /// The <see cref="ResourceManager"/> with the key. /// </param> /// <param name="key"> /// The key to translate. /// </param> /// <param name="errorHandlingStrategy">Specifies how errors are handled.</param> /// <returns> /// A <see cref="Translation"/> that notifies when <see cref="Translator.Culture"/> changes. /// </returns> public static ITranslation GetOrCreate(ResourceManager resourceManager, string key, ErrorHandling errorHandlingStrategy = ErrorHandling.Inherit) { if (resourceManager is null) { throw new ArgumentNullException(nameof(resourceManager)); } if (key is null) { throw new ArgumentNullException(nameof(key)); } errorHandlingStrategy = errorHandlingStrategy.Coerce(); var rmk = new ResourceManagerAndKey(resourceManager, key, errorHandlingStrategy); return(Cache.GetOrAdd(rmk, x => CreateTranslation(x.ResourceManager, x.Key, errorHandlingStrategy))); }