我正在创建一个Visual Studio加载项,当我在服务器资源管理器窗口(或数据表或数据字段)中选择数据连接节点时,有没有办法使用EnvDTE从Visual Studio中显示的属性窗口中获取属性值?
我需要从这些字段中获取这些值:Connection string
、Provider
、Data type
、Is Identity
等。
提前感谢
下面是
一些示例代码,演示如何访问属性网格中的选择。请注意,可以选择多个对象,而不仅仅是一个:
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);
}
}