This project is read-only.
1
Vote

Consider to implement and use DisposableInstanceHandle class when using workflow instance store

description

///
/// The disposable instance handle.
/// 
public class DisposableInstanceHandle : IDisposable, IEquatable
{
    #region Fields

    /// 
    /// The instance handle.
    /// 
    private readonly InstanceHandle instanceHandle;

    #endregion

    #region Constructors and Destructors

    /// 
    /// Initializes a new instance of the  class.
    /// 
    /// 
    /// The instance store.
    /// 
    /// 
    /// The instance store is null
    /// 
    public DisposableInstanceHandle(InstanceStore instanceStore)
    {
        Contract.Requires(instanceStore != null);
        if (instanceStore == null)
        {
            throw new ArgumentNullException("instanceStore");
        }

        this.instanceHandle = instanceStore.CreateInstanceHandle();
    }

    #endregion

    #region Public Methods and Operators

    /// 
    /// The ==.
    /// 
    /// 
    /// The left.
    /// 
    /// 
    /// The right.
    /// 
    /// 
    /// true if equal
    /// 
    public static bool operator ==(DisposableInstanceHandle left, DisposableInstanceHandle right)
    {
        return left == right;
    }

    /// 
    /// The op_ implicit.
    /// 
    /// 
    /// The disposable instance handle.
    /// 
    /// 
    /// 
    /// 
    /// The instance handle is null
    /// 
    public static implicit operator InstanceHandle(DisposableInstanceHandle disposableInstanceHandle)
    {
        return disposableInstanceHandle != null ? disposableInstanceHandle.instanceHandle : null;
    }

    /// 
    /// The !=.
    /// 
    /// 
    /// The left.
    /// 
    /// 
    /// The right.
    /// 
    /// 
    /// true if not equal
    /// 
    public static bool operator !=(DisposableInstanceHandle left, DisposableInstanceHandle right)
    {
        return left != right;
    }

    /// 
    ///   Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    /// 
    /// 2
    public void Dispose()
    {
        this.Dispose(true);
        GC.SuppressFinalize(this);
    }

    /// 
    /// Indicates whether the current object is equal to another object of the same type.
    /// 
    /// 
    /// true if the current object is equal to the  parameter; otherwise, false. 
    /// 
    /// 
    /// An object to compare with this object. 
    /// 
    public bool Equals(DisposableInstanceHandle other)
    {
        if (ReferenceEquals(null, other))
        {
            return false;
        }

        if (ReferenceEquals(this, other))
        {
            return true;
        }

        return this.instanceHandle == other.instanceHandle;
    }

    /// 
    /// Determines whether the specified  is equal to the current .
    /// 
    /// 
    /// true if the specified  is equal to the current  ; otherwise, false. 
    /// 
    /// 
    /// The  to compare with the current  . 
    /// 
    /// 2
    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj))
        {
            return false;
        }

        if (ReferenceEquals(this, obj))
        {
            return true;
        }

        if (obj.GetType() != this.GetType())
        {
            return false;
        }

        return this.Equals((DisposableInstanceHandle)obj);
    }

    /// 
    ///   Serves as a hash function for a particular type.
    /// 
    ///  A hash code for the current  . 
    /// 2
    public override int GetHashCode()
    {
        return this.instanceHandle != null ? this.instanceHandle.GetHashCode() : 0;
    }

    #endregion

    #region Methods

    /// 
    /// Disposes of resources
    /// 
    /// 
    /// The disposing flag 
    /// 
    private void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (this.instanceHandle != null)
            {
                this.instanceHandle.Free();
            }
        }
    }

    #endregion
}

comments