// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
namespace CefSharp
{
///
/// This Class provides tool functionality for managed Dispose Pattern
/// http://msdn.microsoft.com/en-us/library/fs2xkftw(v=vs.110).aspx
///
public class ObjectBase : IDisposable
{
#region IDisposable
~ObjectBase()
{
DoDispose(false);
IsDisposed = true;
}
public void Dispose()
{
DoDispose(true);
IsDisposed = true;
GC.SuppressFinalize(this);
}
protected virtual void DisposeMember(ref T field)
where T : class, IDisposable
{
var oldvalue = field;
field = null;
if (oldvalue != null)
{
oldvalue.Dispose();
}
}
protected virtual void DoDispose(bool isDisposing)
{
}
///
/// If this Object is disposed the Method will throw a .
/// Use this method to guard methods that are not allowed to be called after dispose was called
///
///
protected virtual void DisposeGuard()
{
if (IsDisposed)
{
throw new ObjectDisposedException(GetType().FullName);
}
}
///
/// Gets a value indicating whether this instance is disposed.
/// This Value Should be used for lifetime management.
/// i.e. EventHandlers may not be registered if this object is already disposed
///
///
/// true if this instance is disposed; otherwise, false.
///
public bool IsDisposed { get; private set; }
#endregion
}
}