ExpandoObject ExpandoObject ExpandoObject ExpandoObject Class

定义

表示一个对象,该对象包含可在运行时动态添加和移除的成员。Represents an object whose members can be dynamically added and removed at run time.

public ref class ExpandoObject sealed : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>>, System::Collections::Generic::IDictionary<System::String ^, System::Object ^>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>>, System::ComponentModel::INotifyPropertyChanged, System::Dynamic::IDynamicMetaObjectProvider
public sealed class ExpandoObject : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string,object>>, System.Collections.Generic.IDictionary<string,object>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,object>>, System.ComponentModel.INotifyPropertyChanged, System.Dynamic.IDynamicMetaObjectProvider
type ExpandoObject = class
    interface IDynamicMetaObjectProvider
    interface IDictionary<string, obj>
    interface INotifyPropertyChanged
    interface ICollection<KeyValuePair<string, obj>>
    interface seq<KeyValuePair<string, obj>>
    interface IEnumerable
Public NotInheritable Class ExpandoObject
Implements ICollection(Of KeyValuePair(Of String, Object)), IDictionary(Of String, Object), IDynamicMetaObjectProvider, IEnumerable(Of KeyValuePair(Of String, Object)), INotifyPropertyChanged
继承
ExpandoObjectExpandoObjectExpandoObjectExpandoObject
实现

注解

ExpandoObject类使你能够在运行时添加和删除其实例的成员, 还可以设置和获取这些成员的值。The ExpandoObject class enables you to add and delete members of its instances at run time and also to set and get values of these members. 此类支持动态绑定, 使你可以使用类似sampleObject.sampleMember的标准语法, 而不是更复杂的sampleObject.GetAttribute("sampleMember")语法。This class supports dynamic binding, which enables you to use standard syntax like sampleObject.sampleMember instead of more complex syntax like sampleObject.GetAttribute("sampleMember").

类实现了标准动态语言运行时 (DLR) 接口IDynamicMetaObjectProvider, 使你ExpandoObject能够在支持 DLR 互操作性模型的语言之间共享类的实例。 ExpandoObjectThe ExpandoObject class implements the standard Dynamic Language Runtime (DLR) interface IDynamicMetaObjectProvider, which enables you to share instances of the ExpandoObject class between languages that support the DLR interoperability model. 例如, 可以在中ExpandoObject C#创建类的实例, 然后将其传递给 IronPython 函数。For example, you can create an instance of the ExpandoObject class in C# and then pass it to an IronPython function. 有关详细信息, 请参阅 " C# 动态语言运行时概述" 和 "介绍常见问题" 网站上的 ExpandoObjectFor more information, see Dynamic Language Runtime Overview and Introducing the ExpandoObject on the C# Frequently Asked Questions Web site.

ExpandoObject类是动态对象概念的实现, 它允许获取、设置和调用成员。The ExpandoObject class is an implementation of the dynamic object concept that enables getting, setting, and invoking members. 如果要定义具有其自己的动态调度语义的类型, 请使用DynamicObject类。If you want to define types that have their own dynamic dispatch semantics, use the DynamicObject class. 如果希望定义动态对象如何参与互操作性协议并管理 DLR 快速动态调度缓存, 请创建自己的IDynamicMetaObjectProvider接口实现。If you want to define how dynamic objects participate in the interoperability protocol and manage DLR fast dynamic dispatch caching, create your own implementation of the IDynamicMetaObjectProvider interface.

创建实例Creating an Instance

在C#中, 若要为ExpandoObject类的实例启用后期绑定, 必须使用dynamic关键字。In C#, to enable late binding for an instance of the ExpandoObject class, you must use the dynamic keyword. 有关更多信息,请参见使用类型 dynamicFor more information, see Using Type dynamic.

在 Visual Basic 中, 后期绑定支持动态操作。In Visual Basic, dynamic operations are supported by late binding. 有关详细信息, 请参阅早期和后期绑定For more information, see Early and Late Binding.

