0
我刚刚通过nuget在WebSocketSharp
。
它是类WebSocket
implements IDisposable
但似乎没有Dispose
方法。
这怎么可能?我想如果你实现一个接口,你也必须实现它的所有属性/方法。实现IDisposable无Dispose函数的类?
我刚刚通过nuget在WebSocketSharp
。
它是类WebSocket
implements IDisposable
但似乎没有Dispose
方法。
这怎么可能?我想如果你实现一个接口,你也必须实现它的所有属性/方法。实现IDisposable无Dispose函数的类?
在GitHub上的source:
#region Explicit Interface Implementations
/// <summary>
/// Closes the WebSocket connection, and releases all associated resources.
/// </summary>
/// <remarks>
/// This method closes the connection with <see cref="CloseStatusCode.Away"/>.
/// </remarks>
void IDisposable.Dispose()
{
close (new CloseEventArgs (CloseStatusCode.Away), true, true, false);
}
#endregion
谢谢,非常有趣! –
明确实施。请参阅https://github.com/sta/websocket-sharp/blob/master/websocket-sharp/WebSocket.cs#L3073(以及http://stackoverflow.com/questions/4103300/why-implement-interface-explicitly) – haim770
只是一个想法,也许有人可以证实这一点 - 如果接口方法是显式实现的('显式接口实现'),它会显示在这里吗?也许是这样的。 –
它有一个明确的实现,并有一个Close()方法。这是一种常见的模式。 –