KNFoundation.KNBundle.CacheStrings C# (CSharp) Method

CacheStrings() private method

private CacheStrings ( Assembly assembly ) : void
assembly System.Reflection.Assembly
return void
        private void CacheStrings(Assembly assembly)
        {
            // Erase existing caches

            stringsCache.Clear();

            // Pre-cache strings files.

            foreach (string stringsFilePath in PathsForResourcesOfType("strings")) {

                Dictionary<string, string> stringsTable = AttemptToParseStringsFile(stringsFilePath);
                if (stringsTable.Keys.Count > 0) {
                    stringsCache.Add(Path.GetFileNameWithoutExtension(stringsFilePath), stringsTable);
                }
            }

            // Also pre-cache any strings in the assembly's embedded resource files

            if (assembly == null) {
                if (InfoDictionary.ContainsKey(KNBundleExecutableKey)) {
                    assembly = Assembly.LoadFrom(Path.Combine(BundlePath, (string)InfoDictionary.ValueForKey(KNBundleExecutableKey)));
                } else {
                    assembly = Assembly.GetEntryAssembly();
                }
            }

            if (assembly != null) {
                string[] resourceNames = assembly.GetManifestResourceNames();

                if (resourceNames != null) {
                    foreach (string resourcesFileName in resourceNames) {

                        string tableName = resourcesFileName.Replace(".resources", "");
                        Dictionary<string, string> stringsTable = ExtractStringsFromResourcesFile(resourcesFileName, assembly);

                        if (stringsTable.ContainsKey(KNStringTableRepresentedClassKey)) {
                            tableName = (string)stringsTable.ValueForKey(KNStringTableRepresentedClassKey);
                        }

                        if (stringsCache.ContainsKey(tableName) && stringsTable.Count > 0) {
                            // Replace existing if we have new strings
                            stringsCache.Remove(tableName);
                        }

                        if (stringsTable.Count > 0) {
                            stringsCache.Add(tableName, stringsTable);
                        }
                    }
                }
            }
        }