簡體   English   中英

對單聲道使用擴展方法

[英]using extension methods with 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程序集的引用?

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

//這樣簡單嗎?

使用System.Core;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM