XmlArrayItemAttribute.NestingLevel Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Etkilediği XML öğelerinin XmlArrayItemAttribute hiyerarşisindeki düzeyi alır veya ayarlar.
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
Özellik Değeri
Bir dizi dizisindeki dizin kümesinin sıfır tabanlı dizini.
Örnekler
Aşağıdaki örnek bir dizi dizisine üç XmlArrayItemAttribute öznitelik uygular. Her özniteliğin hangi dizilere uygulanacağını belirtmek için özelliği dizilerin NestingLevel dizinine ayarlanır.
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);
}
}
Açıklamalar
XML belgesi, XML öğelerinin hiyerarşilerini içerebilir. Böyle bir hiyerarşiyi temsil etmek için bir dizi kullanılır. Böyle bir dizide, her dizin hiyerarşideki bir düzeyi temsil eder. Bu nedenle özelliği NestingLevel yalnızca dizi XmlArrayItemAttribute dizisi döndüren bir alana uygulama sırasında kullanılır.
özniteliğini uygularken, özniteliğini ayarlayarak NestingLevelhangi hiyerarşi düzeyini etkileyeceğini belirtin. İlk dizin her zaman 0 değerine sahiptir; bu nedenle, ilk dizi dizinine değeri olmayan NestingLevel bir XmlArrayItemAttribute değerini ayarlamak NestingLevel isteğe bağlıdır. Yalnızca sonraki XmlArrayItemAttribute nesneler belirtilen değerleri gerektirir NestingLevel (1, 2, 3 vb.).