c# – 如果将委托定义放在另一个项目中,则编译失败?
更新:我已经提交了这个作为
an issue on Microsoft Connect,如果你可以重现这个和/或希望看到这个修复,请帮助在那里投票问题.
我一直试图解决这个问题几个小时了. 首先,我有3个文件Class.cs Definitions.cs和Program.cs.我在http://pastie.org/1049492粘贴了文件内容供您试用. 问题是,如果在同一个控制台应用程序项目中有所有3个文件.应用程序编译并运行得很好. 但是,如果我在一个“库”项目中有Class.cs和Definitions.cs,它从只有Program.cs文件的主控制台应用程序项目中引用,则编译失败: >代表法没有2个论点. 这是一个包含3个项目的完整解决方案 – 1个将所有文件组合在一起,另一个项目放在另一个项目中: 我正在使用VS2010 RTW专业版. 解决方法
有趣.我认为你在C#编译器中发现了一个实际的错误 – 虽然我可能会遗漏一些微妙的东西.我写了一个稍微简化的版本,避免了重载等的可能性,并且省去了额外的方法:
// Definitions.cs public interface IData { } public delegate IData Foo(IData input); public delegate IData Bar<T>(IData input,T extraInfo); public delegate Foo Produce<T>(Bar<T> next); // Test.cs class Test { static void Main() { Produce<string> produce = next => input => next(input,"This string should appear."); } } 演示编译为一个程序集,没有错误: > csc Test.cs Definitions.cs 演示编译为具有错误的两个程序集: > csc /target:library Definitions.cs > csc Test.cs /r:Definitions.dll Test.cs(5,43): error CS1662: Cannot convert lambda expression to delegate type 'Produce<string>' because some of the return types in the block are not implicitly convertible to the delegate return type Test.cs(5,52): error CS1593: Delegate 'Bar' does not take 2 arguments 我想不出有什么理由为什么在不同的集会中这应该是不同的,因为一切都是公开的.除内部原因外,该规范很少讨论装配边界. 有趣的是,我对C#3和4编译器都有同样的错误. 现在通过电子邮件发送Eric和Mads …… 编辑:请注意,您可以使用显式参数列表解决此问题.例如,在我的示例代码中,这将起作用: Produce<string> produce = (Bar<string> next) => input => next(input,"This string should appear."); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Swift闭包详解
- server.xml和resfile.properties配置实现图片查询
- 原生态ajax——如何判断浏览器
- C#自定义控件VS用户控件
- 如何使用sqlite后端为python blaze提供用户定义的函数?
- ajax 报错 400 (Failed to load resource: the server resp
- 正则表达式--replaceAll
- xml – E4X选择节点,其中后代可以是A OR B或A \u0026&#
- 百度地图自定义标注、信息窗口、多种类聚合、主题(一篇呕心
- ruby-on-rails – RoR Net :: HTTP post error undefined方