Exemple #1
0
            internal void CreateKeysForCultures(IEnumerable <CultureInfo> cultures)
            {
                if ((cultures?.Any() != true || cultures.All(this.culturesAndKeys.ContainsKey)) && this.culturesAndKeys.ContainsKey(CultureInfo.InvariantCulture))
                {
                    return;
                }

                // I don't remember if this cloning solves a problem or if it is some old thing.
                using (var clone = new ResourceManagerClone(this.resourceManager))
                {
                    if (clone.ResourceManager == null)
                    {
                        return;
                    }

                    var hasAddedNeutral = false;
                    lock (this.culturesAndKeys)
                    {
                        foreach (var culture in cultures)
                        {
                            hasAddedNeutral |= culture.IsInvariant();
                            using (var resourceSet = clone.ResourceManager.GetResourceSet(culture, createIfNotExists: true, tryParents: false))
                            {
                                if (resourceSet == null)
                                {
                                    this.culturesAndKeys.TryAdd(culture, null);
                                }
                                else
                                {
                                    var keys = ReadOnlySet.Create(resourceSet.OfType <DictionaryEntry>().Select(x => x.Key).OfType <string>());
                                    this.allKeys.UnionWith(keys);
                                    this.culturesAndKeys.TryAdd(culture, keys);
                                }
                            }
                        }

                        if (!hasAddedNeutral)
                        {
                            using (var resourceSet = clone.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: false))
                            {
                                if (resourceSet == null)
                                {
                                    this.culturesAndKeys.TryAdd(CultureInfo.InvariantCulture, null);
                                }
                                else
                                {
                                    var keys = ReadOnlySet.Create(resourceSet.OfType <DictionaryEntry>().Select(x => x.Key).OfType <string>());
                                    this.allKeys.UnionWith(keys);
                                    this.culturesAndKeys.TryAdd(CultureInfo.InvariantCulture, keys);
                                }
                            }
                        }
                    }
                }
            }
Exemple #2
0
            private ReadOnlySet <string>?CreateKeysForCulture(CultureInfo culture)
            {
                // I don't remember if this cloning solves a problem or if it is some old thing.
                using var clone = new ResourceManagerClone(this.resourceManager);

                using var resourceSet = clone.ResourceManager?.GetResourceSet(culture, createIfNotExists: true, tryParents: false);
                if (resourceSet is null)
                {
                    return(null);
                }

                var keys = ReadOnlySet.Create(resourceSet.OfType <DictionaryEntry>().Select(x => x.Key).OfType <string>());

                this.allKeys.UnionWith(keys);
                return(keys);
            }