在单声道上运行 MEF

发布于 2024-11-14 17:02:48 字数 1331 浏览 1 评论 0原文

我尝试编译从 此页面复制的 MEF 代码

using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;
using System;

public class Program
{
[Import]
public IMessageSender MessageSender { get; set; }

public static void Main(string[] args)
{
 Program p = new Program();
 p.Run();
}

public void Run()
{
 Compose();
 MessageSender.Send("Message Sent");
}

private void Compose()
{
 AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
 var container = new CompositionContainer(catalog);
 container.ComposeParts(this);
}
}

public interface IMessageSender
{
void Send(string message);
}

[Export(typeof(IMessageSender))]
public class EmailSender : IMessageSender
{
public void Send(string message)
{
 Console.WriteLine(message);
}
}

当我运行此命令 dmcs example.cs 时,我收到此错误消息。

ex.cs(1,29): error CS0234: The type or namespace name `Composition' does not exist in the namespace `System.ComponentModel'. Are you missing an assembly reference?

我需要提供什么参考库才能删除此错误消息?

添加了

dmcs ex.cs /r:System.ComponentModel.Composition.dll 有效。人们不必从 codeplex 下载 dll。

I tried to compile the MEF code copied from this page.

using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;
using System;

public class Program
{
[Import]
public IMessageSender MessageSender { get; set; }

public static void Main(string[] args)
{
 Program p = new Program();
 p.Run();
}

public void Run()
{
 Compose();
 MessageSender.Send("Message Sent");
}

private void Compose()
{
 AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
 var container = new CompositionContainer(catalog);
 container.ComposeParts(this);
}
}

public interface IMessageSender
{
void Send(string message);
}

[Export(typeof(IMessageSender))]
public class EmailSender : IMessageSender
{
public void Send(string message)
{
 Console.WriteLine(message);
}
}

When I run this command dmcs example.cs I got this error message.

ex.cs(1,29): error CS0234: The type or namespace name `Composition' does not exist in the namespace `System.ComponentModel'. Are you missing an assembly reference?

What reference library do I need to give to remove this error message?

ADDED

dmcs ex.cs /r:System.ComponentModel.Composition.dll works. One doesn't have to download the dlls from codeplex.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-11-21 17:02:48

我认为 MEF 是否包含在 Mono 中不是问题......但您需要 MEF 库(不包含在 Mono 库中)。从 Codeplex 下载该库。然后从您的项目中引用它。如果可行,那么 Mono 可能会很好地使用它。

Whether or not MEF is included in Mono isn't the issue, I think ... but that you need the MEF library (not included in Mono libraries). Download the library from Codeplex. Then reference it from your project. If that works, then Mono may play nice with it.

故事↓在人 2024-11-21 17:02:48

据我了解,MEF 目前还不是 Mono 的一部分。 Mono 与 AddIn 具有“相似”的构造,但与 MEF 不同。此时,在 Mono 中创建 MEF 就意味着推出您自己的 MEF,除非我错过了一些新的魔法。

Per my understanding, MEF is not part of Mono at this time. Mono has a "similar" construct with AddIn, but it is not identical to MEF. At this time, creating MEF in Mono would mean rolling your own, unless there is some new magic I am missing out on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文