DirectoryCatalog DirectoryCatalog DirectoryCatalog DirectoryCatalog Class

Definition

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
Inheritance
Implements

Examples

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();
    }
}
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 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

Remarks

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.

Warning

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.

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

Constructors

DirectoryCatalog(String) DirectoryCatalog(String) DirectoryCatalog(String) 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) DirectoryCatalog(String, ICompositionElement) DirectoryCatalog(String, ICompositionElement) 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) DirectoryCatalog(String, ReflectionContext) DirectoryCatalog(String, ReflectionContext) 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, ReflectionContext, ICompositionElement) DirectoryCatalog(String, ReflectionContext, ICompositionElement) DirectoryCatalog(String, ReflectionContext, ICompositionElement) 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) DirectoryCatalog(String, String) DirectoryCatalog(String, String) 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, String, ICompositionElement) DirectoryCatalog(String, String, ICompositionElement) DirectoryCatalog(String, String, ICompositionElement) 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) DirectoryCatalog(String, String, ReflectionContext) DirectoryCatalog(String, String, ReflectionContext) 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) DirectoryCatalog(String, String, ReflectionContext, ICompositionElement) DirectoryCatalog(String, String, ReflectionContext, ICompositionElement) 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.

Properties

FullPath FullPath FullPath FullPath

Gets the translated absolute path observed by the DirectoryCatalog object.

LoadedFiles LoadedFiles LoadedFiles LoadedFiles

Gets the collection of files currently loaded in the catalog.

Parts Parts Parts Parts

Gets the part definitions that are contained in the directory catalog.

Path Path Path Path

Gets the path observed by the DirectoryCatalog object.

SearchPattern SearchPattern SearchPattern SearchPattern

Gets the search pattern that is passed into the constructor of the DirectoryCatalog object.

Methods

Dispose() Dispose() Dispose() Dispose()

Releases all resources used by the ComposablePartCatalog.

(Inherited from ComposablePartCatalog)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Releases the unmanaged resources used by the DirectoryCatalog and optionally releases the managed resources.

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

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through the catalog.

GetExports(ImportDefinition) GetExports(ImportDefinition) GetExports(ImportDefinition) GetExports(ImportDefinition)

Gets the export definitions that match the constraint expressed by the specified import definition.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

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

Gets the Type of the current instance.

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

Creates a shallow copy of the current Object.

(Inherited from Object)
OnChanged(ComposablePartCatalogChangeEventArgs) OnChanged(ComposablePartCatalogChangeEventArgs) OnChanged(ComposablePartCatalogChangeEventArgs) OnChanged(ComposablePartCatalogChangeEventArgs)

Raises the Changed event.

OnChanging(ComposablePartCatalogChangeEventArgs) OnChanging(ComposablePartCatalogChangeEventArgs) OnChanging(ComposablePartCatalogChangeEventArgs) OnChanging(ComposablePartCatalogChangeEventArgs)

Raises the Changing event.

Refresh() Refresh() Refresh() Refresh()

Refreshes the ComposablePartDefinition objects with the latest files in the directory that match the search pattern.

ToString() ToString() ToString() ToString()

Gets a string representation of the directory catalog.

Events

Changed Changed Changed Changed

Occurs when the contents of the catalog has changed.

Changing Changing Changing Changing

Occurs when the catalog is changing.

Explicit Interface Implementations

ICompositionElement.DisplayName ICompositionElement.DisplayName ICompositionElement.DisplayName ICompositionElement.DisplayName

Gets the display name of the directory catalog.

ICompositionElement.Origin ICompositionElement.Origin ICompositionElement.Origin ICompositionElement.Origin

Gets the composition element from which the directory catalog originated.

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

Returns an enumerator that iterates through the catalog.

(Inherited from ComposablePartCatalog)

Extension Methods

CreateCompositionService(ComposablePartCatalog) CreateCompositionService(ComposablePartCatalog) CreateCompositionService(ComposablePartCatalog) CreateCompositionService(ComposablePartCatalog)

Creates a new composition service by using the specified catalog as a source for exports.

Filter(ComposablePartCatalog, Func<ComposablePartDefinition,Boolean>) Filter(ComposablePartCatalog, Func<ComposablePartDefinition,Boolean>) Filter(ComposablePartCatalog, Func<ComposablePartDefinition,Boolean>) Filter(ComposablePartCatalog, Func<ComposablePartDefinition,Boolean>)

Filters the specified catalog with the specified filter function.

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

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

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

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

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(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)

Converts 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. 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. 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. 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.

Applies to