Reputation: 245
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?
The using statement should do the dispose for me right?
Upvotes: 1
Views: 59
Reputation:
You are correct, the using statement should do the dispose right. 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.
Upvotes: 1