mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 05:47:14 -04:00
Add Argument*Exceptions now use proper nameof operators. Added exception messages to quite a few Argument*Exceptions. Fixed rethorwing to be proper syntax. Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling) Added some TODOs to log certain exceptions. Fix sln again. Fixed all AssemblyInfo's and added proper copyright (where I could find them) We live in *current year*. Fixed the use of braces. Fixed a ton of properties, and made a fair amount of functions static that should be and can be static. Made more Methods that should be static static. You can now use static to find bad functions! Removed unused variable. And added one more proper XML comment.
67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using System;
|
|
|
|
namespace Emby.Server.Implementations.Net
|
|
{
|
|
/// <summary>
|
|
/// Correclty implements the <see cref="IDisposable"/> interface and pattern for an object containing only managed resources, and adds a few common niceities not on the interface such as an <see cref="IsDisposed"/> property.
|
|
/// </summary>
|
|
public abstract class DisposableManagedObjectBase : IDisposable
|
|
{
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Override this method and dispose any objects you own the lifetime of if disposing is true;
|
|
/// </summary>
|
|
/// <param name="disposing">True if managed objects should be disposed, if false, only unmanaged resources should be released.</param>
|
|
protected abstract void Dispose(bool disposing);
|
|
|
|
|
|
//TODO Remove and reimplement using the IsDisposed property directly.
|
|
/// <summary>
|
|
/// Throws an <see cref="System.ObjectDisposedException"/> if the <see cref="IsDisposed"/> property is true.
|
|
/// </summary>
|
|
/// <seealso cref="IsDisposed"/>
|
|
/// <exception cref="System.ObjectDisposedException">Thrown if the <see cref="IsDisposed"/> property is true.</exception>
|
|
/// <seealso cref="Dispose()"/>
|
|
protected virtual void ThrowIfDisposed()
|
|
{
|
|
if (IsDisposed) throw new ObjectDisposedException(GetType().Name);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Sets or returns a boolean indicating whether or not this instance has been disposed.
|
|
/// </summary>
|
|
/// <seealso cref="Dispose()"/>
|
|
public bool IsDisposed
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IDisposable Members
|
|
|
|
/// <summary>
|
|
/// Disposes this object instance and all internally managed resources.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Sets the <see cref="IsDisposed"/> property to true. Does not explicitly throw an exception if called multiple times, but makes no promises about behaviour of derived classes.</para>
|
|
/// </remarks>
|
|
/// <seealso cref="IsDisposed"/>
|
|
public void Dispose()
|
|
{
|
|
IsDisposed = true;
|
|
|
|
Dispose(true);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|