public static bool RenameSchemaField(string oldFieldKey, string newFieldKey, string schemaKey, Dictionary <string, object> schemaData, out string error) { bool result = true; if (!IsFieldNameValid(schemaData, newFieldKey, out error)) { result = false; } else if (schemaData.ContainsKey(newFieldKey)) { result = false; error = "Field name already exists."; } else { // Do rename RenameField(oldFieldKey, newFieldKey, schemaData); // Remove the schema key from the listbyfieldname List List <string> schemaKeyList; if (ListByFieldName.TryGetValue(oldFieldKey, out schemaKeyList)) { schemaKeyList.Remove(schemaKey); if (schemaKeyList.Count == 0) { ListByFieldName.Remove(oldFieldKey); } } // Add the schema key to the listbyfieldname List under the new field name if (ListByFieldName.TryGetValue(newFieldKey, out schemaKeyList)) { schemaKeyList.Add(schemaKey); } else { List <string> newListByFieldName = new List <string>() { schemaKey }; ListByFieldName.Add(newFieldKey, newListByFieldName); } // Rename the fields in any existing items with this schema List <string> itemKeys = GetItemsOfSchemaType(schemaKey); foreach (string itemKey in itemKeys) { Dictionary <string, object> itemData; if (AllItems.TryGetValue(itemKey, out itemData)) { RenameField(oldFieldKey, newFieldKey, itemData); } } } ItemsNeedSave |= result; SchemasNeedSave |= result; return(result); }
private static void AddFieldToListByFieldName(string fieldKey, string schemaKey) { List <string> schemaKeyList; if (ListByFieldName.TryGetValue(fieldKey, out schemaKeyList)) { schemaKeyList.Add(schemaKey); } else { schemaKeyList = new List <string>(); schemaKeyList.Add(schemaKey); ListByFieldName.Add(fieldKey, schemaKeyList); } }