首页 新闻 会员 周边

MEF为什么GetExports<T>()为什么会一直不返回

0
悬赏园豆:15 [已关闭问题] 关闭于 2017-01-12 14:48
public interface IProtocol
{
/// <summary>
/// 下载事件
/// </summary>
event DownloadEventHanlder DownloadEvent;
/// <summary>
/// 下载数据
/// </summary>
/// <param name="datas"></param>
void DownloadDatas(byte[] datas);
}

public interface IProtocolMessage
{
/// <summary>
/// 协议版本
/// </summary>
string Version { get; set; }
}

定义了两个插件接口,然后一个抽象类DeviceNetAdapterBase继承这个接口

public abstract class DeviceNetAdapterBase : IProtocol
{
//中间代码
}

最后实现类  

    [Export(typeof(IProtocol))]
    [ExportMetadata("Version", "1.0.0.1")]
    public class MGProtocol : DeviceNetAdapterBase
    {
          //中间代码实现
    }

最后在加载这个插件

//StaticConfig.Config.PlugDir是生成的插件放dll的目录
var directoryNetPlugCatalog = new DirectoryCatalog(StaticConfig.Config.PlugDir, "*.dll");
//
var containerProtocol = new CompositionContainer(directoryNetPlugCatalog);

//这里导出插件。其实定义的全局的,为了看的清放到这里,也就是这里就卡住了一直不返回值,这个函数就走不下去了
private IEnumerable<Lazy<IProtocol,IProtocolMessage>> protocalHanders = containerProtocol.GetExports<IProtocol, IProtocolMessage>();

也不知道为什么,我有两种接口的插件放到不同目录下,起初以为是两种插件要导入的原因,但是现在把另一个已经注释了,就剩下这个也不行。一直在GetExports这里卡住不返回。

小书丶的主页 小书丶 | 初学一级 | 园豆:154
提问于:2016-08-12 14:33
< >
分享
所有回答(1)
0

C#什么时候有了这种语法,卡住不动多半是死循环了。

长蘑菇星人 | 园豆:1832 (小虾三级) | 2016-08-12 14:37

没有循环啊

支持(0) 反对(0) 小书丶 | 园豆:154 (初学一级) | 2016-08-12 14:43

@风过之后的晴: 你F1 一下GetExports的帮助吧

支持(0) 反对(0) 长蘑菇星人 | 园豆:1832 (小虾三级) | 2016-08-12 15:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册