Example #1
0
 private void Foo(XmlReader reader)
 {
     reader.Read();
     Bar(reader.ReadSubtree());
 }
Example #2
0
    private dynamic _ParseValue(XmlReader reader)
    {
        string strToken;

        if (_GetToken(reader, out strToken))
        {
            switch (strToken.ToLower())
            {
                case "true":
                    return true;

                case "false":
                    return false;

                case "string":
                    return reader.ReadString();

                case "date":
                    return DateTime.Parse(reader.ReadString());

                case "integer":
                    return Int64.Parse(reader.ReadString());

                case "dict":
                {
                    XmlReader sub = reader.ReadSubtree();
                    sub.MoveToContent();

                    PropertyList dict = new PropertyList();
                    dict._ParseDictionary(sub);

                    return dict;
                }

                case "array":
                {
                    XmlReader sub = reader.ReadSubtree();
                    sub.MoveToContent();

                    List<PropertyList> list = new List<PropertyList>();
                    while (_NextToken(sub))
                    {
                        string strSubToken;
                        if (_GetToken(reader, out strSubToken) && strSubToken.ToLower() == "dict")
                        {
                            XmlReader subDict = reader.ReadSubtree();
                            subDict.MoveToContent();

                            PropertyList dict = new PropertyList();
                            dict._ParseDictionary(subDict);
                            list.Add(dict);
                        }
                        else
                        {
                            throw new FormatException("Invalid array -- we only support dictionaries");
                        }
                    }

                    return list;
                }

                case "data":
        // TODO: we silently eat "data" elements, eventaully translate these into a object
                    break;

                default:
                {
                    throw new FormatException("Invalid type: " + reader.LocalName.ToLower());
                }
            }
        }

        return null;
    }