(client) feat:实现实体动态创建,实体右键菜单

Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com>
Reviewed-on: #41
This commit is contained in:
2025-07-25 19:16:58 +08:00
parent 28ddcda9a0
commit 82dc89c890
55 changed files with 2964 additions and 747 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
@ -339,5 +340,53 @@ namespace Configs
return null;
}
}
/// <summary>
/// 获取指定目录下所有匹配后缀名的文件路径(可递归)
/// </summary>
/// <param name="directoryPath">目标文件夹路径</param>
/// <param name="extensions">后缀名列表(如 ["txt", "jpg"]</param>
/// <param name="searchOption">是否包含子文件夹</param>
/// <returns>匹配的文件路径列表</returns>
public static List<string> GetFilesByExtensions(
string directoryPath,
string[] extensions,
SearchOption searchOption = SearchOption.AllDirectories)
{
if (string.IsNullOrWhiteSpace(directoryPath))
throw new ArgumentException("目录路径不能为空", nameof(directoryPath));
if (!Directory.Exists(directoryPath))
throw new DirectoryNotFoundException($"目录不存在: {directoryPath}");
if (extensions == null || extensions.Length == 0)
throw new ArgumentException("后缀名列表不能为空", nameof(extensions));
// 标准化后缀名(去掉点,转小写)
var normalizedExtensions = new HashSet<string>(
extensions.Select(ext => ext.TrimStart('.').ToLower())
);
var result = new List<string>();
try
{
var files = Directory.GetFiles(directoryPath, "*", searchOption);
foreach (var file in files)
{
var ext = Path.GetExtension(file).TrimStart('.').ToLower();
if (normalizedExtensions.Contains(ext))
{
result.Add(file);
}
}
}
catch (UnauthorizedAccessException ex)
{
// 可选:记录日志或忽略无权限目录
Console.WriteLine($"访问被拒绝: {ex.Message}");
}
return result;
}
}
}