Пример #1
0
        private IDictionary <string, object> GetResourceDictionary(string resourceDictionary)
        {
            if (!ResourceDictionaries.ContainsKey(resourceDictionary))
            {
                string fileSearchPath = string.IsNullOrWhiteSpace(SearchPath) ? Environment.CurrentDirectory : SearchPath;
                string filePath       = resourceDictionary + FileExtension;
                string fullPath       = Path.Combine(fileSearchPath, resourceDictionary + FileExtension);

                //load dictionary if exists
                if (File.Exists(fullPath))
                {
                    //load dictionary
                    var loadedDictionary = LocalizeDictionary.TryLoadDictionary(fullPath);

                    //return default
                    if (loadedDictionary != null)
                    {
                        //add loaded dictionary to cache
                        ResourceDictionaries.Add(resourceDictionary, loadedDictionary);
                    }
                }
            }

            if (ResourceDictionaries.ContainsKey(resourceDictionary))
            {
                //return requested loaded dictionary
                return(ResourceDictionaries[resourceDictionary]);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary> 
        ///     Returns the dictionary cache slot associated with the given assembly.
        /// </summary> 
        /// <param name="assembly">The desired assembly</param>
        /// <returns>The cache slot.</returns>
        private static ResourceDictionaries EnsureDictionarySlot(Assembly assembly)
        { 
            ResourceDictionaries dictionaries = null;
            if (_dictionaries != null) 
            { 
                _dictionaries.TryGetValue(assembly, out dictionaries);
            } 
            else
            {
                // We will be caching data, create the cache
                _dictionaries = new Dictionary<Assembly, ResourceDictionaries>(1); 
            }
 
            if (dictionaries == null) 
            {
                // Ensure the cache slot is created 
                dictionaries = new ResourceDictionaries(assembly);
                _dictionaries.Add(assembly, dictionaries);
            }
 
            return dictionaries;
        }