2014-07-10 82 views
1

這是我的第一個問題,所以請原諒,如果它不是真的與一些更高級的問題相提並論。我主要是Java開發人員,但是我最近開始轉移C#,並決定選擇Photon Networking Library,以便開始使用我使用Unity3D作爲Hobby創建的遊戲來實現它。班級不實施接口成員

我正在接收的錯誤是如下:

錯誤1 'MMO.Photon.Server.PhotonServerHandler' 不實現接口成員「MMO.Framework.IHandler.HandleMeessage(MMO.Framework。即時聊天,MMO.Photon.Server.PhotonServerPeer)」 C:\用戶\ BOYZ \文件\的Visual Studio 2012 \項目\ MMO.Framework \ MMO.PhotonFramework \服務器\ 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); 
     } 
    } 
} 

我完全不理解這個錯誤,它已經現在困擾我幾個小時,我用盡了一切我知道如何,我一直在做一些Google搜索,這可能只是我錯過的一個非常基本的錯誤,但任何幫助,將不勝感激。

回答

4

您目前得到public bool HandleMessagePhotonServerHandler,但錯誤是抱怨PhotonServerHandler沒有執行HandleMeessage

看起來你已經有了一個錯字這裏:

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

重命名HandleMeessageHandleMessage和特定的錯誤應該消失。

+3

哦......我......上帝......時間浪費在錯字上。非常感謝你指出這一點,我正要開始拉頭髮。 – user3822547

+2

@ user3822547 VS/R#支持自動實現接口 - 只需讓它實現接口並查看不匹配的地方。沒有意義花費「小時」。 –

+0

@AlexeiLevenkov礦以前沒有,但我沒有接受過ReSharper,之後也沒有任何問題。 – user3822547

0

在我的情況是 - 「類不實現接口成員INativeObject.Handle」

我剛剛繼承我的類的NSObject和問題得到了解決。

相關問題