下面的代码示例演示如何创建ExpandoObject类的实例。The following code example demonstrates how to create an instance of the ExpandoObject class.

dynamic sampleObject = new ExpandoObject();
Dim sampleObject As Object = New ExpandoObject()

添加新成员Adding New Members

可以向ExpandoObject类的实例添加属性、方法和事件。You can add properties, methods, and events to instances of the ExpandoObject class.

下面的代码示例演示如何将新属性添加到ExpandoObject类的实例。The following code example demonstrates how to add a new property to an instance of the ExpandoObject class.

sampleObject.test = "Dynamic Property";
Console.WriteLine(sampleObject.test);
Console.WriteLine(sampleObject.test.GetType());
// This code example produces the following output:
// Dynamic Property
// System.String
sampleObject.Test = "Dynamic Property"
Console.WriteLine(sampleObject.test)
Console.WriteLine(sampleObject.test.GetType())
' This code example produces the following output:
' Dynamic Property
' System.String

方法表示存储为委托的 lambda 表达式, 这些表达式可在需要时调用。The methods represent lambda expressions that are stored as delegates, which can be invoked when they are needed. 下面的代码示例演示如何添加递增动态属性值的方法。The following code example demonstrates how to add a method that increments a value of the dynamic property.

sampleObject.number = 10;
sampleObject.Increment = (Action)(() => { sampleObject.number++; });

// Before calling the Increment method.
Console.WriteLine(sampleObject.number);

sampleObject.Increment();

// After calling the Increment method.
Console.WriteLine(sampleObject.number);
// This code example produces the following output:
// 10
// 11
sampleObject.Number = 10
sampleObject.Increment = Function() sampleObject.Number + 1
' Before calling the Increment method.
Console.WriteLine(sampleObject.number)

sampleObject.Increment.Invoke()

' After calling the Increment method.
Console.WriteLine(sampleObject.number)
' This code example produces the following output:
' 10
' 11

下面的代码示例演示如何将事件添加到ExpandoObject类的实例。The following code example demonstrates how to add an event to an instance of the ExpandoObject class.

class Program  
{  
    static void Main(string[] args)  
    {  
        dynamic sampleObject = new ExpandoObject();  

        // Create a new event and initialize it with null.  
        sampleObject.sampleEvent = null;  

        // Add an event handler.  
        sampleObject.sampleEvent += new EventHandler(SampleHandler);  

        // Raise an event for testing purposes.  
        sampleObject.sampleEvent(sampleObject, new EventArgs());  
   }  

    // Event handler.  
    static void SampleHandler(object sender, EventArgs e)  
    {  
        Console.WriteLine("SampleHandler for {0} event", sender);  
    }  
}  
// This code example produces the following output:  
// SampleHandler for System.Dynamic.ExpandoObject event.  
Module Module1  

Sub Main()  
    Dim sampleObject As Object = New ExpandoObject()  

    ' Create a new event and initialize it with null.  
    sampleObject.sampleEvent = Nothing  

    ' Add an event handler.  
    Dim handler As EventHandler = AddressOf SampleHandler  
    sampleObject.sampleEvent =   
        [Delegate].Combine(sampleObject.sampleEvent, handler)  

    ' Raise an event for testing purposes.  
    sampleObject.sampleEvent.Invoke(sampleObject, New EventArgs())  

End Sub  

' Event handler.  
Sub SampleHandler(ByVal sender As Object, ByVal e As EventArgs)  
    Console.WriteLine("SampleHandler for {0} event", sender)  
End Sub  

' This code example produces the following output:  
' SampleHandler for System.Dynamic.ExpandoObject event.  

End Module  

作为参数传递Passing As a Parameter

