I need to access few private methods and members in the Microsoft.VisualStudio.Data.Tools.Package.dll . I did the following coding. everything works fine until the last code line.
Dim dte As EnvDTE.DTE
Dim configuration As EnvDTE.Configuration
Dim projectConfigProperties As Microsoft.VisualStudio.Data.Tools.Package.Project.Internal.ProjectConfigProperties
' Get the Assembly info
Dim name As AssemblyName = New AssemblyName()
name.CodeBase = "file://C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\SQLDB\Microsoft.VisualStudio.Data.Tools.Package.dll"
Dim dbProjectType As Type = assembly.GetType("Microsoft.VisualStudio.Data.Tools.Package.Project.DatabaseProjectPropertyValueType", True, True)
' Retrieve the enum info from the assembly
Dim fields As FieldInfo() = dbProjectType.GetFields((BindingFlags.Public Or BindingFlags.Static Or BindingFlags.NonPublic))
Dim databaseProjectConfig As Microsoft.VisualStudio.Data.Tools.Package.Project.DatabaseProjectConfig
configuration = project.ConfigurationManager.ActiveConfiguration
projectConfigProperties = CType(configuration.Object, Microsoft.VisualStudio.Data.Tools.Package.Project.Internal.ProjectConfigProperties)
projectConfigObject = projectConfigProperties.GetType().GetProperty("ProjectConfig", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance).GetValue(projectConfigProperties)
databaseProjectConfig = CType(projectConfigObject, Microsoft.VisualStudio.Data.Tools.Package.Project.DatabaseProjectConfig)
Dim types As Type() = New Type() {GetType(String), GetType(Boolean), dbProjectType}
' Get method info
Dim myMethod As MethodInfo = databaseProjectConfig.GetType().GetMethod("GetConfigurationProperty", BindingFlags.NonPublic Or BindingFlags.Instance, Nothing, types, Nothing)
' Invoke the method
Dim val = myMethod.Invoke(projectConfigObject, New Object() {"SqlCommandVariablesFile", False, fields(0).GetValue(Nothing)})
The myMethod populates correctly. But when I try to invoke it, the val is always getting a null value. It would be great if someone can tell me where I went wrong.
Aucun commentaire:
Enregistrer un commentaire