public bool TryUpdate(CultureInfo cultureInfo) { if (!Culture.NameEquals(cultureInfo, this.culture)) { lock (this.gate) { if (!Culture.NameEquals(cultureInfo, this.culture)) { this.culture = cultureInfo; var newValue = Translator.Translate( this.translation.resourceManager, this.translation.Key, cultureInfo, this.translation.ErrorHandling); var changed = newValue != this.value; this.value = newValue; return(changed); } return(false); } } return(false); }
public bool TryGetValue(CultureInfo key, [MaybeNullWhen(false)] out string?value) { foreach (var keyValuePair in this.translations) { if (Culture.NameEquals(keyValuePair.Key, key)) { value = keyValuePair.Value; return(true); } } value = null; return(false); }
internal bool TryUpdate(CultureInfo cultureInfo) { if (ShouldUpdate()) { lock (this.gate) { if (ShouldUpdate()) { this.culture = cultureInfo; var newValue = Translator.Translate( this.translation.resourceManager, this.translation.Key, cultureInfo, this.translation.ErrorHandling); var changed = newValue != this.value; this.value = newValue; return(changed); } return(false); } } return(false); bool ShouldUpdate() { if (cultureInfo is null && this.culture is null) { return(false); } if (cultureInfo is null || this.culture is null) { return(true); } return(!Culture.NameEquals(cultureInfo, this.culture)); } }
public bool ContainsKey(CultureInfo key) => this.translations.Any(x => Culture.NameEquals(x.Key, key));