public static IProject GetCurrentProjectScope(this ISolution solution) { Guard.NotNull(() => solution, solution); var selection = ServiceProvider.GlobalProvider.GetService <SVsShellMonitorSelection, IVsMonitorSelectionFixed>(); if (selection != null) { IVsHierarchy hierarchy; uint pitemid; IVsMultiItemSelect ppMIS; ISelectionContainer ppSC; if (selection.GetCurrentSelection(out hierarchy, out pitemid, out ppMIS, out ppSC) == Microsoft.VisualStudio.VSConstants.S_OK) { if (hierarchy != null) { var project = hierarchy.ToProject(); if (project != null) { return(solution.Find <IProject>(p => p.As <EnvDTE.Project>() == project).FirstOrDefault()); } } } } // Use first project in the solution return(solution.Find <IProject>().FirstOrDefault()); }
/// <summary> /// Gets the equivalent <see cref="IItemContainer"/> for the given <see cref="IVsHierarchy"/> /// </summary> public static T As <T>(this IVsHierarchy hierarchy, ISolution solution) where T : IItemContainer { Guard.NotNull(() => hierarchy, hierarchy); Guard.NotNull(() => solution, solution); return(solution.Find <T>(item => item.As <IVsHierarchy>() == hierarchy).FirstOrDefault()); }
public static IItem FindItem(this ISolution solution, string itemPathTemplate) { var item = solution.Find <IItem>(string.Format(itemPathTemplate, solution.Name)).FirstOrDefault(); Assert.IsNotNull(item, "item not found with path " + itemPathTemplate); return(item); }
private static void AddDependentFiles(ISolution solution, string modelFile, IEnumerable <string> diagramFiles) { var item = solution.Find <IItem>(it => it.PhysicalPath == modelFile).Single(); foreach (var diagramFile in diagramFiles) { if (!item.Find <IItem>(it => it.PhysicalPath == diagramFile).Any()) { item.Add(diagramFile); } } }
private void LoadTypes() { if (loadingTypes) { return; } try { tracer.Verbose(Resources.ProjectTypeProvider_TraceLoadTypes); loadingTypes = true; this.availableTypes.Clear(); foreach (var project in solution.Find <IProject>()) { var hierarchy = project.As <IVsHierarchy>(); if (hierarchy != null) { tracer.Verbose(Resources.ProjectTypeProvider_TraceLoadProjectTypes, project.Name); var typeDiscoveryService = dynamicTypeService.GetTypeDiscoveryService(hierarchy); string currentProjectAssemblyName; try { currentProjectAssemblyName = project.As <EnvDTE.Project>().Properties.Item(@"AssemblyName").Value as string; } catch (Exception) { continue; } // We should be able to leverage Progression for this! var types = typeDiscoveryService.GetTypes(typeof(object), true); foreach (Type type in types) { if (string.Equals(type.Assembly.GetName().Name, currentProjectAssemblyName, StringComparison.InvariantCultureIgnoreCase)) { availableTypes.Add(type); } } } } } finally { loadingTypes = false; } }
/// <summary> /// Resolves the current element paths and filename, and returns the item if exists. /// </summary> public static IItemContainer ResolveToSolutionItem <T>(object context, ISolution solution, IUriReferenceService uriService, string path = null, string fileName = null) where T : IItemContainer { // Resolve SourcePath var resolver = new PathResolver(context, uriService, path, fileName); if (resolver.TryResolve()) { // Load file from solution var sourceFile = resolver.Path; return(solution.Find <T>(sourceFile).FirstOrDefault()); } return(null); }
public static IItem FindItem(this ISolution solution, string itemPathTemplate) { var item = solution.Find <IItem>(string.Format(itemPathTemplate, solution.Name)).FirstOrDefault(); return(item); }
private static void AddDependentFiles(ISolution solution, string modelFile, IEnumerable<string> diagramFiles) { var item = solution.Find<IItem>(it => it.PhysicalPath == modelFile).Single(); foreach (var diagramFile in diagramFiles) { if (!item.Find<IItem>(it => it.PhysicalPath == diagramFile).Any()) { item.Add(diagramFile); } } }
public static IEnumerable <IProject> GetAllProjects(this ISolution solution) { return(solution.Find <IProject>()); }