[Mono-dev] Mono enhancements

Vladimir Giszpenc vgiszpenc at dsci.com
Thu Mar 29 09:42:31 EDT 2007


To the Gendarme gurus,

I don't know if the GC is smart enough to Dispose of resources for us, but I will assume that it does not hurt to help it.  There are two patterns that Gendarme could look for.  

class Foo
{
  Foo()
  {
    IDisposable resource = new Resource();
    throw new System.Exception();
    resource.Dispose();
  }
}

This should either be remedied with a try finally or with the using construct which encapsulates try finally (I vote for the latter as a suggested fix).
Another related rule should be to check if resource.Dispose() is never called anywhere in scope.

An unrelated pattern which is not too important to me:

class Foo
{
  Foo()
  {
    System.Console.WriteLine(string.Format("hello {9}", "world"));
  }
}

Note that I missed the zero and typed nine.  

Is it possible to promote Gendarme rules to compiler errors/warnings or would that somehow break compatibility with csc?  Is it worth it if it means better code is produced?  I realize that it won't matter as much once there is a nice Gendarme Plugin for MonoDevelop but even then, we could ask for severe flaws to be compiler warnings at least.

Many thanks,

Vlad Giszpenc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070329/f870ef1b/attachment.html 


More information about the Mono-devel-list mailing list