【发布时间】:2011-01-08 16:45:46
【问题描述】:
如果在引用的 dll 中使用 Application.StartupPath,则路径指向 IDE 的路径。
有没有办法获取实际应用的路径?
需要明确的是,这是在设计时。
ETA:我在下面发布了解决方案:
ETA2:
因为它是相关的,我想我会发布另一个有用的设计时服务的 sn-p。与下面的解决方案一样,此示例适用于 UITypeEditor:
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
Dim typeDiscovery As ITypeDiscoveryService = TryCast(provider.GetService(GetType(ITypeDiscoveryService)), ITypeDiscoveryService)
Dim types As ICollection = typeDiscovery.GetTypes(GetType(MyType), False)
End Function
types 将包含从 MyType 派生的所有类型。将第二个参数更改为 True 以排除搜索 GAC。 将 Nothing 作为第一个参数传递以获取所有类型的列表。
【问题讨论】:
标签: c# .net winforms path design-time