示例#1
0
        public LanguagesConfig Set(LanguageConfig config)
        {
            Guard.NotNull(config, nameof(config));

            return(new LanguagesConfig(languages.SetItem(config.Language, config), Master?.Language == config.Language ? config : Master));
        }
示例#2
0
        private LanguagesConfig(ImmutableDictionary <Language, LanguageConfig> languages, LanguageConfig master, bool checkMaster = true)
        {
            if (checkMaster)
            {
                this.master = master ?? throw new InvalidOperationException("Config has no master language.");
            }

            foreach (var languageConfig in languages.Values)
            {
                foreach (var fallback in languageConfig.LanguageFallbacks)
                {
                    if (!languages.ContainsKey(fallback))
                    {
                        var message = $"Config for language '{languageConfig.Language.Iso2Code}' contains unsupported fallback language '{fallback.Iso2Code}'";

                        throw new InvalidOperationException(message);
                    }
                }
            }

            this.languages = languages;
        }
示例#3
0
 public bool TryGetConfig(Language language, out LanguageConfig config)
 {
     return(languages.TryGetValue(language, out config));
 }
示例#4
0
        public void Set(LanguageConfig config)
        {
            Guard.NotNull(config, nameof(config));

            state = new State(state.Languages.SetItem(config.Language, config), state.Master?.Language == config.Language ? config : state.Master);
        }
示例#5
0
 public bool TryGetConfig(Language language, [MaybeNullWhen(false)] out LanguageConfig config)
 {
     return(languages.TryGetValue(language, out config !));
 }
示例#6
0
        private LanguagesConfig Create(ArrayDictionary <Language, LanguageConfig> newLanguages, LanguageConfig newMaster)
        {
            if (newLanguages.EqualsDictionary(languages, EqualityComparer <Language> .Default, DeepComparer <LanguageConfig> .Instance) && newMaster.Language.Equals(master.Language))
            {
                return(this);
            }

            return(new LanguagesConfig(newLanguages, newMaster));
        }