public static void AddHierarchyItem(this ErrorTask task) { IVsHierarchy hierarchyItem = null; IVsSolution solution = WebEssentialsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); Project project = ProjectHelpers.GetActiveProject(); if (solution != null && project != null) { int flag = -1; try { flag = solution.GetProjectOfUniqueName(project.FullName, out hierarchyItem); } catch (COMException ex) { if ((uint)ex.ErrorCode != DISP_E_MEMBERNOTFOUND) { throw; } } if (0 == flag) { task.HierarchyItem = hierarchyItem; } } }
public static void AddHierarchyItem(this ErrorTask task) { IVsHierarchy HierarchyItem; IVsSolution solution = EditorExtensionsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); Project project = ProjectHelpers.GetActiveProject(); if (solution != null && project != null) { int flag = solution.GetProjectOfUniqueName(project.FullName, out HierarchyItem); if (0 == flag) { task.HierarchyItem = HierarchyItem; } } }
private static CodeTypeRef TryToGuessGenericArgument(CodeClass rootElement, CodeTypeRef codeTypeRef) { var codeTypeRef2 = codeTypeRef as CodeTypeRef2; if (codeTypeRef2 == null || !codeTypeRef2.IsGeneric) { return(codeTypeRef); } // There is no way to extract generic parameter as CodeTypeRef or something similar // (see http://social.msdn.microsoft.com/Forums/vstudio/en-US/09504bdc-2b81-405a-a2f7-158fb721ee90/envdte-envdte80-codetyperef2-and-generic-types?forum=vsx) // but we can make it work at least for some simple case with the following heuristic: // 1) get the argument's local name by parsing the type reference's full text // 2) if it's a known primitive (i.e. string, int, etc.), return that // 3) otherwise, guess that it's a type from the same namespace and same project, // and use the project CodeModel to retrieve it by full name // 4) if CodeModel returns null - well, bad luck, don't have any more guesses var typeNameAsInCode = codeTypeRef2.AsString.Split('<', '>').ElementAtOrDefault(1) ?? ""; CodeModel projCodeModel; try { projCodeModel = rootElement.ProjectItem.ContainingProject.CodeModel; } catch (COMException) { projCodeModel = ProjectHelpers.GetActiveProject().CodeModel; } var codeType = projCodeModel.CodeTypeFromFullName(TryToGuessFullName(typeNameAsInCode)); if (codeType != null) { return(projCodeModel.CreateCodeTypeRef(codeType)); } return(codeTypeRef); }