private IDisposable Prepare([NotNull] IProjectFile file) { var hierarchy = T4ResolutionUtils.TryGetVsHierarchy(file); var components = Components.Value.CanBeNull; if (components == null) { return(Disposable.Empty); } object oldHierarchy = components.Hierarchy; string oldInputFileName = components.InputFile; return(Disposable.CreateBracket( () => { components.Hierarchy = hierarchy; components.InputFile = file.Location.IsNullOrEmpty() ? null : file.Location.FullPath; }, () => { components.Hierarchy = oldHierarchy; components.InputFile = oldInputFileName; }, false )); }
private IReadOnlyDictionary <string, string> ResolveHeavyMacros( [NotNull] IEnumerable <string> macros, [NotNull] IProjectFile file ) { var result = new Dictionary <string, string>(); Lazy <IVsBuildMacroInfo> vsBuildMacroInfo = Lazy.Of(() => TryGetVsBuildMacroInfo(file), false); foreach (string macro in macros) { bool succeeded = false; string value = null; if (vsBuildMacroInfo.Value != null) { succeeded = HResultHelpers.SUCCEEDED(vsBuildMacroInfo.Value.GetBuildMacroValue(macro, out value)) && !string.IsNullOrEmpty(value); } if (!succeeded) { value = MSBuildExtensions.GetStringValue(T4ResolutionUtils.TryGetVsHierarchy(file), macro, null); succeeded = !string.IsNullOrEmpty(value); } if (succeeded) { result[macro] = value; } } return(result); }
private static IVsBuildMacroInfo TryGetVsBuildMacroInfo([NotNull] IProjectFile file) => T4ResolutionUtils.TryGetVsHierarchy(file) as IVsBuildMacroInfo;