internal void AddBindEnum(string[] path, int index, BindEnum bindEnum) { if (index + 1 >= path.Length) { //At lowest level, add enum if (bindTables.ContainsKey(path[index])) { throw new Exception($"Cannot add {string.Join(".", path)} ({bindEnum.Name}), a Table with that key already exists"); } else { CheckConflictingItems(path, index, bindEnum); } bindEnums[path[index]] = bindEnum; } else { CheckConflictingItems(path, index, bindEnum); BindTable nextTable; if (bindTables.TryGetValue(path[index], out nextTable)) { nextTable.AddBindEnum(path, index + 1, bindEnum); } else { //Create new table nextTable = new BindTable(path[index]); bindTables.Add(path[index], nextTable); nextTable.AddBindEnum(path, index + 1, bindEnum); } } }
/// <summary> /// Automatically create tables, etc for bind enums /// </summary> /// <param name="dict"></param> /// <param name="pathString"></param> internal static BindEnum CreateBindEnum(Dictionary <string, BindItem> dict, string pathString, Type enumType) { if (string.IsNullOrWhiteSpace(pathString)) { throw new Exception($"Path cannot be null, empty, or whitespace for path [{pathString}] Enum Type: ({enumType.Name})"); } var path = pathString.Split('.'); string root = path[0]; BindEnum bindEnum = new BindEnum(path[path.Length - 1], enumType); if (path.Length == 1) { //Simple global function if (dict.ContainsKey(root)) { throw new Exception($"Cannot add {pathString} ({enumType.Name}), a {GetItemTypeStr(dict[root])} with that key already exists"); } dict[root] = bindEnum; } else { //Recursion time if (dict.TryGetValue(root, out BindItem item)) { if (item is BindTable t) { t.AddBindEnum(path, 1, bindEnum); } else { throw new Exception($"Cannot add {pathString} ({enumType.Name}), The root key is a {GetItemTypeStr(dict[root])}"); } } else { //Create new table BindTable t = new BindTable(root); dict[root] = t; t.AddBindEnum(path, 1, bindEnum); } } return(bindEnum); }