日期:2014-05-18 浏览次数:20885 次
using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.Reflection; namespace HelloWorld { class Program { [Import] public string Message { get; set; } public class SimpleHello { [Export] public string Message { get { return "Hello World!"; } } } public void Run() { var catalog=new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly()); var container=new CompositionContainer(catalog.CreateResolver()); container.AddPart(this); container.Compose(); Console.WriteLine(Message); Console.ReadKey(); } static void Main(string[] args) { Program pg = new Program(); pg.Run(); } } }