Extensions.Remove 方法

定义

重载

名称 说明
Remove(IEnumerable<XAttribute>)

从源集合的父元素中删除每个属性。

Remove<T>(IEnumerable<T>)

从源集合的父节点中删除每个节点。

Remove(IEnumerable<XAttribute>)

Source:
Extensions.cs
Source:
Extensions.cs
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> 。 这是为了避免混合命令性/声明性代码出现问题所必需的。 有关详细信息,请参阅混合声明性代码/命令性代码 Bug(LINQ to XML)。

另请参阅

适用于

Remove<T>(IEnumerable<T>)

Source:
Extensions.cs
Source:
Extensions.cs
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

source对象的类型,受 XNode约束。

参数

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> 。 这是为了避免混合命令性/声明性代码出现问题所必需的。 有关详细信息,请参阅混合声明性代码/命令性代码 Bug(LINQ to XML)。

另请参阅

适用于