可以将ExpandoObject类的实例作为参数传递。You can pass instances of the ExpandoObject class as parameters. 请注意, 在 Visual Basic 中, 这些实例被C#视为和后期绑定对象中的动态对象。Note that these instances are treated as dynamic objects in C# and late-bound objects in Visual Basic. 这意味着你没有对象成员的 IntelliSense, 因此, 当你调用不存在的成员时, 不会收到编译器错误。This means that you do not have IntelliSense for object members and you do not receive compiler errors when you call non-existent members. 如果调用的成员不存在, 则会出现异常。If you call a member that does not exist, an exception occurs.

下面的代码示例演示如何创建和使用方法来打印属性的名称和值。The following code example demonstrates how you can create and use a method to print the names and values of properties.

class Program
{
    static void Main(string[] args)
    {
        dynamic employee, manager;

        employee = new ExpandoObject();
        employee.Name = "John Smith";
        employee.Age = 33;

        manager = new ExpandoObject();
        manager.Name = "Allison Brown";
        manager.Age = 42;
        manager.TeamSize = 10;

        WritePerson(manager);
        WritePerson(employee);
    }
    private static void WritePerson(dynamic person)
    {
        Console.WriteLine("{0} is {1} years old.",
                          person.Name, person.Age);
        // The following statement causes an exception
        // if you pass the employee object.
        // Console.WriteLine("Manages {0} people", person.TeamSize);
    }
}
// This code example produces the following output:
// John Smith is 33 years old.
// Allison Brown is 42 years old.
Sub Main()
    Dim employee, manager As Object

    employee = New ExpandoObject()
    employee.Name = "John Smith"
    employee.Age = 33

    manager = New ExpandoObject()
    manager.Name = "Allison Brown"
    manager.Age = 42
    manager.TeamSize = 10

    WritePerson(manager)
    WritePerson(employee)
End Sub

Private Sub WritePerson(ByVal person As Object)

    Console.WriteLine("{0} is {1} years old.",
                      person.Name, person.Age)
    ' The following statement causes an exception
    ' if you pass the employee object.
    ' Console.WriteLine("Manages {0} people", person.TeamSize)

End Sub

枚举和删除成员Enumerating and Deleting Members

ExpandoObject 类实现 IDictionary<String, Object> 接口。The ExpandoObject class implements the IDictionary<String, Object> interface. 这样就可以在运行时枚举添加到ExpandoObject类的实例的成员。This enables enumeration of members added to the instance of the ExpandoObject class at run time. 如果在编译时不知道实例可能具有哪些成员, 则这会很有用。This can be useful if you do not know at compile time what members an instance might have.

下面的代码示例演示如何将ExpandoObject类的实例转换IDictionary<TKey,TValue>为接口并枚举实例的成员。The following code example shows how you can cast an instance of the ExpandoObject class to the IDictionary<TKey,TValue> interface and enumerate the instance's members.

dynamic employee = new ExpandoObject();
employee.Name = "John Smith";
employee.Age = 33;

foreach (var property in (IDictionary<String, Object>)employee)
{
    Console.WriteLine(property.Key + ": " + property.Value);
}
// This code example produces the following output:
// Name: John Smith
// Age: 33
Dim employee As Object = New ExpandoObject()
employee.Name = "John Smith"
employee.Age = 33
For Each member In CType(employee, IDictionary(Of String, Object))
    Console.WriteLine(member.Key & ": " & member.Value)
Next
' This code example produces the following output:
' Name: John Smith
' Age: 33

