public void LoadKeys(Locale loadFrom, string collectionKey) { _locale = _localeManager.Locales[_localeManager.CurrentLocale]; if(_locale.StringCollections.ContainsKey(collectionKey) == false) { _locale.StringCollections.Add(collectionKey, new StringCollection(collectionKey)); } _collection = _locale.StringCollections[collectionKey]; txtNew.RightToLeft = _locale.RightToLeft ? RightToLeft.Yes : RightToLeft.No; var enumerable = loadFrom.StringCollections[collectionKey].StringsTable.Values; foreach (var key in enumerable) { if (key.AliasedKey) continue; var item = new ListViewItem(key.Key); item.ImageKey = GetStatusIcon(collectionKey, key.Key); lstKeys.Items.Add(item); } colKey.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); chkMinorUpdate.Visible = _parentLocale == null; chkDerived.Enabled = _parentLocale != null; chkUpToDate.Visible = _parentLocale != null; btnSetModified.Visible = _parentLocale == null; }
private void LoadStringsFromTypes(IEnumerable<Type> types) { foreach (var asmType in types) { if (!asmType.IsSubclassOf(typeof (Control))) continue; var isForm = asmType.IsSubclassOf(typeof (Form)); if (isForm) { _currentForm = asmType.Name; if (_strings.ContainsKey(_currentForm)) { //This form has already been traversed continue; } var stringCollection = new StringCollection(_currentForm); _stringCollections.Add(stringCollection); _strings[_currentForm] = stringCollection; } object control; if (IsFrameworkType(asmType)) { //Only try calling the default constructor on MS-provided types try { control = Activator.CreateInstance(asmType, new object[] {}); } catch (MissingMethodException) { if (!isForm) { //We can't do anything about it, as we must hard-code each known type _failedControls.Add(asmType.Name); continue; } //Create the object without initializing it control = CreateControlWithoutConstructor(asmType); } } else { control = CreateControlWithoutConstructor(asmType); } if (control == null) { _failedControls.Add(asmType.Name); continue; //Give up already! } LoadStringsFromObject(control); foreach (var property in asmType.GetProperties()) { //We can't just use GetProperty() because it sometimes throws AmbiguousMatchException for unknown reasons //It's not like there can be two properties called "Controls" for a form now, is there? WTF, Microsoft? var collection = property.GetValue(control, null); if (!(collection is IEnumerable)) continue; foreach (var item in (IEnumerable) property.GetValue(control, null)) { if (!(item is Control)) continue; LoadStringsFromTypes(new[] {item.GetType()}); } } } }
public void Merge(StringCollection newStrings, bool overwriteExisting = true) { Merge(newStrings.StringsTable.Values, overwriteExisting); return; }