コード例 #1
0
        public TreeDoc ParseEntry(ref int i)
        {
            SkipWhiteSpace(ref i);
            if (GetChar(i) == '(')
            {
                i++;
                TreeDoc result = TreeDoc.CreateListRange(ParseList(ref i));
                if (GetChar(i) != ')')
                {
                    throw new InvalidDataException("Unexpected char " + GetChar(i) + " at " + i + " expected )");
                }
                i++;
                return(result);
            }
            else
            {
                string text = ParseString(ref i);
                SkipWhiteSpace(ref i);
                switch (GetChar(i))
                {
                case null:
                case ',':
                case ')':
                    return(TreeDoc.CreateLeaf(text));

                case ':':
                    i++;
                    string value = ParseString(ref i);
                    return(TreeDoc.CreateLeaf(text, value));

                case '(':
                    i++;
                    TreeDoc entry = TreeDoc.CreateListRange(text, ParseList(ref i));
                    SkipWhiteSpace(ref i);
                    if (GetChar(i) != ')')
                    {
                        throw new InvalidDataException("Unexpected char " + GetChar(i) + " at " + i + " expected )");
                    }
                    i++;
                    return(entry);

                default:
                    throw new InvalidDataException("Unexpected char " + GetChar(i) + " at " + i + "expected ,):(");
                }
            }
        }
コード例 #2
0
ファイル: TreeDoc.cs プロジェクト: jorik041/ChaosUtil
        public static TreeDoc ObjectToTreeDoc(object item)
        {
            if (item == null)
            {
                return(TreeDoc.CreateNull());
            }
            if (item is TreeDoc)
            {
                return((TreeDoc)item);
            }
            if (item is String)
            {
                return(TreeDoc.CreateLeaf((String)item));
            }
            Func <TreeDoc> converter = (Func <TreeDoc>)Delegate.CreateDelegate(typeof(Func <TreeDoc>), item, "ToTreeDoc", false, false);

            if (converter != null)
            {
                return(converter());
            }
            return(TreeDoc.CreateLeaf(ObjectToString(item)));
        }