using System.IO; namespace System.Application { /// /// 指定用于检索应用程序所使用的文件夹目录路径的枚举常数 /// public enum AppFolder { /// /// 图片 /// Images, /// /// 数据库 /// Database, /// /// 缓存、临时文件夹(注意清理!) /// Cache, } /// /// Enum 扩展 /// public static class AppFolderEnumExtensions { /// /// 获取文件夹路径,返回的路径必定存在 /// /// /// public static string GetPath(this AppFolder folder) { var path1 = folder switch { AppFolder.Images or AppFolder.Cache => IOPath.CacheDirectory, AppFolder.Database => IOPath.AppDataDirectory, _ => throw new ArgumentOutOfRangeException(nameof(folder), folder, null), }; var path = Path.Combine(path1, folder.ToString()); IOPath.DirCreateByNotExists(path); return path; } #if DEBUG [Obsolete("use GetPath", true)] public static string GetFolderPath(this AppFolder folder) => folder.GetPath(); #endif } }