DirectoryCatalog 类

定义

发现所指定目录中的程序集的特性化部分。Discovers attributed parts in the assemblies in a specified directory.

public ref class DirectoryCatalog : System::ComponentModel::Composition::Primitives::ComposablePartCatalog, System::ComponentModel::Composition::Hosting::INotifyComposablePartCatalogChanged, System::ComponentModel::Composition::Primitives::ICompositionElement
public class DirectoryCatalog : System.ComponentModel.Composition.Primitives.ComposablePartCatalog, System.ComponentModel.Composition.Hosting.INotifyComposablePartCatalogChanged, System.ComponentModel.Composition.Primitives.ICompositionElement
type DirectoryCatalog = class
    inherit ComposablePartCatalog
    interface INotifyComposablePartCatalogChanged
    interface ICompositionElement
Public Class DirectoryCatalog
Inherits ComposablePartCatalog
Implements ICompositionElement, INotifyComposablePartCatalogChanged
继承
DirectoryCatalog
实现

示例

下面的示例创建一个 DirectoryCatalog 对象,该对象搜索应用程序为部件运行的目录。The following example creates a DirectoryCatalog object that searches the directory the application runs from for parts. 它使用简单的导入来测试目录。It uses a simple import to test the catalog. 若要完成此导入,目录中的 DLL 必须具有匹配的导出,如第二个代码块中所示。To fulfill this import, a DLL in the directory must have a matching export, as illustrated in the second code block.

public class Test2
{
    [Import]
    public Test1 data { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        DirectoryCatalog catalog = new DirectoryCatalog(".");
        CompositionContainer container = new CompositionContainer(catalog);
        Test2 test = new Test2();
        container.SatisfyImportsOnce(test);
        Console.WriteLine(test.data.data);
        Console.ReadLine();
    }
}
Public Class Test2
    <Import()>
    Public Property data As Test1
End Class

Sub Main()
    Dim catalog As New DirectoryCatalog(".")
    Dim container As New CompositionContainer(catalog)
    Dim test As New Test2()
    container.SatisfyImportsOnce(test)
    Console.WriteLine(test.data.data)
    Console.ReadLine()
End Sub

若要创建匹配导出,以下代码必须位于 DLL 文件中。To create the matching export, the following code must be in a DLL file. 若要在 Visual Studio 中创建 DLL 文件,请将 "类库" 类型的新项目添加到解决方案中,并将此代码放在该项目中。To create a DLL file in Visual Studio, add a new project of the type "Class Library" to your solution, and place this code in it.

[Export]
public class Test1
{
    public String data = "The data!";
}
<Export()>
Public Class Test1
    Public ReadOnly Property data As String
        Get
            Return "The data!"
        End Get
    End Property
End Class

注解

可以使用 DirectoryCatalog 对象分析指定目录的内容。You can use a DirectoryCatalog object to parse the contents of a designated directory. 动态链接库(DLL)文件中包含的所有属性化部件都将提取出来并可通过目录使用。若要将分析限制为特定 Dll,可以通过使用与 Directory.GetFiles 方法相同的语法来指定搜索模式。Any attributed parts contained in dynamic link library (DLL) files are extracted and made available through the catalog.To restrict parsing to specific DLLs, you can specify a search pattern by using the same syntax as the Directory.GetFiles method.

警告

指定的目录不允许访问非管理员。The designated directory should not allow access to non-administrators. 例如,使用包含临时 Internet 文件的文件夹可以在应用程序中创建漏洞。For example, using a folder that contains temporary Internet files could create vulnerabilities in your application.

此类型实现 IDisposable 接口。This type implements the IDisposable interface. 在使用完类型后,您应直接或间接释放类型。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接释放类型,请在 Disposetry/ 块中调用其 catch 方法。To dispose of the type directly, call its Dispose method in a try/catch block. 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

构造函数

DirectoryCatalog(String)

根据指定目录路径中的所有 DLL 文件,使用 DirectoryCatalog 对象初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects based on all the DLL files in the specified directory path.

DirectoryCatalog(String, ICompositionElement)

根据指定目录路径中的所有 DLL 文件,部分使用 DirectoryCatalog 对象初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects based on all the DLL files in the specified directory path with the specified source for parts.

DirectoryCatalog(String, ReflectionContext)

根据特定反射上下文中指定目录路径的所有 DLL 文件,使用 DirectoryCatalog 对象初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects based on all the DLL files in the specified directory path, in the specified reflection context.

