コード例 #1
0
        public IList <string> GetAllResourceStrings(CultureInfo culture, bool throwOnMissing)
        {
            var cacheKey = GetResourceCacheKey(culture);

            return(_resourceNamesCache.GetOrAdd(cacheKey, _ =>
            {
                // We purposly don't dispose the ResourceSet because it causes an ObjectDisposedException when you try to read the values later.
                var resourceSet = _resourceManager.GetResourceSet(culture, createIfNotExists: true, tryParents: false);
                if (resourceSet == null)
                {
                    if (throwOnMissing)
                    {
                        throw new MissingManifestResourceException(Resources.FormatLocalization_MissingManifest(GetResourceName(culture)));
                    }
                    else
                    {
                        return null;
                    }
                }

                var names = new List <string>();
                foreach (DictionaryEntry entry in resourceSet)
                {
                    names.Add((string)entry.Key);
                }

                return names;
            }));
        }
コード例 #2
0
        private IList <string> GetResourceNamesForCulture(CultureInfo culture)
        {
            var resourceStreamName = GetResourceStreamName(culture);

            var cacheKey = $"assembly={_resourceAssemblyWrapper.FullName};resourceStreamName={resourceStreamName}";

            var cultureResourceNames = _resourceNamesCache.GetOrAdd(cacheKey, _ =>
            {
                using (var cultureResourceStream = _resourceAssemblyWrapper.GetManifestResourceStream(resourceStreamName))
                {
                    if (cultureResourceStream == null)
                    {
                        return(null);
                    }

                    using (var resources = new ResourceReader(cultureResourceStream))
                    {
                        var names = new List <string>();
                        foreach (DictionaryEntry entry in resources)
                        {
                            var resourceName = (string)entry.Key;
                            names.Add(resourceName);
                        }
                        return(names);
                    }
                }
            });

            return(cultureResourceNames);
        }
コード例 #3
0
        public IList <string> GetAllResourceStrings(CultureInfo culture, bool throwOnMissing)
        {
            var cacheKey = GetResourceCacheKey(culture);

            return(_resourceNamesCache.GetOrAdd(cacheKey, _ =>
            {
                var assembly = GetAssembly(culture);
                if (assembly == null)
                {
                    return ThrowOrNull(culture, throwOnMissing);
                }

                var resourceStreamName = GetResourceName(culture);
                using (var resourceStream = assembly.GetManifestResourceStream(resourceStreamName))
                {
                    if (resourceStream == null)
                    {
                        return ThrowOrNull(culture, throwOnMissing);
                    }

                    using (var resources = new ResourceReader(resourceStream))
                    {
                        var names = new List <string>();
                        foreach (DictionaryEntry entry in resources)
                        {
                            var resourceName = (string)entry.Key;
                            names.Add(resourceName);
                        }
                        return names;
                    }
                }
            }));
        }
コード例 #4
0
        private IList <string> GetResourceNamesForCulture(CultureInfo culture)
        {
            var resourceStreamName = _resourceBaseName;

            if (!string.IsNullOrEmpty(culture.Name))
            {
                resourceStreamName += "." + culture.Name;
            }
            resourceStreamName += ".resources";

            var cacheKey = $"assembly={_resourceAssemblyWrapper.FullName};resourceStreamName={resourceStreamName}";

            var cultureResourceNames = _resourceNamesCache.GetOrAdd(cacheKey, _ =>
            {
                var names = new List <string>();
                using (var cultureResourceStream = _resourceAssemblyWrapper.GetManifestResourceStream(resourceStreamName))
                    using (var resources = new ResourceReader(cultureResourceStream))
                    {
                        foreach (DictionaryEntry entry in resources)
                        {
                            var resourceName = (string)entry.Key;
                            names.Add(resourceName);
                        }
                    }

                return(names);
            });

            return(cultureResourceNames);
        }
コード例 #5
0
 private IList <string> GetResourceNamesFromCulture(CultureInfo currentCulture)
 {
     return(_resourceNamesCache.GetOrAdd(
                currentCulture.Name,
                n => _localizedStringManager.GetLocalizedStringKeys(n).GetAwaiter().GetResult().ToList()));
 }