public static KspToken WriteObject(KspObject obj) { var attributes = obj.Properties.Select(p => PropertyToAttribute(obj, p)).ToList(); var tokens = obj.Children.Select(WriteObject).ToList(); return(obj.IsGlobalObject ? KspTokenGlobalExtension.CreateGlobalToken(attributes, tokens) : new KspToken(obj.Type, attributes, tokens)); }
private static int ReadToken(String[] lines, int index, out KspToken token) { if ((index + 1) >= lines.Length) { token = null; return(index); } var name = lines [index].Trim(); var isGlobalToken = name.Contains("="); var attributes = new List <KeyValuePair <String, String> > (); var tokens = new List <KspToken> (); if (!isGlobalToken) { index++; if (lines [index++] != "{") { throw new FormatException(); } } index = ReadAttributes(lines, index, attributes.Add); index = ReadTokens(lines, index, tokens.Add); if (!isGlobalToken) { if (index >= lines.Length || lines [index++] != "}") { throw new FormatException(); } token = new KspToken(name, attributes, tokens); } else { token = KspTokenGlobalExtension.CreateGlobalToken(attributes, tokens); } return(index); }