internal static bool IsValidForNestedStructure(this DictionaryModel model) { DictionaryModel parentModel = model.GetParentModel(); if (parentModel == null) { return(true); } string[] itemKeyParts = model.GetItemKey().Split('.'); string[] parentItemKeyParts = parentModel.GetItemKey().Split('.') ?? new string[0]; bool equal = itemKeyParts.Length - parentItemKeyParts.Length == 1 && !string.IsNullOrWhiteSpace(itemKeyParts.Last()); if (!equal) { return(false); } if (!parentModel.IsValidForNestedStructure()) { return(false); } for (int i = 0; i < parentItemKeyParts.Length; i++) { equal = parentItemKeyParts[i] == itemKeyParts[i]; if (!equal) { break; } } return(equal); }
internal static bool IsRootModel(this DictionaryModel model, bool useNestedStructure) { return(model.GetParentModel() == null || !useNestedStructure || !model.IsValidForNestedStructure()); }
internal static bool RenderParentModel(this DictionaryModel model, bool useNestedStructure) { return(useNestedStructure && model.IsValidForNestedStructure()); }