private dynamic ParseValue(XElement val) { switch (val.Name.ToString()) { case "string": return(val.Value); case "integer": return(int.Parse(val.Value)); case "real": return(val.Value.ToFloat()); case "true": return(true); case "false": return(false); case "dict": DynamicPList plist = new DynamicPList(); Parse(plist, val.Elements()); return(plist); case "array": List <dynamic> list = ParseArray(val.Elements()); return(list); case "key": return(val.Value.ToString()); default: throw new ArgumentException("Unsupported"); } }
private void Parse(DynamicPList dict, IEnumerable <XElement> elements) { for (int i = 0; i < elements.Count(); i += 2) { XElement key = elements.ElementAt(i); XElement val = elements.ElementAt(i + 1); dict[key.Value] = ParseValue(val); } }