当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.Read方法代码示例

本文整理汇总了C#中FileInfo.Read方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Read方法的具体用法?C# FileInfo.Read怎么用?C# FileInfo.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileInfo的用法示例。


在下文中一共展示了FileInfo.Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteTimeRefreshes

        public void WriteTimeRefreshes()
        {
            string fileName = GetTestFilePath();
            File.Create(fileName).Dispose();
            FileInfo fileInfo = new FileInfo(fileName);
            DateTime beforeWrite = DateTime.Now.AddSeconds(-1);
            using (Stream stream = new FileInfo(fileName).OpenWrite())
            {
                stream.Write(new Byte[] { 10 }, 0, 1);
            }
            DateTime afterWrite = DateTime.Now;
            fileInfo.Refresh();
            DateTime lastWriteTime = fileInfo.LastWriteTime;
            Assert.InRange<long>(fileInfo.LastWriteTime.Ticks, beforeWrite.Ticks, afterWrite.Ticks);

            //Read from the File and test the writeTime to ensure it is unchanged
            using (Stream stream = new FileInfo(fileName).OpenRead())
            {
                stream.Read(new Byte[1], 0, 1);
            }
            Assert.Equal(fileInfo.LastWriteTime, lastWriteTime);

            //Write to the file again to test lastWriteTime can be updated again
            beforeWrite = DateTime.Now.AddSeconds(-1);
            using (Stream stream = fileInfo.Open(FileMode.Open))
            {
                stream.Write(new Byte[] { 10 }, 0, 1);
            }
            afterWrite = DateTime.Now;
            Assert.Equal(fileInfo.LastWriteTime, lastWriteTime); //needs to be refreshed first
            fileInfo.Refresh();
            Assert.InRange<long>(fileInfo.LastWriteTime.Ticks, beforeWrite.Ticks, afterWrite.Ticks);
        }
开发者ID:rcabr,项目名称:corefx,代码行数:33,代码来源:get_LastWriteTime.cs

示例2: Asset

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Path">Path to the asset</param>
 /// <param name="AssetManager">The asset manager.</param>
 public Asset(string Path, AssetManager AssetManager)
 {
     Contract.Requires<ArgumentNullException>(AssetManager != null, "AssetManager");
     this.Path = Path;
     this.Included = new List<IAsset>();
     this.Manager = AssetManager;
     this.Type = Manager.DetermineType(Path);
     var File = new FileInfo(Path);
     this.LastModified = File.Modified;
     this.Content = File.Read();
     this.Minified = File.FullName.ToUpperInvariant().Contains(".MIN.");
 }
开发者ID:modulexcite,项目名称:Craig-s-Utility-Library,代码行数:17,代码来源:Asset.cs

示例3: Run

 /// <summary>
 /// Runs this instance.
 /// </summary>
 /// <param name="PushToNuget">if set to <c>true</c> [push to nuget].</param>
 /// <returns>True if it runs successfully, false otherwise</returns>
 public bool Run(bool PushToNuget)
 {
     foreach (FileInfo File in new DirectoryInfo("..\\..\\..\\UtilitiesPackages\\").EnumerateFiles("*.nuspec", System.IO.SearchOption.AllDirectories))
     {
         var PackagesFile = new FileInfo("..\\..\\..\\" + File.Name.Replace(".nuspec", "") + "\\packages.config");
         if (PackagesFile.Exists)
         {
             var PackagesContent = PackagesFile.Read();
             var FileContent = File.Read();
             foreach (Match Package in Regex.Matches(PackagesContent, @"<package id=""(?<Package>[^""]*)"" version=""(?<Version>[^""]*)"""))
             {
                 if (Regex.IsMatch(FileContent, @"<dependency id=""" + Package.Groups["Package"].Value + @""" version=""(?<VersionNumber>[^""]*)"" />"))
                 {
                     var TempMatch = Regex.Match(FileContent, @"<dependency id=""" + Package.Groups["Package"].Value + @""" version=""(?<VersionNumber>[^""]*)"" />");
                     FileContent = FileContent.Replace(TempMatch.Value, @"<dependency id=""" + Package.Groups["Package"].Value + @""" version=""[" + Package.Groups["Version"].Value + @"]"" />");
                 }
             }
             File.Write(FileContent);
         }
     }
     return true;
 }
开发者ID:JaCraig,项目名称:Craig-s-Utility-Library,代码行数:27,代码来源:SetupDependencies.cs


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