XmlArrayItemAttribute.NestingLevel 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 影響的 XmlArrayItemAttribute XML 元素階層層級。
public:
property int NestingLevel { int get(); void set(int value); };
public int NestingLevel { get; set; }
member this.NestingLevel : int with get, set
Public Property NestingLevel As Integer
屬性值
一組索引在陣列陣列中以零為基礎的索引。
範例
以下範例將三個 XmlArrayItemAttribute 屬性應用於陣列陣列。 為了指定每個屬性適用在哪個陣列,屬性 NestingLevel 會設定為陣列的索引。
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);
}
}
備註
XML 文件可以包含 XML 元素的階層結構。 為了表示這種階層結構,會使用陣列陣列。 在這樣的陣列中,每個索引代表階層中的一個層級。 因此,該 NestingLevel 性質僅在對回傳陣列陣列的欄位應用 a XmlArrayItemAttribute 時使用。
套用屬性時,請設定屬性影響的階層層 NestingLevel級。 第一個指標的值總是為 0;因此,設定其 NestingLevel --XmlArrayItemAttributean 是可選NestingLevel的,則套用在第一個陣列索引上。 只有後續 XmlArrayItemAttribute 物件需要 NestingLevel 指定值(如 1、2、3 等)。