Is there any way to mark a method so that code analysis or build with give error message to dispose the object returned by method. for e.g. in the following method.
private void chart1_Click(object sender, EventArgs e)
{
Brush sb = GetBlackBrush();
}
Brush GetBlackBrush()
{
SolidBrush sb = new SolidBrush(Color.Black);
return sb;
}
whenever any method called GetBlackBrush, while building the solution in VS2010, i should get a code analysis warning or build error or build warning to indicate that i need to dispose Brush object. I want i should get some indication in chart1_Click() method to dispose brush object.
This is just a sample code,i know we should be using "Using" but here whats the solution.
There is a CA2213 code analysis warning but that is not getting called for this particular example.
CA2000 warning is something you might be after, see documentation:
Not sure if you can mark it as error but it should pick it up. You might want to enable also CA2213