[英]Code analysis CA2000 warning without warrant
I have the following extension method 我有以下扩展方法
public static string NameInCSharp(this Type type)
{
string typeName = type.FullName.Replace(type.Namespace + ".", "");
using (var provider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp"))
{
var reference = new System.CodeDom.CodeTypeReference(typeName);
return provider.GetTypeOutput(reference);
}
}
Does anyone know why I get code analysis warning CA2000 (Dispose objects before losing scope) when I compile? 有谁知道为什么我在编译时得到代码分析警告CA2000(在失去作用域之前处理对象)?
The using statement should do the dispose for me right? using语句应该为我做配置对吗?
You are correct, the using statement should do the dispose right. 您是正确的,using语句应具有处置权。 I was as puzzled as you by this warning which is why I built your code on my machine, enabled all code analysis rules and did not get the warning you mentioned. 这个警告让我和您一样困惑,这就是为什么我在计算机上构建您的代码,启用所有代码分析规则并且没有得到您提到的警告的原因。 Perhaps the warning applies to another part of your code, or there is a bug somewhere in the tools you are using. 该警告可能适用于代码的另一部分,或者您正在使用的工具中某处存在错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.