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


C# FileSystem.GetFilesByExtension方法代码示例

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


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

示例1: BatchTest

        public async Task BatchTest()
        {
            FileSystem fs = new FileSystem();
            string path = @"C:\PathToSpecs"; //path to specs
            Assert.True(fs.DirectoryExists(path), $"{path} does not exist");

            // get all of the json and yaml files from filesystem
            string[] files = fs.GetFilesByExtension(path, SearchOption.AllDirectories, "json", "yaml");
            Assert.True(files.Count() > 0, $"{path} does not contain any json or yaml files");

            foreach (string file in files)
            {
                // Comment this block out if not needed
                if (!fs.ReadFileAsText(file).Contains(@"""swagger"": ""2.0"""))
                {
                    //skip files that are not swagger files.
                    continue;
                }

                using (var memoryFileSystem = GenerateCodeForTestFromSpec(file))
                {
                    // Expected Files
                    Assert.True(memoryFileSystem.GetFiles(@"GeneratedCode\", "*.cs", SearchOption.TopDirectoryOnly).GetUpperBound(0) > 0);
                    Assert.True(memoryFileSystem.GetFiles(@"GeneratedCode\Models\", "*.cs", SearchOption.TopDirectoryOnly).GetUpperBound(0) > 0);

                    var result = await Compile(memoryFileSystem);

                    // filter the warnings
                    var warnings = result.Messages.Where(
                        each => each.Severity == DiagnosticSeverity.Warning
                                && !SuppressWarnings.Contains(each.Id)).ToArray();

                    // use this to dump the files to disk for examination
                    // memoryFileSystem.SaveFilesToTemp(file.Name);

                    // filter the errors
                    var errors = result.Messages.Where(each => each.Severity == DiagnosticSeverity.Error).ToArray();

                    Write(warnings, memoryFileSystem);
                    Write(errors, memoryFileSystem);

                    // use this to write out all the messages, even hidden ones.
                    // Write(result.Messages, memoryFileSystem);

                    // Don't proceed unless we have zero Warnings.
                    Assert.Empty(warnings);

                    // Don't proceed unless we have zero Errors.
                    Assert.Empty(errors);

                    // Should also succeed.
                    Assert.True(result.Succeeded);
                }
            }
        }
开发者ID:jhancock93,项目名称:autorest,代码行数:55,代码来源:BatchTestSpecs.cs


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