Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
public sealed class Dependency : IDisposable
{
public string SomeProperty { get; set; }
public void Dispose()
{
}
}
public sealed class Owner : IDisposable
{
readonly Dependency dependency;
public Owner()
{
// This will violate CA2000 Dispose objects before losing scope
dependency = new Dependency { SomeProperty = "Blah" };
}
public void Dispose()
{
dependency.Dispose();
}
}
//Here's what it generates
public sealed class Owner : IDisposable
{
// Fields
private Dependency dependency;
// Methods
public Owner()
{
// <>g__initLocal0 is never disposed.
Dependency <>g__initLocal0 = new Dependency {
SomeProperty = "Blah"
};
this.dependency = <>g__initLocal0;
}
public void Dispose()
{
this.dependency.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.