private void PopulateFieldWithSubfields(IField field, SortedList <string, IField> elements, SortedList <string, IField> groups, SortedList <string, SortedList <string, string> > elementsGroups) { SortedList <string, string> sortedList = elementsGroups[field.Name]; foreach (string current in sortedList.Keys) { if (elements.ContainsKey(current)) { field.AddSubfield(elements[current]); } else { this.PopulateFieldWithSubfields(groups[current], elements, groups, elementsGroups); field.AddSubfield(groups[current]); } } }