private static string GetConfigPathForItem(string path, string solutionRoot, Project project) { if (String.IsNullOrWhiteSpace(path)) { return(null); } var projectFullName = project?.FullName; var projectDirectory = String.IsNullOrEmpty(projectFullName) ? String.Empty : Path.GetDirectoryName(projectFullName); IEnumerable <string> configPaths = (path.StartsWith(solutionRoot, StringComparison.InvariantCultureIgnoreCase)) ? StylerPackage.GetConfigPathBetweenPaths(path, solutionRoot) : StylerPackage.GetConfigPathBetweenPaths(path, projectDirectory); // find the FullPath of "Settings.XamlStyler" ref in project var filePathsInProject = project?.ProjectItems.Cast <ProjectItem>() .Where(x => { ThreadHelper.ThrowIfNotOnUIThread(); return(string.Equals(x.Name, "Settings.XamlStyler", StringComparison.Ordinal)); }) .SelectMany(x => { ThreadHelper.ThrowIfNotOnUIThread(); return(x.Properties.Cast <Property>()); }) .Where(x => { ThreadHelper.ThrowIfNotOnUIThread(); return(string.Equals(x.Name, "FullPath", StringComparison.Ordinal)); }) .Select(x => { ThreadHelper.ThrowIfNotOnUIThread(); return(x.Value as string); }); if (filePathsInProject != null) { configPaths = configPaths.Concat(filePathsInProject); } return(configPaths.FirstOrDefault(File.Exists)); }
private string GetConfigPathForItem(string path) { try { if (String.IsNullOrWhiteSpace(path)) { return(null); } var solutionRoot = String.IsNullOrEmpty(_dte.Solution?.FullName) ? String.Empty : Path.GetDirectoryName(_dte.Solution.FullName); IEnumerator <string> configPaths = (path.StartsWith(solutionRoot, StringComparison.InvariantCultureIgnoreCase)) ? StylerPackage.GetConfigPathInsideSolution(path, solutionRoot).GetEnumerator() : StylerPackage.GetConfigPathOutsideSolution(path).GetEnumerator(); while (configPaths.MoveNext()) { if (File.Exists(configPaths.Current)) { return(configPaths.Current); } } } catch { // Fail gracefully. } return(null); }
private string GetConfigPathForItem(string path) { try { if (String.IsNullOrWhiteSpace(path)) { return(null); } var solutionRoot = String.IsNullOrEmpty(_dte.Solution?.FullName) ? String.Empty : Path.GetDirectoryName(_dte.Solution.FullName); var project = _dte.ActiveDocument?.ProjectItem?.ContainingProject; var projectFullName = project?.FullName; var projectDirectory = String.IsNullOrEmpty(projectFullName) ? String.Empty : Path.GetDirectoryName(projectFullName); IEnumerable <string> configPaths = (path.StartsWith(solutionRoot, StringComparison.InvariantCultureIgnoreCase)) ? StylerPackage.GetConfigPathBetweenPaths(path, solutionRoot) : StylerPackage.GetConfigPathBetweenPaths(path, projectDirectory); // find the FullPath of "Settings.XamlStyler" ref in project var filePathsInProject = project?.ProjectItems.Cast <ProjectItem>() .Where(x => string.Equals(x.Name, "Settings.XamlStyler")) .SelectMany(x => x.Properties.Cast <Property>()) .Where(x => string.Equals(x.Name, "FullPath")) .Select(x => x.Value as string); if (filePathsInProject != null) { configPaths = configPaths.Concat(filePathsInProject); } using (var configPathEnumerator = configPaths.GetEnumerator()) { while (configPathEnumerator.MoveNext()) { if (File.Exists(configPathEnumerator.Current)) { return(configPathEnumerator.Current); } } } } catch { // Fail gracefully. } return(null); }