/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/FileProviders/Embedded/test/Manifest/TestEntry.cs
40 строк
1 KB
Pranav K
Use file scoped namespaces (#38076)
06 ноя 2021, 03:52
Не верифицирован
06 ноя 2021, 03:52
a450cb6
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; using System.Linq; using System.Xml.Linq; namespace Microsoft.Extensions.FileProviders.Embedded.Manifest; class TestEntry { public bool IsFile => ResourcePath != null; public string Name { get; set; } public TestEntry[] Children { get; set; } public string ResourcePath { get; set; } public static TestEntry Directory(string name, params TestEntry[] entries) => new TestEntry() { Name = name, Children = entries }; public static TestEntry File(string name, string path = null) => new TestEntry() { Name = name, ResourcePath = path ?? name }; public XElement ToXElement() => IsFile ? new XElement("File", new XAttribute("Name", Name), new XElement("ResourcePath", ResourcePath)) : new XElement("Directory", new XAttribute("Name", Name), Children.Select(c => c.ToXElement())); public IEnumerable<TestEntry> GetFiles() { if (IsFile) { return Enumerable.Empty<TestEntry>(); } var files = Children.Where(c => c.IsFile).ToArray(); var otherFiles = Children.Where(c => !c.IsFile).SelectMany(d => d.GetFiles()).ToArray(); return files.Concat(otherFiles).ToArray(); } }