C# File.GetLastWriteTimeUtc的代码示例

通过代码示例来学习C# File.GetLastWriteTimeUtc方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


File.GetLastWriteTimeUtc是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.GetLastWriteTimeUtc() 已经帮大家高亮显示了,大家可以重点学习File.GetLastWriteTimeUtc() 方法的写法,从而快速掌握该方法的应用。

File.GetLastWriteTimeUtc的代码示例1 - Create()

    using System.IO;

        public static FileThumbPrint Create(string path)
        {
            byte[] hashBytes;
            using (var sha1 = SHA1.Create())
            using (var fileStream = File.OpenRead(path))
            {
                hashBytes = sha1.ComputeHash(fileStream);
            }

            var hash = Convert.ToBase64String(hashBytes);
            var lastWriteTimeUtc = File.GetLastWriteTimeUtc(path);
            return new FileThumbPrint(path, lastWriteTimeUtc, hash);
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:15,代码来源:FIleThumbPrint.cs

在Create()方法中,File的代码示例类中的GetLastWriteTimeUtc的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.GetLastWriteTimeUtc的代码示例2 - ReplaceContent()

    using System.IO;

        internal void ReplaceContent(string content, params string[] paths)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (paths == null)
            {
                throw new ArgumentNullException(nameof(paths));
            }

            var filePath = Path.Combine(Project.DirectoryPath, Path.Combine(paths));
            if (!File.Exists(filePath))
            {
                throw new InvalidOperationException($"File {filePath} could not be found.");
            }

            File.WriteAllText(filePath, content, Encoding.UTF8);
            // Timestamps on xplat are precise only to a second. Update it's last write time by at least 1 second
            // so we can ensure that MSBuild recognizes the file change. See https://github.com/dotnet/corefx/issues/26024
            File.SetLastWriteTimeUtc(filePath, File.GetLastWriteTimeUtc(filePath).AddSeconds(1));
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:25,代码来源:MSBuildIntegrationTestBase.cs

在ReplaceContent()方法中,File的代码示例类中的GetLastWriteTimeUtc的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.GetLastWriteTimeUtc的代码示例3 - GetFileTimeStamp()

    using System.IO;

        private static DateTime? GetFileTimeStamp(string fullPath)
        {
            try
            {
                Debug.Assert(Path.IsPathRooted(fullPath));

                return File.GetLastWriteTimeUtc(fullPath);
            }
            catch (Exception e)
            {
                // There are several exceptions that can occur here: NotSupportedException or PathTooLongException
                // for a bad path, UnauthorizedAccessException for access denied, etc. Rather than listing them all,
                // just catch all exceptions and log.
                ServerLogger.LogException(e, $"Error getting timestamp of file {fullPath}.");

                return null;
            }
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:20,代码来源:MetadataCache.cs

在GetFileTimeStamp()方法中,File的代码示例类中的GetLastWriteTimeUtc的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.GetLastWriteTimeUtc的代码示例4 - GetMetadata_ReplacesCache_IfFileTimestampChanged()

    using System.IO;

        [Fact]
        public void GetMetadata_ReplacesCache_IfFileTimestampChanged()
        {
            using (var directory = TempDirectory.Create())
            {
                // Arrange
                var metadataCache = new MetadataCache();
                var assemblyFilePath = LoaderTestResources.Delta.WriteToFile(directory.DirectoryPath, "Delta.dll");

                // Act 1
                var result = metadataCache.GetMetadata(assemblyFilePath);

                // Assert 1
                Assert.NotNull(result);
                var entry = Assert.Single(metadataCache.Cache.TestingEnumerable);
                Assert.Same(result, entry.Value.Metadata);

                // Act 2
                // Update the timestamp of the file
                File.SetLastWriteTimeUtc(assemblyFilePath, File.GetLastWriteTimeUtc(assemblyFilePath).AddSeconds(1));
                var cacheResult = metadataCache.GetMetadata(assemblyFilePath);

                // Assert 2
                Assert.NotSame(result, cacheResult);
                entry = Assert.Single(metadataCache.Cache.TestingEnumerable);
                Assert.Same(cacheResult, entry.Value.Metadata);
            }
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:30,代码来源:MetadataCacheTest.cs

在GetMetadata_ReplacesCache_IfFileTimestampChanged()方法中,File的代码示例类中的GetLastWriteTimeUtc的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.GetLastWriteTimeUtc的代码示例5 - ChangeOutputFileTimestampToMatchOriginal()

    
        private void ChangeOutputFileTimestampToMatchOriginal()
        {
            Debug.Log("Changing output files timestamp to match original timestamp ...");

            var originalFileCreationTime = System.IO.File.GetCreationTimeUtc(this.InputFilePath);
            var originalFileLastAccesTime = System.IO.File.GetLastAccessTimeUtc(this.InputFilePath);
            var originalFileLastWriteTime = System.IO.File.GetLastWriteTimeUtc(this.InputFilePath);
            Debug.Log($"  original timestamp: {originalFileCreationTime}, {originalFileLastAccesTime}, {originalFileLastWriteTime}");

            for (int index = 0; index < this.OutputFilePaths.Length; index++)
            {
                string outputFilePath = this.OutputFilePaths[index];
                try
                {
                    System.IO.File.SetCreationTimeUtc(outputFilePath, originalFileCreationTime);
                    System.IO.File.SetLastAccessTimeUtc(outputFilePath, originalFileLastAccesTime);
                    System.IO.File.SetLastWriteTimeUtc(outputFilePath, originalFileLastWriteTime);
                    Debug.Log($"  output file '{outputFilePath}' timestamp changed");
                }
                catch (Exception exception)
                {
                    Debug.Log($"Can't change timestamp from file '{outputFilePath}'");
                    Debug.Log($"An exception as been thrown: {exception}.");
                }
            }

            Debug.Log("... timestamp matching finished.");
        }
    

开发者ID:Tichau,项目名称:FileConverter,代码行数:29,代码来源:ConversionJob.cs

在ChangeOutputFileTimestampToMatchOriginal()方法中,File的代码示例类中的GetLastWriteTimeUtc的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的File.GetLastWriteTimeUtc方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。