C# 在mono中使用扩展方法

C# 在mono中使用扩展方法,c#,mono,extension-methods,C#,Mono,Extension Methods,如何添加对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 S

如何添加对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程序集的引用呢?

编辑项目的引用(右键单击MonoDevelop解决方案资源管理器中的“引用”),并在全局程序集缓存选项卡中查找System.Core。选中它旁边的复选框并单击“确定”

//是否像这样简单


使用系统内核

使用
不会添加程序集引用。它只是使命名空间中已引用程序集的类型可以用较短的名称访问,因为您不再需要指定命名空间。另外,请检查您是否至少引用了.NET 3.0-如果我没记错,您可以在“项目属性”下的“生成”中执行此操作