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 or a process by which you can extend the IDE?
views:
150answers:
6You 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.
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
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
I am not sure, if FXCop or StyleCop can do this already. But then, it will be a post-compile suggestion/warning.
Resharper suggests this, I guess.
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.
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();
}
}
}
}