110,538
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
}
public void Run()
{
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
Console.WriteLine(Message);
Console.ReadKey();
}