我做了一個非常簡單的MEF示例,它運行在.NET上, 但在Mono上無法正常工作。單聲道MEF無法正常工作?
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Composition;
namespace Vialis
{
class Program
{
[Import(typeof(ILedController))]
public List<ILedController> Controllers
{
get;
set;
}
static void Main(string[] args)
{
new Program();
}
public Program()
{
compose();
selectController();
Console.ReadLine();
}
private void compose()
{
var catalog = new DirectoryPartCatalog("controllers");
var container = new CompositionContainer(catalog);
container.AddPart(this);
container.Compose();
}
private void selectController()
{
Console.Clear();
Console.WriteLine("Please select the controller to use\n");
byte i = 0;
foreach (var controller in Controllers)
{
Console.WriteLine("\t{0}) {1}", i, controller.ToString());
i++;
}
Console.Write("\nYour selection: ");
var input = Convert.ToInt32(Console.ReadLine());
Controllers[input].DisplayText(10, 10, "Hello World");
}
}
}
這是接口:
using System;
using System.Collections.Generic;
using System.Text;
namespace Vialis
{
public interface ILedController
{
void DisplayText(int x, int y, string text);
}
}
這是第一個實現:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Composition;
namespace Vialis
{
[Export(typeof(ILedController))]
public class LyanController : ILedController
{
public void DisplayText(int x, int y, string text)
{
Console.SetCursorPosition(x, y);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(text);
}
}
}
第二種方案:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Composition;
namespace Vialis
{
[Export(typeof(ILedController))]
public class VialisController : ILedController
{
public void DisplayText(int x, int y, string text)
{
Console.SetCursorPosition(x, y);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(text);
}
}
}
這是.NET會發生什麼(Windows):
選擇控制器:
但使用單聲道2.2的組件不加載:
有什麼建議嗎?
信息:谷歌似乎有一些picasa網絡問題, 這就是爲什麼圖像不加載。
圖片顯示,在Mac OS上,沒有列出控制器。
在我的新聞閱讀器圖片顯示正確(谷歌閱讀器),但在本網站上,他們不是...奇數 – TimothyP 2009-01-25 14:59:01