blob: 884765240bb96c40613051e5bbfb8a04c4d05346 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
namespace RealTimeGraphEx.DX2D
{
using System;
public static class Disposer
{
/// <summary>
/// Dispose an object instance and set the reference to null
/// </summary>
/// <typeparam name="T">The type of object to dispose</typeparam>
/// <param name="resource">A reference to the instance for disposal</param>
/// <remarks>This method hides any thrown exceptions that might occur during disposal of the object (by design)</remarks>
public static void SafeDispose<T>(ref T resource) where T : class
{
if (resource == null)
{
return;
}
var disposer = resource as IDisposable;
if (disposer != null)
{
try
{
disposer.Dispose();
}
catch
{
}
}
resource = null;
}
}
}
|