我正在进行代码审查,并发现了很多以下格式的代码:
public MyResponse MyMethod(string arg)
{
using (Tracer myTracer = new Tracer(Constants.TraceLog))
{
MyResponse abc = new MyResponse();
// Some code
return abc;
}
}
运行代码分析时,我收到了一个CA2000警告Microsoft.Reliability
应该将代码改成:
public MyResponse MyMethod(string arg)
{
MyResponse abc = new MyResponse();
using (Tracer myTracer = new Tracer(Constants.TraceLog))
{
// Some code
}
return abc;
}
或者说这并不重要吗?
编辑
报告警告的行是:
MyResponse abc = new MyResponse();
MyResponse是一个标准数据集。
完整的错误信息如下:
警告 150 CA2000:Microsoft.Reliability:在方法 'xxxxx(Guid,Guid)'中,对象'MyResponse'没有在所有异常路径上被处理。 在所有引用超出范围之前调用System.IDisposable.Dispose对对象'MyResponse'进行处理。
MyResponse
实现了IDisposable
接口吗? - Jon