A Catalog is a container that lists Parts where each Part is actually mapped to a Type which individually hosts a number of Exports in forms of ExportDefination and number of Import in forms of ImportDefinations. An AssemblyCatalog is actually a collection of TypeCatalogs where the Types are actually defined within one particular assembly.
Lets take a look at AssemblyCatalog using our previous code :
public class ExportContainer
{
[Export]
public string ExportName { get; set; }
[Export]
public string GetName()
{
return this.ExportName;
}
[Export]
public Action MyActionDelegate { get; set; }
}
Now if I use Assemblycatalog to load the Catalog into Parts we write :
static void Main(string[] args)
{
AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
Console.WriteLine(catalog.Parts.Count());
Console.ReadKey(true);
}
Read more: Daily .Net Tips
QR: