0

我正在为 SSMS 2014 编写插件。我想获取层次结构以在 ObjectExplorer 中搜索项目。但是 GetHierarchy 方法为空。有没有人有任何想法?

ObjectExplorerService objExplorerService = (ObjectExplorerService)ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService));
MethodInfo getHierarchyMethod = objExplorerService.GetType().GetMethod("GetHierarchy", BindingFlags.Instance | BindingFlags.NonPublic);
4

1 回答 1

4

我找到了我的问题的答案。我使用以下代码访问了“对象资源管理器层次结构”。

List<IExplorerHierarchy> hierarchyList = new List<IExplorerHierarchy>();
ObjectExplorerService objExplorerService = (ObjectExplorerService)ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService));
System.Type t = objExplorerService.GetType();

PropertyInfo getHierarchyMethod = t.GetProperty("Tree", BindingFlags.Instance | BindingFlags.NonPublic);
var value = getHierarchyMethod.GetValue(objExplorerService, null);

PropertyInfo getHierarchyMethod2s = value.GetType().GetProperty("Hierarchies", BindingFlags.Instance | BindingFlags.NonPublic);
var value2 = getHierarchyMethod2s.GetValue(value, null);

foreach (var item in (Dictionary<string, IExplorerHierarchy>)value2)
{
    hierarchyList.Add(item.Value);
}
于 2015-12-29T06:40:57.540 回答