Switching between the NHibernate Mapping File and the class in Visual Studio
Posted by Tobi
Most of the times, I try to use the keyboard as much as possible to navigate trough the source code. As I couldn't find another way to open a NHibernate mapping file from within the class I'm working on, I wrote the following small macro. All it does is switching between .cs and .hbm.xml. So if I'm working in Model.cs, pressing SHIFT-CTRL-X opens Model.hbm.xml and pressing SHIFT-CTRL-X again, brings me back to Model.cs.
Sub SwitchBetweenClassAndNHibernateMapping()
If DTE.ActiveDocument Is Nothing Then Return
Dim FileName As String = System.IO.Path.GetFileNameWithoutExtension(DTE.ActiveDocument.Name)
Dim FileExtension As String = System.IO.Path.GetExtension(DTE.ActiveDocument.Name)
If FileExtension = ".xml" Then
FileName = System.IO.Path.GetFileNameWithoutExtension(FileName)
FileExtension = ".cs"
Else
FileExtension = ".hbm.xml"
End If
Dim Item As EnvDTE.ProjectItem = DTE.Solution.FindProjectItem(FileName + FileExtension)
If Not Item Is Nothing Then
Item.Open()
Item.Document.Activate()
End If
End Sub