private static JToken CreateJValueParentsIfNeeded(this FieldView self, JToken currentLevel) { if (self.IsInChildObject()) // Navigate down to the correct child JObject { string[] parents = self.fullPath.Split("."); for (int i = 0; i < parents.Length - 1; i++) { string fieldName = parents.ElementAt(i); var child = GetChildJToken(currentLevel, fieldName); if (child == null) { if (int.TryParse(parents.ElementAt(i + 1), out int _)) { currentLevel[fieldName] = new JArray(); } else { currentLevel[fieldName] = new JObject(); } } currentLevel = child; AssertV2.IsNotNull(currentLevel, $"rootModel (p='{fieldName}', child={child}"); } } return(currentLevel); }
public static JToken GetJParent(this FieldView self, JToken rootModel) { if (self.IsInChildObject()) // Navigate down to the correct child JObject { string[] parents = self.fullPath.Split("."); foreach (string parent in parents.Take(parents.Length - 1)) { rootModel = GetChildJToken(rootModel, parent); } } return(rootModel); }