Last active
December 10, 2015 23:09
-
-
Save haacked/4507192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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