DirectoryCatalog(String, ReflectionContext, ICompositionElement)

根据特定反射上下文中指定目录路径的所有 DLL 文件,使用 DirectoryCatalog 对象初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects based on all the DLL files in the specified directory path, in the specified reflection context.

DirectoryCatalog(String, String)

根据指定目录路径中的指定搜索模式,使用 DirectoryCatalog 对象匹配初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects that match a specified search pattern in the specified directory path.

DirectoryCatalog(String, String, ICompositionElement)

根据指定目录路径中的指定搜索模式,部分使用 DirectoryCatalog 对象初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects based on the specified search pattern in the specified directory path with the specified source for parts.

DirectoryCatalog(String, String, ReflectionContext)

根据指定目录路径中的指定搜索模式,使用特定反射上下文 DirectoryCatalog 对象初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects based on the specified search pattern in the specified directory path, using the specified reflection context.

DirectoryCatalog(String, String, ReflectionContext, ICompositionElement)

根据指定目录路径中的指定搜索模式,使用特定反射上下文 DirectoryCatalog 对象初始化 ComposablePartDefinition 类的新实例。Initializes a new instance of the DirectoryCatalog class by using ComposablePartDefinition objects based on the specified search pattern in the specified directory path, using the specified reflection context.

属性

FullPath

获取 DirectoryCatalog 遵循的已转换的绝对路径。Gets the translated absolute path observed by the DirectoryCatalog object.

LoadedFiles

获取目录中当前加载的文件的集合。Gets the collection of files currently loaded in the catalog.

Parts

获取目录中包含的部件定义。Gets the part definitions that are contained in the directory catalog.

Path

获取 DirectoryCatalog 对象遵循的路径。Gets the path observed by the DirectoryCatalog object.

SearchPattern

获取传递给DirectoryCatalog 对象的构造函数的搜索模式。Gets the search pattern that is passed into the constructor of the DirectoryCatalog object.

方法

Dispose()

释放 ComposablePartCatalog 使用的所有资源。Releases all resources used by the ComposablePartCatalog.

(继承自 ComposablePartCatalog)
Dispose(Boolean)

释放 DirectoryCatalog 使用的非托管资源,并选择性地释放托管资源。Releases the unmanaged resources used by the DirectoryCatalog and optionally releases the managed resources.

Equals(Object)

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

(继承自 Object)
GetEnumerator()

返回一个循环访问类别的枚举器。Returns an enumerator that iterates through the catalog.

GetExports(ImportDefinition)

获取与指定的定义所表示的约束相匹配的导入定义。Gets the export definitions that match the constraint expressed by the specified import definition.

GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
OnChanged(ComposablePartCatalogChangeEventArgs)

引发 Changed 事件。Raises the Changed event.

OnChanging(ComposablePartCatalogChangeEventArgs)

引发 Changing 事件。Raises the Changing event.

Refresh()

使用目录中与搜索模式相匹配的最新文件刷新 ComposablePartDefinition 对象。Refreshes the ComposablePartDefinition objects with the latest files in the directory that match the search pattern.

ToString()

获取目录的字符串表示形式。Gets a string representation of the directory catalog.

事件

Changed

在目录的内容更改后发生。Occurs when the contents of the catalog has changed.

Changing

在目录正在更改时发生。Occurs when the catalog is changing.

显式接口实现

ICompositionElement.DisplayName

获取目录的显示名称。Gets the display name of the directory catalog.

ICompositionElement.Origin

获取目录源自于的组合元素。Gets the composition element from which the directory catalog originated.

IEnumerable.GetEnumerator()

返回一个循环访问类别的枚举器。Returns an enumerator that iterates through the catalog.

(继承自 ComposablePartCatalog)

扩展方法

CreateCompositionService(ComposablePartCatalog)

用作为导出源的指定目录创建新复合服务。Creates a new composition service by using the specified catalog as a source for exports.

Filter(ComposablePartCatalog, Func<ComposablePartDefinition,Boolean>)

用指定的筛选功能筛选指定的目录。Filters the specified catalog with the specified filter function.

CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 DataTableDataRow 的输入 IEnumerable<T> 对象的情况下,返回包含 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)

在给定其泛型参数 DataRowDataTable 的输入 IEnumerable<T> 对象的情况下,将 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)

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

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.

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)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。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>)

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

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)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。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>)

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

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>)

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

Nodes<T>(IEnumerable<T>)

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

Remove<T>(IEnumerable<T>)

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

适用于