다음을 통해 공유


XmlArrayItemAttribute.NestingLevel 속성

정의

영향을 주는 XML 요소 XmlArrayItemAttribute 의 계층 구조에서 수준을 가져오거나 설정합니다.

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

속성 값

배열 배열에 있는 인덱스 집합의 인덱스(0부터 시작하는 인덱스)입니다.

예제

다음 예제에서는 배열 배열에 세 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 이 속성은 배열 배열을 반환하는 XmlArrayItemAttribute 필드에 적용할 때만 사용됩니다.

특성을 적용할 때 특성을 설정 NestingLevel하여 특성이 영향을 받는 계층 수준을 지정합니다. 첫 번째 인덱스의 값은 항상 0입니다. 따라서 첫 번째 배열 인덱스로 값이 XmlArrayItemAttribute 적용되지 않은 NestingLevel --을 설정하는 NestingLevel 것은 선택 사항입니다. 후속 XmlArrayItemAttribute 개체에만 지정된 값(1, 2, 3 등)이 필요합니다 NestingLevel .

적용 대상