2011-01-24 31 views
2

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

回答

3

編輯項目的引用(在MonoDevelop的解決方案資源管理器中右鍵單擊「引用」)並在全局程序集緩存選項卡中找到System.Core。選中它旁邊的複選框並點擊「確定」

+1

還檢查你是否引用至少.NET 3.0 - 你可以在項目屬性中,如果我沒有記錯,在Build下執行此操作 – JohnL 2011-01-24 16:09:22

+0

.NET 3.5,不是3.0 – 2011-01-24 22:20:41

-2

//這是否容易?

using System.Core;