Extensions.Remove メソッド

定義

オーバーロード

Remove(IEnumerable<XAttribute>)

ソース コレクション内の親要素からすべての属性を削除します。

Remove<T>(IEnumerable<T>)

ソース コレクション内の親ノードからすべてのノードを削除します。

Remove(IEnumerable<XAttribute>)

Source:
Extensions.cs
Source:
Extensions.cs
Source:
Extensions.cs

ソース コレクション内の親要素からすべての属性を削除します。

public:
[System::Runtime::CompilerServices::Extension]
 static void Remove(System::Collections::Generic::IEnumerable<System::Xml::Linq::XAttribute ^> ^ source);
public static void Remove (this System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute> source);
public static void Remove (this System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute?> source);
static member Remove : seq<System.Xml.Linq.XAttribute> -> unit
<Extension()>
Public Sub Remove (source As IEnumerable(Of XAttribute))

パラメーター

source
IEnumerable<XAttribute>

ソース コレクションが格納されている IEnumerable<T>XAttribute

次の例では、属性のコレクションを取得し、このメソッドを呼び出して、それらの属性を親要素から削除します。

XElement root = new XElement("Root",  
    new XAttribute("Att1", 1),  
    new XAttribute("Att2", 2),  
    new XAttribute("Att3", 3),  
    new XAttribute("Att4", 4),  
    new XAttribute("Att5", 5)  
);  

IEnumerable<XAttribute> atList =  
    from at in root.Attributes()  
    where (int)at >= 3  
    select at;  

atList.Remove();  

Console.WriteLine(root);  
Dim root As XElement = <Root Att1="1" Att2="2" Att3="3" Att4="4" Att5="5"/>  

Dim atList = From at In root.Attributes _  
             Where at.Value >= 3 _  
             Select at  

atList.Remove()  

Console.WriteLine(root)  

この例を実行すると、次の出力が生成されます。

<Root Att1="1" Att2="2" />  

注釈

このメソッドはスナップショット セマンティクスを使用します。つまり、ソース コレクション内の属性を 親から切断する前に に System.Collections.Generic.List<T> コピーします。 これは、命令型または宣言型の混合コードに関する問題を回避するために必要です。 詳細については、「混合宣言型コード/命令型コードのバグ (LINQ to XML)」を参照してください。

こちらもご覧ください

適用対象

Remove<T>(IEnumerable<T>)

Source:
Extensions.cs
Source:
Extensions.cs
Source:
Extensions.cs

ソース コレクション内の親ノードからすべてのノードを削除します。

public:
generic <typename T>
 where T : System::Xml::Linq::XNode[System::Runtime::CompilerServices::Extension]
 static void Remove(System::Collections::Generic::IEnumerable<T> ^ source);
public static void Remove<T> (this System.Collections.Generic.IEnumerable<T> source) where T : System.Xml.Linq.XNode;
public static void Remove<T> (this System.Collections.Generic.IEnumerable<T?> source) where T : System.Xml.Linq.XNode;
static member Remove : seq<'T (requires 'T :> System.Xml.Linq.XNode)> -> unit (requires 'T :> System.Xml.Linq.XNode)
<Extension()>
Public Sub Remove(Of T As XNode) (source As IEnumerable(Of T))

型パラメーター

T

XNode に制限された、source 内のオブジェクトの型。

パラメーター

source
IEnumerable<T>

ソース コレクションが格納されている IEnumerable<T>XNode

次の例では、要素のコレクションを取得します。 次に、このメソッドを呼び出して、親要素から要素を削除します。

XElement root = new XElement("Root",  
    new XElement("Data", 1),  
    new XElement("Data", 2),  
    new XElement("Data", 3),  
    new XElement("Data", 4),  
    new XElement("Data", 5)  
);  

IEnumerable<XElement> elList =  
    from el in root.Elements()  
    where (int)el >= 3  
    select el;  

elList.Remove();  

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

Dim elList = From el In root.Elements _  
             Where el.Value >= 3 _  
             Select el  

elList.Remove()  

Console.WriteLine(root)  

この例を実行すると、次の出力が生成されます。

<Root>  
  <Data>1</Data>  
  <Data>2</Data>  
</Root>  

注釈

このメソッドはスナップショット セマンティクスを使用します。つまり、ソース コレクション内の属性を 親から切断する前に に List<T> コピーします。 これは、命令型または宣言型の混合コードに関する問題を回避するために必要です。 詳細については、「混合宣言型コード/命令型コードのバグ (LINQ to XML)」を参照してください。

こちらもご覧ください

適用対象