Discovers attributed parts in the assemblies in a specified directory.
Assembly: System.ComponentModel.Composition (in System.ComponentModel.Composition.dll)
Thetype exposes the following members.
|DirectoryCatalog(String)||Initializes a new instance of the class with ComposablePartDefinition objects based on all the DLL files in the specified directory path.|
|DirectoryCatalog(String, String)||Initializes a new instance of the class with ComposablePartDefinition objects based on the specified search pattern in the specified directory path.|
|FullPath||Gets the translated absolute path observed by the .|
|LoadedFiles||Gets the collection of files currently loaded in the catalog.|
|Parts||Gets the part definitions that are contained in the directory catalog. (Overrides ComposablePartCatalog.Parts.)|
|Path||Gets the path observed by the .|
|SearchPattern||Gets the search pattern passed into the constructor of .|
|Dispose||Releases all resources used by the ComposablePartCatalog. (Inherited from ComposablePartCatalog.)|
|Dispose(Boolean)||Releases the unmanaged resources used by the and optionally releases the managed resources. (Overrides ComposablePartCatalog.Dispose(Boolean).)|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetExports||Gets the export definitions that match the constraint expressed by the specified definition. (Overrides ComposablePartCatalog.GetExports(ImportDefinition).)|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|OnChanged||Raises the Changed event.|
|OnChanging||Raises the Changing event.|
|Refresh||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. (Overrides Object.ToString.)|
A parses the contents of the designated directory. Any attributed parts contained in DLL files are extracted and made available via the catalog. A search pattern, to restrict parsing to specific DLLs, can also be specified using the same syntax as GetFiles.
The designated directory should not allow access to non-administrators. For example, using a folder that contains temporary Internet files could create vulnerabilities in the application.
The following example creates a that searches the directory the application runs from for parts. It uses a simple import to test the catalog. In order to fulfill this import, a DLL in the directory must have a matching export. (See below.)
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
To create the matching export, the following code must be in a DLL file. To create a separate DLL in Visual Studio, add a new project of the type "Class Library" to the solution, and put this code in it.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.