本文整理汇总了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);
}
}