1 Star 0 Fork 0

deu2019/pzf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Disposer.cs 935 Bytes
一键复制 编辑 原始数据 按行查看 历史
deu2019 提交于 2020-06-09 22:44 . commit
using System;
using System.Collections.Generic;
namespace Pfz
{
/// <summary>
/// Class that does the pattern of checking for null, disposing the object and setting its variable to null.
/// </summary>
public static class Disposer
{
/// <summary>
/// Disposes the object if needed and sets its variable to null.
/// </summary>
public static void Dispose<T>(ref T disposable)
where
T: class, IDisposable
{
var content = disposable;
if (content != null)
{
disposable = null;
content.Dispose();
}
}
/// <summary>
/// Disposes all the items in a given collection.
/// </summary>
public static void DisposeCollection<T>(ref T collectionOfDisposables)
where
T: class, IEnumerable<IDisposable>
{
var collection = collectionOfDisposables;
if (collection == null)
return;
collectionOfDisposables = null;
foreach(var item in collection)
item.Dispose();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/deu2019/pzf.git
[email protected]:deu2019/pzf.git
deu2019
pzf
pzf
master

搜索帮助