Title covers it all. I\'d like classes which implement IDisposable to show up in a specific color so I can know if I should wrap them in a using block. Is there a setting
Sure, there is a large set of tools to build VS extensions, see Visual Studio 2008 SDK 1.1 But time required to build such an add-in will require more time that you will spend by browsing components and determining whether they are Disposable or not
Maybe I'm a bad person for doing this, but I've been using this piece of code recently:
public static void BulkDispose(object[] objects)
{
foreach (object o in objects)
{
if (o != null)
{
if (o is IDisposable)
{
IDisposable disposable = o as IDisposable;
disposable.Dispose();
}
}
}
}
The word on the street is this kind of thing will be much easier in VS.NET 2010. The editor is being rewritten in WPF.
It is certainly possible to do this though it isn't as simple as just changing a setting. You would need to write a Visual Studio addin to accomplish this.
Visit http://msdn.microsoft.com/en-us/vsx/bb980955.aspx to get started. As others will point out. This is not for the faint of heart.
Here's a link that may point you toward what you are looking for:http://msdn.microsoft.com/en-us/library/bb166778.aspx
You cannot. This would require language service support and neither C# or VB.Net provide this functionality.
Cannot is probably too strong of a word. It's certainly possible to do this with an Add-In which does deep inspection of the code and figures out hierarchies. However it's a very non-trivial task.
I assume this will become easier/extension-free once Roslyn comes out, but this is presently not easy because you can't access the code as C# from an extension easily.
In Resharper it's easy, though! My example was tested in ReSharper 9.0. Sadly, there's no easy way to give this to you.
new $disp$($args$)
Type
, name: disp
, type: System.IDisposable
Arguments
, name: args
Save and you'll now get a "suggestion" whenever a new disposable is being constructed.
Adding the pattern $disp$ $var$ = $exp$;
could also be helpful.
Type
, name: disp
, type: System.IDisposable
Expression
, name: exp
Identifier
, name: var