简体   繁体   English

类未实现接口成员

[英]Class does not implement interface member

this is my first question here so please do excuse if it's not really up to par with some of the more advanced questions. 这是我的第一个问题,因此,如果它不能真正与某些更高级的问题相提并论,请原谅。 I'm mainly a Java developer however I recently started moving over the C# and I decided to pick up the Photon Networking Library in order to start implementing it with my Game that I'm creating using Unity3D as a Hobby. 我主要是Java开发人员,但是最近我开始使用C#,所以我决定选择Photon Networking Library,以便开始将我使用Unity3D作为爱好创建的Game实施它。

The error that I'm receiving is as follows: 我收到的错误如下:

Error 1 'MMO.Photon.Server.PhotonServerHandler' does not implement interface member '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 错误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

Which I don't really understand, as far as I'm aware it is implementing the interface, but I don't really understand how it works completely. 据我所知,它并不是在真正实现接口,但是我却并不完全了解它是如何工作的。 So I'll just show you the classes that are at question here. 因此,我仅向您展示这里有问题的课程。

PhotonServerHandler is the class that the error derives from (or so it seems) 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);
    }
}

Then there's the IHandler which it's importing or inheriting from; 然后是要导入或继承的IHandler; However you word it in C#. 但是,您用C#来写它。

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

Then last but not least, we have the PhotonServerPeer class 最后但同样重要的是,我们有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);
        }
    }
}

I don't understand this error at all and It's been bothering me for a few hours now and I've tried everything I know how, I've been doing some googling and it might just be a very basic mistake which I've missed, but any help would be appreciated. 我完全不理解此错误,这已经困扰了我几个小时,我已经尝试了所有我知道的方法,正在进行一些谷歌搜索,这可能只是我错过的一个非常基本的错误,但会有所帮助。

You've currently got public bool HandleMessage in PhotonServerHandler , but the error is complaining that PhotonServerHandler doesn't implement HandleMeessage . 您目前在PhotonServerHandler拥有public bool HandleMessage ,但该错误抱怨PhotonServerHandler没有实现HandleMeessage

Looks like you've got a typo here: 您似乎在这里输入错字了:

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

Rename HandleMeessage to HandleMessage and that particular error should disappear. HandleMeessage重命名为HandleMessage ,该特定错误应消失。

In my case it was - "Class does not implement interface member INativeObject.Handle" 就我而言,它是-“类未实现接口成员INativeObject.Handle”

I just inherited my class with NSObject and issue got fixed. 我刚刚用NSObject继承了我的课程,并且问题得到了解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM