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:
RoosterDragon
2014-05-21 06:19:26 +01:00
parent 334a210231
commit a598a01108
37 changed files with 248 additions and 260 deletions

View File

@@ -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)