On Fri, Dec 26, 2008 at 6:29 AM, Jesse Jones <[email protected]>wrote:
> "This rule checks that disposable locals are always disposed OF before
> the method returns. Use A 'using' statement (or a try/finally block)
> to guarantee local disposal even in the event an UNCAUGHT exception
> occurs." would be a bit better.
Good catch for the OF. For the latter even better would be UNHANDLED I guess
;)
> + [Solution ("Use 'using' statement or surround the local's usage
> > with a try/finally block.")]
>
> "Use A 'using' statement or surround the local's usage with a try/
> finally block."
Ok.
>
> >
> > + public class EnsureLocalDisposalRule : Rule, IMethodRule {
>
> Should probably be sealed.
Ok.
>
> >
> > + return MethodSignatures.Dispose.Matches (call) ||
> > MethodSignatures.DisposeExplicit.Matches (call);
> > + }
>
> If the method's declaring type implements IDisposable you should
> probably treat a call to Close as a call to Dispose.
Still, an IDisposable should be Disposed, Close may indeed free some
resources but it is not the correct pattern wrt IDisposable.
In most cases, Close and Dispose are equivalent [1] (thus you should use
Dispose for consistency - and likely suppress finalizers),
at worst - (rarely) - Close and Dispose are different and thus you'd need to
call Dispose anyways.
method.IsGeneratedCode returns true for delegate methods so unless you
> have seen a problem with checking generated methods I don't think you
> should skip them.
>
True, I'll try.
1: "Try to delegate cleanup responsibility to Dispose (e.g. by calling
Close() from Dispose()) in such circumstances, and make sure to carefully
document any situations that deviate from this pattern." - FDG 2nd edition
"Based on this experience, I'd encourage you to think very carefully before
attempting to use a domain-specific name instead of Dispose -- we're now at
a place where users are familiar with Dispose and it *is* the most
discoverable method name."
http://blogs.msdn.com/kimhamil/archive/2008/03/15/the-often-non-difference-between-close-and-dispose.aspx
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Gendarme" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/gendarme?hl=en
-~----------~----~----~----~------~----~------~--~---