簡體   English   中英

類未實現接口成員

[英]Class does not implement interface member

這是我的第一個問題,因此,如果它不能真正與某些更高級的問題相提並論,請原諒。 我主要是Java開發人員,但是最近我開始使用C#,所以我決定選擇Photon Networking Library,以便開始將我使用Unity3D作為愛好創建的Game實施它。

我收到的錯誤如下:

錯誤1'MMO.Photon.Server.PhotonServerHandler'未實現接口成員'MMO.Framework.IHandler.HandleMeessage(MMO.Framework.IMessage,MMO.Photon.Server.PhotonServerPeer)'c:\\ users \\ boyz \\ documents \\ visual studio 2012 \\ Projects \\ MMO.Framework \\ MMO.PhotonFramework \\ Server \\ PhotonServerHandler.cs 11 27 MMO.Photon

據我所知,它並不是在真正實現接口,但是我卻並不完全了解它是如何工作的。 因此,我僅向您展示這里有問題的課程。

PhotonServerHandler是錯誤產生的類(或看起來是這樣)

namespace MMO.Photon.Server
{
    public abstract class PhotonServerHandler : IHandler<PhotonServerPeer>
    {
        public abstract MessageType Type { get; }
        public abstract byte Code { get; }
        public abstract int? SubCode { get; }
        protected PhotonApplication Server;

        public PhotonServerHandler(PhotonApplication application)
        {
            this.Server = application;
        }

        public bool HandleMessage(IMessage message, PhotonServerPeer serverPeer)
        {
            OnHandleMessage(message, serverPeer);
            return true;
        }

        protected abstract bool OnHandleMessage(IMessage message, PhotonServerPeer serverPeer);
    }
}

然后是要導入或繼承的IHandler; 但是,您用C#來寫它。

namespace MMO.Framework
{
    public interface IHandler<T>
    {
        MessageType Type { get; }
        byte Code { get; }
        int? SubCode { get; }
        bool HandleMeessage(IMessage message, T peer);
    }
}

最后但同樣重要的是,我們有PhotonServerPeer類

namespace MMO.Photon.Server
{
    public class PhotonServerPeer : ServerPeerBase
    {
        private readonly PhotonServerHandlerList handlerList;
        protected readonly PhotonApplication Server;

        #region Factory Method

        public delegate PhotonServerPeer Factory(IRpcProtocol protocol, IPhotonPeer photonPeer);

        #endregion

        public PhotonServerPeer(IRpcProtocol protocol, IPhotonPeer photonPeer, PhotonServerHandlerList handlerList, PhotonApplication application) : base(protocol, photonPeer)
        {
            this.handlerList = handlerList;
            this.Server = application;
        }

        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            handlerList.HandleMessage(new PhotonRequest(operationRequest.OperationCode, operationRequest.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(operationRequest.Parameters[Server.SubCodeParameterKey]) : null, operationRequest.Parameters), this);
        }

        protected override void OnEvent(IEventData eventData, SendParameters sendParameters)
        {
           handlerList.HandleMessage(new PhotonEvent(eventData.Code, eventData.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(eventData.Parameters[Server.SubCodeParameterKey]) : null, eventData.Parameters), this);
        }

        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            handlerList.HandleMessage(new PhotonResponse(operationResponse.OperationCode, operationResponse.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(operationResponse.Parameters[Server.SubCodeParameterKey]) : null, operationResponse.Parameters, operationResponse.DebugMessage, operationResponse.ReturnCode), this);

        }

        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
            //Server.ConnectionCollection.OnDisconnect(this);
        }
    }
}

我完全不理解此錯誤,這已經困擾了我幾個小時,我已經嘗試了所有我知道的方法,正在進行一些谷歌搜索,這可能只是我錯過的一個非常基本的錯誤,但會有所幫助。

您目前在PhotonServerHandler擁有public bool HandleMessage ,但該錯誤抱怨PhotonServerHandler沒有實現HandleMeessage

您似乎在這里輸入錯字了:

public interface IHandler<T>
{
    MessageType Type { get; }
    byte Code { get; }
    int? SubCode { get; }
    bool HandleMeessage(IMessage message, T peer);
}

HandleMeessage重命名為HandleMessage ,該特定錯誤應消失。

就我而言,它是-“類未實現接口成員INativeObject.Handle”

我剛剛用NSObject繼承了我的課程,並且問題得到了解決。

暫無
暫無

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

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