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 )); }
public static IDisposable With( [CanBeNull] this ITextTemplatingComponents components, [CanBeNull] IVsHierarchy hierarchy, [CanBeNull] FileSystemPath inputFilePath ) { if (components == null) { return(Disposable.Empty); } object oldHierarchy = components.Hierarchy; string oldInputFileName = components.InputFile; return(Disposable.CreateBracket( () => { components.Hierarchy = hierarchy; components.InputFile = inputFilePath.IsNullOrEmpty() ? null : inputFilePath.FullPath; }, () => { components.Hierarchy = oldHierarchy; components.InputFile = oldInputFileName; }, false )); }