首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

MEF太难了,根本搞不懂。解决方案

2012-04-25 
MEF太难了,根本搞不懂。下载了一个入门代码,里面有几个东西,在MSDN上面都查不到的,比如AttributedAssemblyP

MEF太难了,根本搞不懂。
下载了一个入门代码,里面有几个东西,在MSDN上面都查不到的,比如AttributedAssemblyPartCatalog

在主函数Run里面的。
根本没有这个东西啊,调试不出来。。。
哪儿错了?


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


[解决办法]
MEF 接口就那么几个,应该不难学。要看源码直接从 codeplex 上下好了。

热点排行