/// <summary> /// Attemps to perform a smart cast to the given type /// from the element. This may involve retriving /// underlying implementation objects such as /// a <c>DTE</c> object or an <c>IVsHierarchy</c>. /// </summary> public T As <T>() where T : class { T result = null; using (HierarchyNode node = new HierarchyNode(this.solution)) { result = node.ExtObject as T; if (result == null) { result = node.GetObject <IVsHierarchy>() as T; } if (result == null) { result = node as T; } } if (result == null) { result = this as T; } return(result); }
public void TestGetObject() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode slnNode = new HierarchyNode(solution); Assert.AreSame(hierarchy, slnNode.GetObject <MockVSHierarchy>()); }
public void TestGetObject() { MockVSHierarchy hierarchy = new MockVSHierarchy(); MockVsSolution solution = new MockVsSolution(hierarchy); HierarchyNode slnNode = new HierarchyNode(solution); Assert.AreSame(hierarchy, slnNode.GetObject<MockVSHierarchy>()); }