XStreamingElement.Add Método

Definição

Adiciona o conteúdo especificado como filhos a isso XStreamingElement.

Sobrecargas

Nome Description
Add(Object)

Adiciona o conteúdo especificado como filhos a isso XStreamingElement.

Add(Object[])

Adiciona o conteúdo especificado como filhos a isso XStreamingElement.

Add(Object)

Adiciona o conteúdo especificado como filhos a isso XStreamingElement.

public:
 void Add(System::Object ^ content);
public void Add(object content);
member this.Add : obj -> unit
Public Sub Add (content As Object)

Parâmetros

content
Object

Conteúdo a ser adicionado ao elemento de streaming.

Exemplos

O exemplo a seguir cria um novo XStreamingElement. Em seguida, ele adiciona duas consultas ao elemento de streaming. As consultas não serão iteradas até que o elemento de streaming seja serializado.

XElement srcTree = new XElement("Root",
                       new XElement("Child", 1),
                       new XElement("Child", 2),
                       new XElement("Child", 3),
                       new XElement("Child", 4),
                       new XElement("Child", 5)
                   );

XStreamingElement dstTree = new XStreamingElement("NewRoot");

dstTree.Add(
    from el in srcTree.Elements()
    where (int)el <= 1
    select new XElement("Child", (int)el)
);

dstTree.Add(
    from el in srcTree.Elements()
    where (int)el >= 3
    select new XElement("DifferentChild", (int)el)
);

Console.WriteLine(dstTree);
Dim srcTree As XElement = _
    <Root>
        <Child>1</Child>
        <Child>2</Child>
        <Child>3</Child>
        <Child>4</Child>
        <Child>5</Child>
    </Root>

Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot")

dstTree.Add( _
    From el In srcTree.Elements() _
    Where el.Value <= 1 _
    Select <Child><%= el.Value %></Child> _
)

dstTree.Add( _
    From el In srcTree.Elements() _
    Where el.Value >= 3 _
    Select <DifferentChild><%= el.Value %></DifferentChild> _
)

Console.WriteLine(dstTree)

Este exemplo produz a seguinte saída:

<NewRoot>
  <Child>1</Child>
  <DifferentChild>3</DifferentChild>
  <DifferentChild>4</DifferentChild>
  <DifferentChild>5</DifferentChild>
</NewRoot>

Comentários

Esse construtor adiciona o conteúdo e os atributos especificados ao XStreamingElement. Embora muitas vezes seja possível construir a XStreamingElement instrução em uma única instrução, às vezes é mais conveniente adicionar conteúdo ao elemento de streaming incrementalmente.

As consultas não são iteradas até que elas XStreamingElement sejam serializadas. Isso contrasta com o uso de consultas para conteúdo para um XElement, em que as consultas são iteradas no momento da construção do novo XElement.

Para obter detalhes sobre o conteúdo válido que pode ser passado para essa função, consulte Conteúdo Válido de Objetos XElement e XDocument.

Confira também

Aplica-se a

Add(Object[])

Adiciona o conteúdo especificado como filhos a isso XStreamingElement.

public:
 void Add(... cli::array <System::Object ^> ^ content);
public void Add(params object[] content);
member this.Add : obj[] -> unit
Public Sub Add (ParamArray content As Object())

Parâmetros

content
Object[]

Conteúdo a ser adicionado ao elemento de streaming.

Exemplos

O exemplo a seguir cria um novo XStreamingElement. Em seguida, ele adiciona duas consultas ao elemento de streaming. As consultas não serão iteradas até que o elemento de streaming seja serializado.

XElement srcTree = new XElement("Root",
                       new XElement("Child", 1),
                       new XElement("Child", 2),
                       new XElement("Child", 3),
                       new XElement("Child", 4),
                       new XElement("Child", 5)
                   );

XStreamingElement dstTree = new XStreamingElement("NewRoot");

dstTree.Add(
    from el in srcTree.Elements()
    where (int)el <= 1
    select new XElement("Child", (int)el)
);

dstTree.Add(
    from el in srcTree.Elements()
    where (int)el >= 3
    select new XElement("DifferentChild", (int)el)
);

Console.WriteLine(dstTree);
Dim srcTree As XElement = _
    <Root>
        <Child>1</Child>
        <Child>2</Child>
        <Child>3</Child>
        <Child>4</Child>
        <Child>5</Child>
    </Root>

Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot")

dstTree.Add( _
    From el In srcTree.Elements() _
    Where el.Value <= 1 _
    Select <Child><%= el.Value %></Child> _
)

dstTree.Add( _
    From el In srcTree.Elements() _
    Where el.Value >= 3 _
    Select <DifferentChild><%= el.Value %></DifferentChild> _
)

Console.WriteLine(dstTree)

Este exemplo produz a seguinte saída:

<NewRoot>
  <Child>1</Child>
  <DifferentChild>3</DifferentChild>
  <DifferentChild>4</DifferentChild>
  <DifferentChild>5</DifferentChild>
</NewRoot>

Comentários

Esse construtor adiciona o conteúdo e os atributos especificados ao XStreamingElement. Embora muitas vezes seja possível construir a XStreamingElement instrução em uma única instrução, às vezes é mais conveniente adicionar conteúdo ao elemento de streaming incrementalmente.

As consultas não são iteradas até que elas XStreamingElement sejam serializadas. Isso contrasta com o uso de consultas para conteúdo para um XElement, em que as consultas são iteradas no momento da construção do novo XElement.

Para obter detalhes sobre o conteúdo válido que pode ser passado para essa função, consulte Conteúdo Válido de Objetos XElement e XDocument.

Confira também

Aplica-se a