- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
public class TObjects
{
public delegate T DeferredConstruction<out T>();
public static void Dispose<T>(ref T objectForDispose)
{
var typeOfObjectForDispose = typeof(T);
if (!typeOfObjectForDispose.IsClass)
DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
else
if (!Equals(objectForDispose, null))
DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
objectForDispose = default(T);
//objectForDispose = (T)(object)(null);
}
public static void Create<T>(ref T objectForCreate, DeferredConstruction<T> newObject)
{
Dispose(ref objectForCreate);
objectForCreate = newObject();
}
private static void DisposeIfIDisposable<T>(ref T objectForDispose, Type typeOfObjectForDispose)
{
bool canDisposable = (objectForDispose as IDisposable) != null;
if (canDisposable)
{
var dispose = typeOfObjectForDispose.GetMethod("Dispose");
dispose.Invoke(objectForDispose, new object[] { });
}
}
}
Говногость 03.02.2011 12:00 # +1
Lure Of Chaos 03.02.2011 12:40 # +2
abatishchev 03.02.2011 12:51 # 0
Lure Of Chaos 03.02.2011 12:55 # 0
guest 03.02.2011 22:21 # −1
http://govnokod.ru/5498