这是从 UITypeEditor 执行此操作的方法。
ETA:原始代码有一个额外的不需要的步骤。我忘了我们有服务提供商,所以不需要看网站。精简后的代码是:
Public Class MyEditor
Inherits UITypeEditor
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
Dim typeRes As ITypeResolutionService = TryCast(provider.GetService(GetType(ITypeResolutionService)), ITypeResolutionService)
Dim ass As System.Reflection.AssemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName()
MessageBox.Show(ass.CodeBase, "Design-time Path")
MessageBox.Show(typeRes.GetPathOfAssembly(ass), "Run-time Path")
End Function
End Class
原始代码:
Public Class MyEditor
Inherits UITypeEditor
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
Dim component As IComponent = TryCast(context.Instance, IComponent)
Dim site As ISite = component.Site
Dim typeRes As ITypeResolutionService = TryCast(site.GetService(GetType(ITypeResolutionService)), ITypeResolutionService)
Dim ass As System.Reflection.AssemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName()
MessageBox.Show(ass.CodeBase, "Design-time Path")
MessageBox.Show(typeRes.GetPathOfAssembly(ass), "Run-time Path")
End Function
End Class
此解决方案基于How to: Access Design-Time Services中的代码,您可以在其中找到大量信息。