XStreamingElement.Add Metoda

Definice

Přidá zadaný obsah jako podřízené položky k tomuto XStreamingElementsouboru .

Přetížení

Add(Object)

Přidá zadaný obsah jako podřízené položky k tomuto XStreamingElementsouboru .

Add(Object[])

Přidá zadaný obsah jako podřízené položky k tomuto XStreamingElementsouboru .

Add(Object)

Source:
XStreamingElement.cs
Source:
XStreamingElement.cs
Source:
XStreamingElement.cs

Přidá zadaný obsah jako podřízené položky k tomuto XStreamingElementsouboru .

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

Parametry

content
Object

Obsah, který se má přidat do elementu streamování.

Příklady

Následující příklad vytvoří nový XStreamingElement. Potom přidá dva dotazy do elementu streamování. Dotazy nejsou iterated, dokud streamovaný prvek není serializován.

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)

Tento příklad vytvoří následující výstup:

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

Poznámky

Tento konstruktor přidá zadaný obsah a atributy do XStreamingElement. I když je často možné vytvořit XStreamingElement v jediném příkazu, je někdy pohodlnější přidat obsah do elementu streamování přírůstkově.

Dotazy se iterují, dokud XStreamingElement není serializován. To je v kontrastu s používáním dotazů na obsah pro XElementobjekt , kde se dotazy iteují v době výstavby nového XElementobjektu .

Podrobnosti o platném obsahu, který lze předat této funkci, najdete v tématu Platný obsah objektů XElement a XDocument.

Viz také

Platí pro

Add(Object[])

Source:
XStreamingElement.cs
Source:
XStreamingElement.cs
Source:
XStreamingElement.cs

Přidá zadaný obsah jako podřízené položky k tomuto XStreamingElementsouboru .

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

Parametry

content
Object[]

Obsah, který se má přidat do elementu streamování.

Příklady

Následující příklad vytvoří nový XStreamingElement. Potom přidá dva dotazy do elementu streamování. Dotazy nejsou iterated, dokud streamovaný prvek není serializován.

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)

Tento příklad vytvoří následující výstup:

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

Poznámky

Tento konstruktor přidá zadaný obsah a atributy do XStreamingElement. I když je často možné vytvořit XStreamingElement v jediném příkazu, je někdy pohodlnější přidat obsah do elementu streamování přírůstkově.

Dotazy se iterují, dokud XStreamingElement není serializován. To je v kontrastu s používáním dotazů na obsah pro XElementobjekt , kde se dotazy iteují v době výstavby nového XElementobjektu .

Podrobnosti o platném obsahu, který lze předat této funkci, najdete v tématu Platný obsah objektů XElement a XDocument.

Viz také

Platí pro