XmlArrayItemAttribute.NestingLevel Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém ou define o nível em uma hierarquia de elementos XML que o XmlArrayItemAttribute afeta.
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
Valor da propriedade
O índice baseado em zero de um conjunto de índices em uma matriz de matrizes.
Exemplos
O exemplo a seguir aplica três XmlArrayItemAttribute atributos a uma matriz de matrizes. Para especificar a qual das matrizes cada atributo se aplica, a NestingLevel propriedade é definida como o índice das matrizes.
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);
}
}
Comentários
Um documento XML pode conter hierarquias de elementos XML. Para representar essa hierarquia, uma matriz de matrizes é usada. Nessa matriz, cada índice representa um nível na hierarquia. Portanto, a NestingLevel propriedade só é usada ao aplicar um XmlArrayItemAttribute campo que retorna uma matriz de matrizes.
Ao aplicar o atributo, especifique qual nível de hierarquia o atributo afeta definindo o NestingLevel. O primeiro índice sempre tem o valor de 0; portanto, é opcional definir seu NestingLevel --um XmlArrayItemAttribute sem um NestingLevel valor é aplicado ao primeiro índice de matriz. Somente os objetos subsequentes XmlArrayItemAttribute exigem NestingLevel valores especificados (como 1, 2, 3 e assim por diante).