在不具有删除成员的语法的语言 (例如C#和 Visual Basic) 中, 可以通过将的ExpandoObject实例隐式强制转换为IDictionary<String, Object>接口, 然后将该成员作为键/值对删除来删除成员。In languages that do not have syntax for deleting members (such as C# and Visual Basic), you can delete a member by implicitly casting an instance of the ExpandoObject to the IDictionary<String, Object> interface and then deleting the member as a key/value pair. 这在下面的示例中显示。This is shown in the following example.

dynamic employee = new ExpandoObject();
employee.Name = "John Smith";
((IDictionary<String, Object>)employee).Remove("Name");
Dim employee As Object = New ExpandoObject()
employee.Name = "John Smith"
CType(employee, IDictionary(Of String, Object)).Remove("Name")

接收属性更改的通知Receiving Notifications of Property Changes

ExpandoObject类实现PropertyChanged接口, 并可在添加、删除或修改成员后引发事件。 INotifyPropertyChangedThe ExpandoObject class implements the INotifyPropertyChanged interface and can raise a PropertyChanged event when a member is added, deleted, or modified. 这使ExpandoObject类与 Windows Presentation Foundation (WPF) 数据绑定和需要通知对象内容中的更改的其他环境相集成。This enables ExpandoObject class integration with Windows Presentation Foundation (WPF) data binding and other environments that require notification about changes in the object content.

下面的代码示例演示如何为PropertyChanged事件创建事件处理程序。The following code example demonstrates how to create an event handler for the PropertyChanged event.

// Add "using System.ComponentModel;" line 
// to the beginning of the file.
class Program
{
    static void Test()
    {
        dynamic employee = new ExpandoObject();
        ((INotifyPropertyChanged)employee).PropertyChanged +=
            new PropertyChangedEventHandler(HandlePropertyChanges);
        employee.Name = "John Smith";
    }

    private static void HandlePropertyChanges(
        object sender, PropertyChangedEventArgs e)
    {
        Console.WriteLine("{0} has changed.", e.PropertyName);
    }
}
' Add "Imports System.ComponentModel" line 
' to the beginning of the file.
Sub Main()
    Dim employee As Object = New ExpandoObject
    AddHandler CType(
        employee, INotifyPropertyChanged).PropertyChanged,
        AddressOf HandlePropertyChanges
    employee.Name = "John Smith"
End Sub

Private Sub HandlePropertyChanges(
       ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
    Console.WriteLine("{0} has changed.", e.PropertyName)
End Sub

构造函数

ExpandoObject() ExpandoObject() ExpandoObject() ExpandoObject()

初始化不包含任何成员的新 ExpandoObjectInitializes a new ExpandoObject that does not have members.

显式界面实现

ICollection<KeyValuePair<String,Object>>.Add(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Add(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Add(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Add(KeyValuePair<String,Object>)

将指定值添加到具有指定键的 ICollection<T> 中。Adds the specified value to the ICollection<T> that has the specified key.

ICollection<KeyValuePair<String,Object>>.Clear() ICollection<KeyValuePair<String,Object>>.Clear() ICollection<KeyValuePair<String,Object>>.Clear() ICollection<KeyValuePair<String,Object>>.Clear()

从集合中移除所有项。Removes all items from the collection.

ICollection<KeyValuePair<String,Object>>.Contains(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Contains(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Contains(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Contains(KeyValuePair<String,Object>)

确定是否 ICollection<T> 包含一个指定键和值。Determines whether the ICollection<T> contains a specific key and value.

ICollection<KeyValuePair<String,Object>>.CopyTo(KeyValuePair<String,Object>[], Int32) ICollection<KeyValuePair<String,Object>>.CopyTo(KeyValuePair<String,Object>[], Int32) ICollection<KeyValuePair<String,Object>>.CopyTo(KeyValuePair<String,Object>[], Int32) ICollection<KeyValuePair<String,Object>>.CopyTo(KeyValuePair<String,Object>[], Int32)

从特定的数组索引处开始,将 ICollection<T> 的元素复制到类型 KeyValuePair<TKey,TValue> 的一个数组。Copies the elements of the ICollection<T> to an array of type KeyValuePair<TKey,TValue>, starting at the specified array index.

ICollection<KeyValuePair<String,Object>>.Count ICollection<KeyValuePair<String,Object>>.Count ICollection<KeyValuePair<String,Object>>.Count ICollection<KeyValuePair<String,Object>>.Count

获取 ICollection<T> 中的元素数。Gets the number of elements in the ICollection<T>.

ICollection<KeyValuePair<String,Object>>.IsReadOnly ICollection<KeyValuePair<String,Object>>.IsReadOnly ICollection<KeyValuePair<String,Object>>.IsReadOnly ICollection<KeyValuePair<String,Object>>.IsReadOnly

获取一个值,该值指示 ICollection<T> 是否为只读。Gets a value indicating whether the ICollection<T> is read-only.

ICollection<KeyValuePair<String,Object>>.Remove(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Remove(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Remove(KeyValuePair<String,Object>) ICollection<KeyValuePair<String,Object>>.Remove(KeyValuePair<String,Object>)

从集合中移除键和值。Removes a key and value from the collection.

IDictionary<String,Object>.Add(String, Object) IDictionary<String,Object>.Add(String, Object) IDictionary<String,Object>.Add(String, Object) IDictionary<String,Object>.Add(String, Object)

将指定的键和值添加到字典中。Adds the specified key and value to the dictionary.

IDictionary<String,Object>.ContainsKey(String) IDictionary<String,Object>.ContainsKey(String) IDictionary<String,Object>.ContainsKey(String) IDictionary<String,Object>.ContainsKey(String)

确定字典是否包含指定键。Determines whether the dictionary contains the specified key.

IDictionary<String,Object>.Item[String] IDictionary<String,Object>.Item[String] IDictionary<String,Object>.Item[String] IDictionary<String,Object>.Item[String]

获取或设置具有指定键的元素。Gets or sets the element that has the specified key.

IDictionary<String,Object>.Keys IDictionary<String,Object>.Keys IDictionary<String,Object>.Keys IDictionary<String,Object>.Keys

获取包含 IDictionary<TKey,TValue> 的键的 ICollection<T>Gets an ICollection<T> that contains the keys of the IDictionary<TKey,TValue>.

IDictionary<String,Object>.Remove(String) IDictionary<String,Object>.Remove(String) IDictionary<String,Object>.Remove(String) IDictionary<String,Object>.Remove(String)

IDictionary 中移除具有指定键的元素。Removes the element that has the specified key from the IDictionary.

IDictionary<String,Object>.TryGetValue(String, Object) IDictionary<String,Object>.TryGetValue(String, Object) IDictionary<String,Object>.TryGetValue(String, Object) IDictionary<String,Object>.TryGetValue(String, Object)

获取与指定键关联的值。Gets the value associated with the specified key.

IDictionary<String,Object>.Values IDictionary<String,Object>.Values IDictionary<String,Object>.Values IDictionary<String,Object>.Values

获取包含 ICollection<T> 中的值的 IDictionary<TKey,TValue>Gets an ICollection<T> that contains the values in the IDictionary<TKey,TValue>.

IDynamicMetaObjectProvider.GetMetaObject(Expression) IDynamicMetaObjectProvider.GetMetaObject(Expression) IDynamicMetaObjectProvider.GetMetaObject(Expression) IDynamicMetaObjectProvider.GetMetaObject(Expression)

提供的 MetaObject 将调度到 Dynamic 虚方法。The provided MetaObject will dispatch to the dynamic virtual methods. 可以将该对象封装到另一个 MetaObject 中,以便为单个操作提供自定义行为。The object can be encapsulated inside another MetaObject to provide custom behavior for individual actions.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

返回一个循环访问集合的枚举器。Returns an enumerator that iterates through the collection.

IEnumerable<KeyValuePair<String,Object>>.GetEnumerator() IEnumerable<KeyValuePair<String,Object>>.GetEnumerator() IEnumerable<KeyValuePair<String,Object>>.GetEnumerator() IEnumerable<KeyValuePair<String,Object>>.GetEnumerator()

返回一个循环访问集合的枚举器。Returns an enumerator that iterates through the collection.

INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged

在属性值更改时发生。Occurs when a property value changes.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

扩展方法

Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于