If an undisposed object is detected, there should be a possibility to wrap this in a using statement via CodeFix. There are several situation that should be treated differently:
An undisposed local variable
namespace SomeNamespace {
public class SomeClass(){
public void SomeClass(){
var mem = new MemoryStream();
mem.Write(...)
}
}
}
Should become:
namespace SomeNamespace {
public class SomeClass(){
public void SomeClass(){
using(var mem = new MemoryStream()){
mem.Write(...);
}
}
}
}
An undisposed anonymous variable
namespace SomeNamespace {
public class SomeClass(){
public void SomeClass(){
new MemoryStream();
}
}
}
Should become:
namespace SomeNamespace {
public class SomeClass(){
public void SomeClass(){
using(new MemoryStream()){
}
}
}
}
An undisposed anonymous variable within an ctor call of a class that is not tracking
namespace SomeNamespace {
public class SomeClass(){
public void SomeClass(){
using(var reader = new NonTrackingReader(new MemoryStream()){
}
}
}
}
Should become:
namespace SomeNamespace {
public class SomeClass(){
public void SomeClass(){
using(var somename = new MemoryStream()){
using(var reader = new NonTrackingReader(somename){
}
}
}
}
}
If an undisposed object is detected, there should be a possibility to wrap this in a using statement via CodeFix. There are several situation that should be treated differently:
An undisposed local variable
Should become:
An undisposed anonymous variable
Should become:
An undisposed anonymous variable within an ctor call of a class that is not tracking
Should become: