IHierarchicalEnumerable 接口

定义

表示一个可以使用 IEnumerator 接口枚举的分层集合。Represents a hierarchical collection that can be enumerated with an IEnumerator interface. 实现 IHierarchicalEnumerable 接口的集合供 ASP.NET 站点导航控件和数据源控件使用。Collections that implement the IHierarchicalEnumerable interface are used by ASP.NET site navigation and data source controls.

public interface class IHierarchicalEnumerable : System::Collections::IEnumerable
public interface IHierarchicalEnumerable : System.Collections.IEnumerable
type IHierarchicalEnumerable = interface
    interface IEnumerable
Public Interface IHierarchicalEnumerable
Implements IEnumerable
派生
实现

示例

下面的代码示例IHierarchicalEnumerable演示如何使用扩展ArrayList和提供包装FileSystemInfo对象的对象集合的IHierarchyData类实现接口。The following code example demonstrates how to implement the IHierarchicalEnumerable interface with a class that extends ArrayList and provides a collection of IHierarchyData objects that wrap FileSystemInfo objects. 当调用Select方法时, 派生自HierarchicalDataSourceView的类使用集合来返回分层节点的集合。IHierarchicalEnumerableThe IHierarchicalEnumerable collection is used by classes that derive from HierarchicalDataSourceView to return a collection of hierarchical nodes when the Select method is called. 此代码示例是为HierarchicalDataSourceControl类提供的更大示例的一部分。This code example is part of a larger example provided for the HierarchicalDataSourceControl class.

// A collection of FileSystemHierarchyData objects
public class FileSystemHierarchicalEnumerable :
    ArrayList, IHierarchicalEnumerable
{
    public FileSystemHierarchicalEnumerable()
        : base()
    {
    }

    public IHierarchyData GetHierarchyData(object enumeratedItem)
    {
        return enumeratedItem as IHierarchyData;
    }
}


Public Class FileSystemHierarchicalEnumerable
    Inherits ArrayList
    Implements IHierarchicalEnumerable

    Public Sub New()
    End Sub


    Public Overridable Function GetHierarchyData( _
        ByVal enumeratedItem As Object) As IHierarchyData _
        Implements IHierarchicalEnumerable.GetHierarchyData

        Return CType(enumeratedItem, IHierarchyData)
    End Function

End Class

注解

IHierarchicalEnumerable接口GetHierarchyData GetEnumerator扩展接口并公开,IHierarchyData这是用于从枚举项中检索对象的方法, 以及方法。 IEnumerableThe IHierarchicalEnumerable interface extends the IEnumerable interface and exposes GetHierarchyData, which is a method used to retrieve an IHierarchyData object from an enumerated item, in addition to the GetEnumerator method.

IHierarchicalEnumerable通常, 使用集合的客户端通过IEnumerator调用GetEnumerator方法来检索对象, GetHierarchyData然后循环访问枚举, 并对每个枚举项调用来检索IHierarchyData对象。Typically, clients that use IHierarchicalEnumerable collections retrieve an IEnumerator object by calling the GetEnumerator method, then iterate through the enumeration and call the GetHierarchyData on each enumerated item to retrieve an IHierarchyData object.

方法

GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

(继承自 IEnumerable)
GetHierarchyData(Object)

返回指定枚举项的分层数据项。Returns a hierarchical data item for the specified enumerated item.

扩展方法

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