Fixed IDisposable implementation and usage.
- Implement IDisposable interface correctly, with sealed classes where possible for simplicity. - Add using statement around undisposed local variables.
This commit is contained in:
@@ -17,7 +17,7 @@ using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Irc
|
||||
{
|
||||
public class IrcClient : IDisposable
|
||||
public sealed class IrcClient : IDisposable
|
||||
{
|
||||
public static readonly IrcClient Instance = new IrcClient();
|
||||
|
||||
@@ -252,14 +252,15 @@ namespace OpenRA.Irc
|
||||
|
||||
ConnectionState = IrcConnectionState.Disconnecting;
|
||||
OnDisconnecting();
|
||||
connection.Close();
|
||||
if (connection != null)
|
||||
connection.Close();
|
||||
ConnectionState = IrcConnectionState.Disconnected;
|
||||
OnDisconnect();
|
||||
LocalUser = null;
|
||||
connection = null;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
public void Dispose()
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Net.Sockets;
|
||||
|
||||
namespace OpenRA.Irc
|
||||
{
|
||||
public class IrcConnection : IDisposable
|
||||
public sealed class IrcConnection : IDisposable
|
||||
{
|
||||
TcpClient socket;
|
||||
Stream stream;
|
||||
@@ -49,14 +49,8 @@ namespace OpenRA.Irc
|
||||
|
||||
public void Close()
|
||||
{
|
||||
CloseImpl();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
void CloseImpl()
|
||||
{
|
||||
if (disposed) return;
|
||||
|
||||
if (disposed)
|
||||
return;
|
||||
disposed = true;
|
||||
if (socket != null) socket.Close();
|
||||
if (stream != null) stream.Close();
|
||||
@@ -64,16 +58,11 @@ namespace OpenRA.Irc
|
||||
if (reader != null) reader.Close();
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
public void Dispose()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
~IrcConnection()
|
||||
{
|
||||
CloseImpl();
|
||||
}
|
||||
|
||||
void CheckDisposed()
|
||||
{
|
||||
if (disposed)
|
||||
|
||||
Reference in New Issue
Block a user