Skip to content

Commit

Permalink
Problem: There are CA1063 warnings related to the implementation of I…
Browse files Browse the repository at this point in the history
…Disposable

Solution: Fix implementations of Dispose, class and method modifiers
  • Loading branch information
sigiesec committed May 17, 2017
1 parent b1bff0c commit ff48f0b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
7 changes: 3 additions & 4 deletions ZContext.cs
Expand Up @@ -9,7 +9,7 @@ namespace ZeroMQ
/// <summary>
/// Creates <see cref="ZSocket"/> instances within a process boundary.
/// </summary>
public class ZContext : IDisposable
public sealed class ZContext : IDisposable
{
static Encoding _encoding = System.Text.Encoding.UTF8;

Expand All @@ -20,7 +20,6 @@ public class ZContext : IDisposable
public static Encoding Encoding
{
get { return _encoding; }
protected set { _encoding = value; }
}

private static readonly object SyncObject = new object();
Expand Down Expand Up @@ -323,13 +322,13 @@ public bool Terminate(out ZError error)
return true;
}

public virtual void Dispose()
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}

protected virtual void Dispose(bool disposing)
void Dispose(bool disposing)
{
if (disposing)
{
Expand Down
24 changes: 12 additions & 12 deletions ZFrame.cs
Expand Up @@ -13,7 +13,7 @@ namespace ZeroMQ
/// <summary>
/// A single part message, sent or received via a <see cref="ZSocket"/>.
/// </summary>
public class ZFrame : Stream, ICloneable, IDisposable
public sealed class ZFrame : Stream, ICloneable
{
public static ZFrame FromStream(Stream stream, long i, int l)
{
Expand Down Expand Up @@ -145,7 +145,7 @@ public ZFrame()
: this(Alloc(data, size), size)
{ } */

protected ZFrame(DispoIntPtr frameIntPtr, int size)
internal ZFrame(DispoIntPtr frameIntPtr, int size)
: base()
{
framePtr = frameIntPtr;
Expand Down Expand Up @@ -375,7 +375,7 @@ public override int ReadByte()
return byt;
}

public virtual byte ReadAsByte()
public byte ReadAsByte()
{
if (position + 1 > Length)
return default(byte);
Expand All @@ -385,7 +385,7 @@ public virtual byte ReadAsByte()
return byt;
}

public virtual Int16 ReadInt16()
public Int16 ReadInt16()
{
var bytes = new byte[2];
int len = Read(bytes, 0, 2);
Expand All @@ -397,7 +397,7 @@ public virtual Int16 ReadInt16()
return BitConverter.ToInt16(bytes, 0);
}

public virtual UInt16 ReadUInt16()
public UInt16 ReadUInt16()
{
var bytes = new byte[2];
int len = Read(bytes, 0, 2);
Expand All @@ -409,7 +409,7 @@ public virtual UInt16 ReadUInt16()
return BitConverter.ToUInt16(bytes, 0);
}

public virtual Char ReadChar()
public Char ReadChar()
{
var bytes = new byte[2];
int len = Read(bytes, 0, 2);
Expand All @@ -421,7 +421,7 @@ public virtual Char ReadChar()
return BitConverter.ToChar(bytes, 0);
}

public virtual Int32 ReadInt32()
public Int32 ReadInt32()
{
var bytes = new byte[4];
int len = Read(bytes, 0, 4);
Expand All @@ -433,7 +433,7 @@ public virtual Int32 ReadInt32()
return BitConverter.ToInt32(bytes, 0);
}

public virtual UInt32 ReadUInt32()
public UInt32 ReadUInt32()
{
var bytes = new byte[4];
int len = Read(bytes, 0, 4);
Expand All @@ -445,7 +445,7 @@ public virtual UInt32 ReadUInt32()
return BitConverter.ToUInt32(bytes, 0);
}

public virtual Int64 ReadInt64()
public Int64 ReadInt64()
{
var bytes = new byte[8];
int len = Read(bytes, 0, 8);
Expand All @@ -457,7 +457,7 @@ public virtual Int64 ReadInt64()
return BitConverter.ToInt64(bytes, 0);
}

public virtual UInt64 ReadUInt64()
public UInt64 ReadUInt64()
{
var bytes = new byte[8];
int len = Read(bytes, 0, 8);
Expand Down Expand Up @@ -616,7 +616,7 @@ public override void Write(byte[] buffer, int offset, int count)
position += count;
}

public virtual void Write(byte value)
public void Write(byte value)
{
if (position + 1 > Length)
{
Expand Down Expand Up @@ -904,7 +904,7 @@ public override string ToString()
return ToString(ZContext.Encoding);
}

public virtual string ToString(Encoding encoding)
public string ToString(Encoding encoding)
{
if (Length > -1)
{
Expand Down
14 changes: 7 additions & 7 deletions ZSocket.cs
Expand Up @@ -92,15 +92,15 @@ protected bool Initialize(out ZError error)

public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases the unmanaged resources used by the <see cref="ZSocket"/>, and optionally disposes of the managed resources.
/// </summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <summary>
/// Releases the unmanaged resources used by the <see cref="ZSocket"/>, and optionally disposes of the managed resources.
/// </summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
Expand Down
8 changes: 4 additions & 4 deletions ZThread.cs
Expand Up @@ -119,13 +119,13 @@ public virtual void Close()
/// <summary>
/// Releases all resources used by the current instance, including the frontend and backend sockets.
/// </summary>
public virtual void Dispose()
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
GC.SuppressFinalize(this);
}

protected abstract void Run();
protected abstract void Run();

/// <summary>
/// Stops the device and releases the underlying sockets. Optionally disposes of managed resources.
Expand Down
2 changes: 1 addition & 1 deletion lib/DispoIntPtr.Ansi.cs
Expand Up @@ -7,7 +7,7 @@ namespace ZeroMQ.lib
using System.Threading;
using System.Runtime.InteropServices;

public partial class DispoIntPtr : IDisposable
internal sealed partial class DispoIntPtr : IDisposable
{
public static class Ansi
{
Expand Down
4 changes: 2 additions & 2 deletions lib/DispoIntPtr.cs
Expand Up @@ -7,7 +7,7 @@ namespace ZeroMQ.lib
using System.Threading;
using System.Runtime.InteropServices;

public partial class DispoIntPtr : IDisposable
internal sealed partial class DispoIntPtr : IDisposable
{
private delegate DispoIntPtr AllocStringNativeDelegate(string str, out int byteCount);

Expand Down Expand Up @@ -113,7 +113,7 @@ public void Dispose()
GC.SuppressFinalize(this);
}

protected void Dispose(bool disposing)
void Dispose(bool disposing)
{
// TODO: instance ThreadStatic && do ( o == null ? return : ( lock(o, ms), check threadId, .. ) )
IntPtr handle = _ptr;
Expand Down

0 comments on commit ff48f0b

Please sign in to comment.