private void WriteKey(XElement xe, TextWriter writer) { var key = XUtils.GetKey(xe); if (this.version >= TomlVersion.V04 && !IsValidBareKey(key)) { WriteBasicString(key, writer); } else { writer.Write(key); } writer.Write(" = "); }
private string GetFullName(XElement xe) { var s = new Stack <string>(); while (xe.Parent != null) { if (XUtils.GetTypeAttr(xe.Parent) != "array") { var key = XUtils.GetKey(xe); if (this.version >= TomlVersion.V04 && !IsValidBareKey(key)) { key = CreateBasicString(key); } s.Push(XUtils.GetKey(xe)); } xe = xe.Parent; } return(string.Join(".", s)); }
private IEnumerable <KeyValuePair <string, object> > ToKvpEnumerable() { return(this.element.Elements().Select(xe => new KeyValuePair <string, object>(XUtils.GetKey(xe), ToValue(xe)))); }
public override bool TryConvert(ConvertBinder binder, out object result) { if (binder.Type.IsAssignableFrom(typeof(List <object>))) { result = this.ToEnumerable().ToList(); return(true); } if (binder.Type.IsAssignableFrom(typeof(ArrayList))) { var al = new ArrayList(); foreach (var o in this.ToEnumerable()) { al.Add(o); } result = al; return(true); } if (binder.Type.IsAssignableFrom(typeof(object[]))) { result = this.ToEnumerable().ToArray(); return(true); } if (!this.isArray) { if (binder.Type.IsAssignableFrom(typeof(List <KeyValuePair <string, object> >))) { result = this.ToKvpEnumerable().ToList(); return(true); } if (binder.Type.IsAssignableFrom(typeof(Dictionary <string, object>))) { var dic = new Dictionary <string, object>(); foreach (var xe in this.element.Elements()) { dic.Add(XUtils.GetKey(xe), ToValue(xe)); } result = dic; return(true); } if (binder.Type.IsAssignableFrom(typeof(Hashtable))) { var ht = new Hashtable(); foreach (var xe in this.element.Elements()) { ht.Add(XUtils.GetKey(xe), ToValue(xe)); } result = ht; return(true); } if (binder.Type.IsAssignableFrom(typeof(KeyValuePair <string, object>[]))) { result = this.ToKvpEnumerable().ToArray(); return(true); } } if (binder.Type.IsAssignableFrom(typeof(XElement))) { result = this.element; return(true); } result = null; return(false); }
private XElement Get(string key) { return(this.element.Elements() .FirstOrDefault(xe => XUtils.GetKey(xe) == key)); }