MEF 和 DirectoryCatalog
有没有办法安全地使用 DirectoryCatalog 来处理目录不存在的情况?
这是我的容器如何设置的代码示例:
//Create an assembly catalog of the assemblies with exports
var catalog = new AggregateCatalog(
new AssemblyCatalog(Assembly.GetExecutingAssembly()),
new AssemblyCatalog(Assembly.Load("My.Second.Assembly")),
new DirectoryCatalog("Plugins", "*.dll"));
//Create a composition container
var container = new CompositionContainer(catalog);
但是如果目录不存在,则会引发异常,我想忽略该错误。
Is there a way to safely use DirectoryCatalog to handle if the directory doesn't exist?
Here a code example of how my container is setup:
//Create an assembly catalog of the assemblies with exports
var catalog = new AggregateCatalog(
new AssemblyCatalog(Assembly.GetExecutingAssembly()),
new AssemblyCatalog(Assembly.Load("My.Second.Assembly")),
new DirectoryCatalog("Plugins", "*.dll"));
//Create a composition container
var container = new CompositionContainer(catalog);
But an exception is thrown if the directory doesn't exist, and I would like to ignore that error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果抛出异常,显然不会。只需在运行 MEF 容器设置之前创建目录,就不会抛出任何错误。
根据文档:
进行目录检查的伪代码:
Apparently not if an exception is thrown. Just create the directory prior to running the MEF container setup and then no error will be thrown.
According to the documentation:
PsuedoCode to do a directory check: