DirectoryCatalog Class
Discovers attributed parts in the assemblies in a specified directory.
System.ComponentModel.Composition.Primitives.ComposablePartCatalog
System.ComponentModel.Composition.Hosting.DirectoryCatalog
Namespace: System.ComponentModel.Composition.Hosting
Assembly: System.ComponentModel.Composition (in System.ComponentModel.Composition.dll)
The DirectoryCatalog type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DirectoryCatalog(String) | 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) | 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) | 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) | 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, ReflectionContext, ICompositionElement) | 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, ICompositionElement) | 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) | 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) | 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. |
| Name | Description | |
|---|---|---|
![]() | FullPath | 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 catalog. (Inherited from ComposablePartCatalog.) In .NET Framework Client Profile, this member is overridden by Parts. |
![]() | Path | Gets the path observed by the DirectoryCatalog object. |
![]() | SearchPattern | Gets the search pattern that is passed into the constructor of the DirectoryCatalog object. |
| Name | Description | |
|---|---|---|
![]() | Dispose() | Releases all resources used by the ComposablePartCatalog. (Inherited from ComposablePartCatalog.) |
![]() | Dispose(Boolean) | Releases the unmanaged resources used by the DirectoryCatalog 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.) |
![]() | GetEnumerator | Returns an enumerator that iterates through the catalog. (Overrides ComposablePartCatalog.GetEnumerator().) |
![]() | GetExports | Gets the export definitions that match the constraint expressed by the specified import 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().) |
| Name | Description | |
|---|---|---|
![]() | CreateCompositionService | Creates a new composition service by using the specified catalog as a source for exports. (Defined by CatalogExtensions.) |
![]() | Filter | Filters the specified catalog with the specified filter function. (Defined by ScopingExtensions.) |
| Name | Description | |
|---|---|---|
![]() ![]() | 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. (Inherited from ComposablePartCatalog.) |
You can use a DirectoryCatalog object to parse the contents of a designated directory. 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.
Caution |
|---|
The designated directory should not allow access to non-administrators. For example, using a folder that contains temporary Internet files could create vulnerabilities in your application. |
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. 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(); } }
To create the matching export, the following code must be in a DLL file. 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.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.








Caution