1

我现有的代码可以在 Caliburn Micro 1.4 上编译并正常工作:

private static readonly Lazy<IShell> shellLazy = new Lazy<IShell>(IoC.Get<IShell>, true);

我删除了 1.4 版本并通过 NuGet 安装了 1.5 版本,并且没有更改任何内容,此行现在会引发错误:

错误 1 ​​'System.Lazy.Lazy(System.Func, System.Threading.LazyThreadSafetyMode)' 的最佳重载方法匹配有一些无效参数 C:\Users\User\Documents\Visual Studio 2012\Projects\Arnova\Src\CShellCore \Shell.cs 35 58 CShellCore

我发现摆脱这个错误的唯一方法是完全避免使用 Lazy<> :

private static readonly IShell shellLazy = IoC.Get<IShell>();

我已经搜索了与 IoC.Get<> 和 Lazy<> 相关的任何内容,以及从 1.4 版到 1.5 版可能发生的变化,但找不到任何东西来解释 Caliburn Micro 在这些版本之间发生了什么变化以及如何解决这个问题。

4

2 回答 2

0

我认为你的问题是这IoC.Get<T>是一个static返回 type 实例的方法,T换句话说,解决问题不是这样,你必须像Func<T>这样修改你的代码:

private static readonly Lazy<IShell> shellLazy = new Lazy<IShell>(() => IoC.Get<IShell>(), true); 

Lazy<>这就是编译错误的原因,即在接受IShell实例的类型上没有构造函数。

于 2013-07-05T21:10:19.773 回答
0

找到了,不知道为什么需要这样改变?智能感知显示 1.4 和 1.5 caliburn micro 版本的相同信息,这些函数看起来需要相同的参数。

到目前为止,这似乎有效:

private static readonly Lazy<IShell> shellLazy = new Lazy<IShell>(() => { return IoC.Get<IShell>(); }, true);
于 2013-07-08T18:34:12.643 回答