AssemblyCatalog Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Discovers attributed parts in a managed code assembly.
public ref class AssemblyCatalog : System::ComponentModel::Composition::Primitives::ComposablePartCatalog, System::ComponentModel::Composition::Primitives::ICompositionElement
public class AssemblyCatalog : System.ComponentModel.Composition.Primitives.ComposablePartCatalog, System.ComponentModel.Composition.Primitives.ICompositionElement
type AssemblyCatalog = class
inherit ComposablePartCatalog
interface ICompositionElement
Public Class AssemblyCatalog
Inherits ComposablePartCatalog
Implements ICompositionElement
- Inheritance
- Implements
Examples
The following code demonstrates the common scenario of an application creating an AssemblyCatalog to parse its own assembly. This is a straightforward way to load parts contained in a single project into the Managed Extensibility Framework (MEF).
[Export]
class MyAddin
{
public String myData { get { return "The data!"; } }
}
class MyProgram
{
[Import]
public MyAddin myAddin { get; set; }
}
class Program
{
static void Main(string[] args)
{
AggregateCatalog catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(MyAddin).Assembly));
CompositionContainer _container = new CompositionContainer(catalog);
MyProgram myProgram = new MyProgram();
_container.SatisfyImportsOnce(myProgram);
Console.WriteLine(myProgram.myAddin.myData);
Console.ReadLine();
_container.Dispose();
}
}
<Export()>
Public Class MyAddin
Public ReadOnly Property theData As String
Get
Return "The Data!"
End Get
End Property
End Class
Public Class MyProgam
Private _MyAddin As MyAddin
<Import()>
Public Property MyAddinProperty As MyAddin
Get
Return _MyAddin
End Get
Set(ByVal value As MyAddin)
_MyAddin = value
End Set
End Property
End Class
Sub Main()
Dim catalog As AggregateCatalog = New AggregateCatalog()
catalog.Catalogs.Add(New AssemblyCatalog(GetType(MyAddin).Assembly))
Dim container As CompositionContainer = New CompositionContainer(catalog)
Dim theProgam As MyProgam = New MyProgam()
container.SatisfyImportsOnce(theProgam)
Console.WriteLine(theProgam.MyAddinProperty.theData)
Console.ReadLine()
container.Dispose()
End Sub
Remarks
An AssemblyCatalog is used to parse all the parts present in a specified assembly. The target assembly can be indicated either by object reference or by path.
Important
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.
This type is thread safe.
Constructors
| Name | Description |
|---|---|
| AssemblyCatalog(Assembly, ICompositionElement) |
Initializes a new instance of the AssemblyCatalog class with the specified assembly. |
| AssemblyCatalog(Assembly, ReflectionContext, ICompositionElement) |
Initializes a new instance of the AssemblyCatalog class with the specified assembly and reflection context. |
| AssemblyCatalog(Assembly, ReflectionContext) |
Initializes a new instance of the AssemblyCatalog class with the specified assembly and reflection context. |
| AssemblyCatalog(Assembly) |
Initializes a new instance of the AssemblyCatalog class with the specified assembly. |
| AssemblyCatalog(String, ICompositionElement) |
Initializes a new instance of the AssemblyCatalog class with the specified code base. |
| AssemblyCatalog(String, ReflectionContext, ICompositionElement) |
Initializes a new instance of the AssemblyCatalog class with the specified code base and reflection context. |
| AssemblyCatalog(String, ReflectionContext) |
Initializes a new instance of the AssemblyCatalog class with the specified code base and reflection context. |
| AssemblyCatalog(String) |
Initializes a new instance of the AssemblyCatalog class with the specified code base. |
Properties
| Name | Description |
|---|---|
| Assembly |
Gets the assembly whose attributed types are contained in the assembly catalog. |
| Parts |
Gets the part definitions that are contained in the catalog. (Inherited from ComposablePartCatalog) |
Methods
| Name | Description |
|---|---|
| Dispose() |
Releases all resources used by the ComposablePartCatalog. (Inherited from ComposablePartCatalog) |
| Dispose(Boolean) |
Releases the unmanaged resources used by the AssemblyCatalog and optionally releases the managed resources. |
| GetEnumerator() |
Returns an enumerator that iterates through the catalog. |
| GetExports(ImportDefinition) |
Gets a collection of exports that match the conditions specified by the import definition. |
| ToString() |
Gets a string representation of the assembly catalog. |
Explicit Interface Implementations
| Name | Description |
|---|---|
| ICompositionElement.DisplayName |
Gets the display name of the AssemblyCatalog object. |
| ICompositionElement.Origin |
Gets the composition element that this element originated from. |
| IEnumerable.GetEnumerator() |
Returns an enumerator that iterates through the catalog. (Inherited from ComposablePartCatalog) |
Extension Methods
| Name | Description |
|---|---|
| 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. |
| ToAsyncEnumerable<TSource>(IEnumerable<TSource>) |
Creates a new IAsyncEnumerable<T> that iterates through |
| ToFrozenDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>) |
Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector and element selector functions. |
| ToFrozenDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>) |
Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector function. |
| ToFrozenSet<T>(IEnumerable<T>, IEqualityComparer<T>) |
Creates a FrozenSet<T> with the specified values. |
| ToImmutableArray<TSource>(IEnumerable<TSource>) |
Creates an immutable array from the specified collection. |
| ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>, IEqualityComparer<TValue>) |
Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key and value comparers. |
| ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>) |
Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key comparer. |
| ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>) |
Enumerates and transforms a sequence, and produces an immutable dictionary of its contents. |
| ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>) |
Constructs an immutable dictionary based on some transformation of a sequence. |
| ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) |
Constructs an immutable dictionary from an existing collection of elements, applying a transformation function to the source keys. |
| ToImmutableHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>) |
Enumerates a sequence, produces an immutable hash set of its contents, and uses the specified equality comparer for the set type. |
| ToImmutableHashSet<TSource>(IEnumerable<TSource>) |
Enumerates a sequence and produces an immutable hash set of its contents. |
| ToImmutableList<TSource>(IEnumerable<TSource>) |
Enumerates a sequence and produces an immutable list of its contents. |
| ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>, IEqualityComparer<TValue>) |
Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key and value comparers. |
| ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>) |
Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key comparer. |
| ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>) |
Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents. |
| ToImmutableSortedSet<TSource>(IEnumerable<TSource>, IComparer<TSource>) |
Enumerates a sequence, produces an immutable sorted set of its contents, and uses the specified comparer. |
| ToImmutableSortedSet<TSource>(IEnumerable<TSource>) |
Enumerates a sequence and produces an immutable sorted set of its contents. |