英語で読む

次の方法で共有


Extensions.Remove メソッド

定義

オーバーロード

Remove(IEnumerable<XAttribute>)

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

Remove<T>(IEnumerable<T>)

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

Remove(IEnumerable<XAttribute>)

ソース:
Extensions.cs
ソース:
Extensions.cs
ソース:
Extensions.cs

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

C#
public static void Remove(this System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute> source);
C#
public static void Remove(this System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute?> source);

パラメーター

source
IEnumerable<XAttribute>

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

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

C#
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);  

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

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

注釈

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

こちらもご覧ください

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Remove<T>(IEnumerable<T>)

ソース:
Extensions.cs
ソース:
Extensions.cs
ソース:
Extensions.cs

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

C#
public static void Remove<T>(this System.Collections.Generic.IEnumerable<T> source) where T : System.Xml.Linq.XNode;
C#
public static void Remove<T>(this System.Collections.Generic.IEnumerable<T?> source) where T : System.Xml.Linq.XNode;

型パラメーター

T

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

パラメーター

source
IEnumerable<T>

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

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

C#
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);  

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

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

注釈

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

こちらもご覧ください

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0