次の方法で共有


XmlArrayItemAttribute.NestingLevel プロパティ

定義

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

プロパティ値

複数の配列内の 1 つの配列のインデックスのセットの 0 から始まるインデックス番号。

次の例では、配列の配列に 3 つの 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 です。したがって、値のない NestingLevel -NestingLevel-an XmlArrayItemAttribute を最初の配列インデックスに適用するように設定することは省略可能です。 後続 XmlArrayItemAttribute のオブジェクトのみが値を指定する必要があります NestingLevel (1、2、3 など)。

適用対象