I use static code analysis in our projects to check for code violations. One of extensively used rules is CA2213, which checks for correct disposing of disposable fields.
I noticed CA2213 does not check disposing of auto implemented properties.
Furthermore CA2213 does not check disposing of neither fields nor auto implemented properties if the class inherits from class which implements IDisposable and does not override the Dispose method.
Practical example:
public sealed class Good : IDisposable {
private Font font;
public Font Font {
get { return font; }
set { font = value; }
}
public Good() { font = new Font("Arial", 9); }
public void Dispose() { /* Do nothing */ } // CA2213
}
public sealed class Bad : IDisposable {
public Font Font { get; set; }
public Bad() { Font = new Font("Arial", 9); }
public void Dispose() { /* Do nothing */ } // No warning
}
Has anyone else encountered this behavior? Is this by design or bug in CA2213 rule?