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


C# XmlArrayItemAttribute.NestingLevel属性代码示例

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


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

示例1: attribute

//引入命名空间
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

public class Forest{
   /* Set the NestingLevel for each array. The first 
   attribute (NestingLevel = 0) is optional. */
   [XmlArrayItem(ElementName = "tree", NestingLevel = 0)]
   [XmlArrayItem(ElementName = "branch", NestingLevel = 1)]
   [XmlArrayItem(ElementName = "leaf",NestingLevel = 2)]
   public string[][][] TreeArray;
}

public class Test{
   public static void Main(){
      Test t = new Test();
      t.SerializeObject("Tree.xml");
   }
   private void SerializeObject(string filename){
      XmlSerializer serializer = 
      new XmlSerializer(typeof(Forest));

      Forest f = new Forest();
      string[][][] myTreeArray = new string[2] [][];

      string[][]myBranchArray1= new string[1][];
      myBranchArray1[0]=new string[1]{"One"};
      myTreeArray[0]=myBranchArray1;

      string[][]myBranchArray2= new string[2][];
      myBranchArray2[0]=new string[2]{"One","Two"};
      myBranchArray2[1]=new string[3]{"One","Two","Three"};
      myTreeArray[1]=myBranchArray2;
   
      f.TreeArray=myTreeArray;

     serializer.Serialize(Console.Out, f);
   }
}
开发者ID:.NET开发者,项目名称:System.Xml.Serialization,代码行数:41,代码来源:XmlArrayItemAttribute.NestingLevel


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