public void Load(JObject dataFromFile) { foreach (KeyValuePair <string, JToken> child in dataFromFile) { INavigationElement toAdd; if (child.Value.Type == JTokenType.String) { var nameToUse = child.Key; var isIndexElement = child.Key == "__index"; if (isIndexElement) { nameToUse = this.Name; } toAdd = new SimpleNavigationElement() { Name = nameToUse, Value = child.Value.ToObject <string>(), IsIndexElement = isIndexElement }; } else { var subLevel = new NavigationLevel() { Name = child.Key, IsRoot = false }; subLevel.Load((JObject)child.Value); toAdd = subLevel; } toAdd.ParentContainer = this; this.Value.Add(toAdd); } }
public void Load(JObject dataFromFile) { foreach (KeyValuePair <string, JToken> child in dataFromFile) { INavigationElement toAdd; if (child.Value.Type == JTokenType.String) { var nameToUse = child.Key; var isIndexElement = child.Key == "__index"; if (isIndexElement) { nameToUse = this.Name; } var childValue = child.Value.ToObject <string>(); if (childValue.EndsWith("**")) { var path = childValue.Replace("**", string.Empty) .Replace('\\', Path.DirectorySeparatorChar) .Replace('/', Path.DirectorySeparatorChar); if (!Path.IsPathRooted(path)) { path = Path.Combine(_rootDirectory, path); } toAdd = CreateGeneratedLevel(path); toAdd.Name = nameToUse; } else { toAdd = new SimpleNavigationElement { Name = nameToUse, Value = childValue, IsIndexElement = isIndexElement }; } } else { var subLevel = new NavigationLevel(_rootDirectory) { Name = child.Key, IsRoot = false }; subLevel.Load((JObject)child.Value); toAdd = subLevel; } toAdd.ParentContainer = this; this.Value.Add(toAdd); } }