public static string SelectItemText(this JSONBlockItem block, string selector) { JSONParseItem item = SelectItem(block, selector); if (item != null) { string text = item.Text.Replace("\\\"", "\""); return(text.Substring(1, text.Length - 2)); } return(string.Empty); }
public static JSONParseItem SelectItem(this JSONBlockItem block, string selector) { string[] paths = selector.Split('/'); string path = paths[0]; var items = from b in block.BlockItemChildren let m = b as JSONMember where m != null && m.UnquotedNameText == path select m.Value; JSONParseItem item = items.ElementAtOrDefault(0); JSONObject obj = item as JSONObject; if (obj != null) { return(SelectItem(obj, string.Join("/", paths.Skip(1)))); } return(item); }
public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context) { JSONMember member = context.ContextItem as JSONMember; if (member == null || member.Name == null) { yield break; } var vocabularies = VocabularyFactory.GetVocabularies(member); if (!vocabularies.Any()) { yield break; } JSONBlockItem block = member.FindType <JSONBlockItem>(); var visitor = new JSONItemCollector <JSONMember>(); block.Accept(visitor); JSONMember ldType = visitor.Items.FirstOrDefault(m => m.Name != null && m.Value != null && m.Name.Text == "\"@type\""); if (ldType == null) { yield break; } string value = ldType.Value.Text.Trim('"'); foreach (IVocabulary vocab in vocabularies.Where(v => v.Cache.ContainsKey(value))) { foreach (Entry entry in vocab.Cache[value]) { yield return(new JSONCompletionEntry(entry.Name, "\"" + entry.Name + "\"", null, entry.Glyph, "iconAutomationText", true, context.Session as ICompletionSession)); } } }