Oddur Magnusson

Object reference not set to an instance of a human being

VS Add-inn Idea : The Disposer!

For those looking for ideas for the VS-Add-inn contest

Don't know if VS add-ins would allow you to do this but I'd really like to see a add-inn that would do this. Each time you write:

ObjectThatIsIDisposable o = new ObjectThatIsIDisposable();

it would wrap it up in a using clause, rewriting it, so it would look like:

using (ObjectThatIsIDisposable o = new ObjectThatIsIDisposable())

{

<And place the cursor here>

}

I just love the using synthetic sugar !

Also, I'd really like to see a add-in that would allow me close all files currently open in VS, without closing the solution.

Posted: Apr 27 2004, 02:11 PM by oddurmag | with 5 comment(s)
Filed under:

Comments

Damian said:

QuickCode.NET would do this http://www.dvxp.com/en/QuickCode.aspx
# April 27, 2004 9:17 AM

RohanD said:

"Also, I'd really like to see a add-in that would allow me close all files currently open in VS, without closing the solution."

Is this what you are looking for?
Window menu -> Close All Documents
# April 27, 2004 9:20 AM

Oddur Magnusson said:

WHY ! Why is "Close" in the File menu , but "Close All" in the Window menu ! Makes my feel stupid !
# April 27, 2004 9:22 AM

Fons sonnemans said:

Try this!

Public Sub InsertUsing()
Dim sb1 As New StringBuilder()
sb1.Append("using (")

Dim sb2 As New StringBuilder()
sb2.Append(")").Append(vbCrLf)
sb2.Append("{").Append(vbCrLf).Append(vbCrLf)
sb2.Append("}").Append(vbCrLf)

InsertCode("InsertUsing Macro", sb1.ToString, sb2.ToString)
End Sub

Private Sub InsertCode(ByVal name As String, ByVal startCode As String, ByVal endCode As String)

DTE.UndoContext.Open(name)
Try
Dim ts As TextSelection
ts = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
Dim tp As EditPoint = ts.TopPoint.CreateEditPoint()
ts.TopPoint.CreateEditPoint().Insert(startCode)
Dim bp As EditPoint = ts.BottomPoint.CreateEditPoint()
bp.Insert(endCode)
tp.SmartFormat(bp)
Finally
'If an error occured, then need to make sure that the undo context is cleaned up.
'Otherwise, the editor can be left in a perpetual undo context
DTE.UndoContext.Close()
End Try
End Sub
# April 27, 2004 9:42 AM

Jerome Laban said:

Actually, I got tired of using Windows/Close all and I mapped it to the same shortcut as the one in MyIE2 or some other softwares... the Ctrl+Shift+W combination.
# April 27, 2004 4:57 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)