我正在创建一个Visual Studio加载项,当我在Server explorer窗口(或数据表或数据字段)中选择数据连接节点时,是否可以使用EnvDTE从Visual Studio中显示的Properties窗口中获取属性值?
我需要从以下字段中获取这些值:Connection string
,Provider
,Data type
,Is Identity
等。
答案 0 :(得分:0)
以下是一些示例代码,演示如何访问属性网格中的选择。请注意,可以选择多个对象,而不仅仅是一个:
IVsMonitorSelection selection = (IVsMonitorSelection)yourSite.GetService(typeof(SVsShellMonitorSelection)); // or yourPackage.GetGlobalService
IVsMultiItemSelect ms;
IntPtr h;
IntPtr pp;
uint itemid;
selection.GetCurrentSelection(out h, out itemid, out ms, out pp);
if (pp != IntPtr.Zero)
{
try
{
ISelectionContainer container = Marshal.GetObjectForIUnknown(pp) as ISelectionContainer;
if (container != null)
{
uint count;
container.CountObjects((uint)Microsoft.VisualStudio.Shell.Interop.Constants.GETOBJS_SELECTED, out count);
if (count == 1)
{
object[] objs = new object[1];
container.GetObjects((uint)Microsoft.VisualStudio.Shell.Interop.Constants.GETOBJS_SELECTED, 1, objs);
object selection = objs[0]; // selection is here
}
}
}
finally
{
Marshal.Release(pp);
}
}