繁体   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