ProxyGen outputs the Proxy and HostTypeMapProvider files in C#. For anyone interested in using a VB.Net HostTypeMapProvider, here is a download to help with this.
Included in this download:
Template- the template is a HostTypeMapProvider in VB.Net without types.
Macro- translates C# canonicalToTypeName.Add and typeToCanonicalName.Add statements from the HostTypeMapProvider created by ProxyGen to VB.Net
Instructions:
Add the HostTypeMapProvider template to the host VB.Net project.
Copy the C# canonicalToTypeName.Add and typeToCanonicalName.Add statements from the HostTypeMapProvider created by ProxyGen.
Paste the statements into the New method.
Run the macro.
For your convience, the template and macro can be copied from here:
'This file works as a template for VB HostTypeMapProviders.
' Copy and paste the types generated by ProxyGen into the
' constructor below.
' Then run the HTMProvider_TranslateTypesToVB macro with
' this file selected.
Public Class HostTypeMapProvider : Implements Microsoft.VisualStudio.Tools.Applications.Runtime.ITypeMapProvider
Dim typeToCanonicalName As System.Collections.Generic.Dictionary(Of System.Type, System.String) = System.Collections.Generic.Dictionary(Of System.Type, System.String)()
Dim canonicalToTypeName As System.Collections.Generic.Dictionary(Of System.String, System.Type) = System.Collections.Generic.Dictionary(Of System.String, System.Type)()
Friend Sub New()
'add types here to translate.
'Run HTMProvider_TranslateTypesToVB macro with this doc selected
End Sub
Public Function GetCanonicalNameForType(ByVal type As System.Type) As String Implements Microsoft.VisualStudio.Tools.Applications.Runtime.ITypeMapProvider.GetCanonicalNameForType
'default fetch from dictionary
If typeToCanonicalName.ContainsKey(type) Then
Return typeToCanonicalName(type)
End If
Return Nothing
End Function
Public Function GetTypeForCanonicalName(ByVal canonicalName As String) As System.Type Implements Microsoft.VisualStudio.Tools.Applications.Runtime.ITypeMapProvider.GetTypeForCanonicalName
'defualt fetch from the dictionary
If canonicalToTypeName.ContainsKey(canonicalName) Then
Return canonicalToTypeName(canonicalName)
End If
Return Nothing
End Function
End Class
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module HTMProvider_TranslateTypesToVB
'Translates the types found in a HostTypeMapProvider from C# to VB
Public Sub HTMProvider_TranslateTypesToVB()
'make syntax changes
FindReplaceAll(";", "")
FindReplaceAll("<", "( Of ")
FindReplaceAll(">", ")")
FindReplaceAll("typeof", "gettype")
'correct the formatting
DTE.ExecuteCommand("Edit.FormatDocument")
End Sub
'replaces all occurences of the find string with the replace string
Private Sub FindReplaceAll(ByVal inFind As String, ByVal inReplace As String)
DTE.Find.FindWhat = inFind
DTE.Find.ReplaceWith = inReplace
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
DTE.Find.MatchInHiddenText = True
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
End Sub
End Module