/// <summary> /// 获取文件或目录最后的写入UTC时间。 /// </summary> /// <param name="virtualPathProvider">虚拟路径提供者。</param> /// <param name="virtualPath">虚拟路径。</param> /// <returns>UTC时间。</returns> public static DateTime?GetLastWriteTimeUtc(this IVirtualPathProviderBase virtualPathProvider, string virtualPath) { virtualPathProvider.NotNull("virtualPathProvider"); virtualPath.NotEmptyOrWhiteSpace("virtualPath"); var dateTime = virtualPathProvider.GetFileLastWriteTimeUtc(virtualPath); return(dateTime.HasValue ? dateTime : virtualPathProvider.GetDirectoryLastWriteTimeUtc(virtualPath)); }
/// <summary> /// 在指定虚拟路径创建一个文件并创建一个写入流。 /// </summary> /// <typeparam name="T">返回值类型。</typeparam> /// <param name="virtualPathProvider">虚拟路径提供者。</param> /// <param name="virtualPath">虚拟路径。</param> /// <param name="func">对写入流的操作。</param> /// <returns>新文件的写入流。</returns> public static T CreateTextFunc <T>(this IVirtualPathProviderBase virtualPathProvider, string virtualPath, Func <StreamWriter, T> func) { virtualPathProvider.NotNull("virtualPathProvider"); virtualPath.NotEmptyOrWhiteSpace("virtualPath"); func.NotNull("func"); var result = default(T); virtualPathProvider.CreateText(virtualPath, stream => result = func(stream)); return(result); }
/// <summary> /// 打开一个文件。 /// </summary> /// <typeparam name="T">返回值类型。</typeparam> /// <param name="virtualPathProvider">虚拟路径提供者。</param> /// <param name="virtualPath">虚拟路径。</param> /// <param name="func">对流的操作。</param> /// <returns>文件流。</returns> public static T OpenFileFunc <T>(this IVirtualPathProviderBase virtualPathProvider, string virtualPath, Func <Stream, T> func) { virtualPathProvider.NotNull("virtualPathProvider"); virtualPath.NotEmptyOrWhiteSpace("virtualPath"); func.NotNull("func"); var result = default(T); virtualPathProvider.OpenFile(virtualPath, stream => { result = func(stream); }); return(result); }