当前位置: 首页>>代码示例>>C#>>正文


C# XDocument.Dictionary方法代码示例

本文整理汇总了C#中System.Xml.Linq.XDocument.Dictionary方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.Dictionary方法的具体用法?C# XDocument.Dictionary怎么用?C# XDocument.Dictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XDocument的用法示例。


在下文中一共展示了XDocument.Dictionary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: dictionary_xml_reader

    public void dictionary_xml_reader()
    {
      Assert.Throws<ArgumentNullException>(() => ((XmlReader)null).Dictionary());

      var xml = new XDocument(
        new XElement("Articles",
          new XElement("Article",
            new XComment("Comment"),
            new XAttribute("Id", "id"),
            new XElement("Name", "name"),
            new XElement("Date", DateTime.MaxValue),
            new XElement("Description", new XCData("description")),
            new XElement("Tags",
              new XElement("Tag", "tag1"),
              new XElement("Tag", "tag2")))));
      var xmlDictionary = xml.Dictionary();

      IDictionary<string, object> dictionary;
      using (var reader = new StringReader(xml.ToString()).XmlReader(true))
      {
        dictionary = reader.Dictionary();
        Assert.True(dictionary.Keys.SequenceEqual(xmlDictionary.Keys));
      }

      var xmlReader = new StringReader(xml.ToString()).XmlReader(true);
      dictionary = xmlReader.Dictionary();
      Assert.False(xmlReader.Read());
      Assert.True(dictionary.Keys.SequenceEqual(xmlDictionary.Keys));
    }
开发者ID:prokhor-ozornin,项目名称:Catharsis.NET.Commons,代码行数:29,代码来源:XmlExtensionsTest.cs

示例2: dictionary_x_document

    public void dictionary_x_document()
    {
      Assert.Throws<ArgumentNullException>(() => ((XDocument)null).Dictionary());

      var xml = new XDocument(
        new XElement("Articles",
          new XElement("Article",
            new XComment("Comment"),
            new XAttribute("Id", "id"),
            new XElement("Name", "name"),
            new XElement("Date", DateTime.MaxValue),
            new XElement("Description", new XCData("description")),
            new XElement("Notes", string.Empty),
            new XElement("Tags",
            new XElement("Tag", "tag1"),
            new XElement("Tag", "tag2")))));
      var dictionary = xml.Dictionary();
      Assert.Equal(1, dictionary.Keys.Count);
      Assert.True(dictionary.ContainsKey("Articles"));
      var article = dictionary["Articles"].To<IDictionary<string, object>>()["Article"].To<IDictionary<string, object>>();
      Assert.Equal(6, article.Keys.Count);
      Assert.False(article.ContainsKey("Comment"));
      Assert.Equal("id", article["Id"].ToString());
      Assert.Equal("name", article["Name"].ToString());
      Assert.Equal(DateTime.MaxValue.RFC1121(), article["Date"].ToString().ToDateTime().RFC1121());
      Assert.Equal("description", article["Description"].ToString());
      Assert.Null(article["Notes"]);
      var tags = article["Tags"].To<IDictionary<string, object>>();
      Assert.Equal(1, tags.Keys.Count);
      Assert.Equal("tag2", tags["Tag"].ToString());
    }
开发者ID:prokhor-ozornin,项目名称:Catharsis.NET.Commons,代码行数:31,代码来源:XmlExtensionsTest.cs


注:本文中的System.Xml.Linq.XDocument.Dictionary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。