使用 mono 的扩展方法
如何添加对 System.Core.dll 程序集的引用?
我正在尝试使用 mono 编译扩展方法。我有这个代码:
using System;
using System.Net;
using System.Net.Sockets;
namespace My.Util
{
public static class SocketReturnTypeCovariants
{
public static IPEndPoint RemoteEndPoint_safe(this Socket soc)
{
return soc.RemoteEndPoint as IPEndPoint;
}
}
}
我收到此错误。
/home/richard/d/trash/mono/return-type-covariance/return-type-covariance/Main.cs(34,34): Error CS1110: `My.Util.SocketReturnTypeCovariants.RemoteEndPoint_safe(this System.Net.Sockets.Socket)': Extension methods cannot be declared without a reference to System.Core.dll assembly. Add the assembly reference or remove `this' modifer from the first parameter (CS1110) (return-type-covariance)
那么如何添加对 System.Core.dll 程序集的引用呢?
How do I add a reference to System.Core.dll assembly?
I am trying to compile an extension method using mono. I have this code:
using System;
using System.Net;
using System.Net.Sockets;
namespace My.Util
{
public static class SocketReturnTypeCovariants
{
public static IPEndPoint RemoteEndPoint_safe(this Socket soc)
{
return soc.RemoteEndPoint as IPEndPoint;
}
}
}
I get this error.
/home/richard/d/trash/mono/return-type-covariance/return-type-covariance/Main.cs(34,34): Error CS1110: `My.Util.SocketReturnTypeCovariants.RemoteEndPoint_safe(this System.Net.Sockets.Socket)': Extension methods cannot be declared without a reference to System.Core.dll assembly. Add the assembly reference or remove `this' modifer from the first parameter (CS1110) (return-type-covariance)
So how do I add a reference to System.Core.dll assembly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑项目的引用(右键单击 MonoDevelop 解决方案资源管理器中的“引用”)并在“全局程序集缓存”选项卡中找到 System.Core。选中旁边的框并单击“确定”
Edit the references of your project (right click on "References" in MonoDevelop's solution explorer) and find System.Core in the Global Assembly Cache tab. Check the box next to it and click "OK"
// 就这么简单吗?
使用系统核心;
// Is it as easy as this?
using System.Core;