XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.AutoPath

【DLL】自动路径创建工具,自动创建不存在的文件夹,对路径统一管理

公开
关注 0 Fork 0 Star 0
UTF-8

XFEExtension.NetCore.AutoPath

NuGet NuGet Downloads License: MIT .NET

📖 English | 简体中文

Description

An automatic path creation tool that automatically creates non-existent folders and provides unified path management.

Auto Path Management

Basic Usage

// Create a path management class
public partial class AppPath
{
    [AutoPath]
    readonly static string myTestPath = "MyTestPath/Test";
    [AutoPath]
    readonly static string mySecTestPath = $"{MyTestPath}/Sec"; // Paths can reference auto-generated paths
}


// Use the unified path management
class Program
{
    static void Main(string[] args)
    {
        File.WriteAllText($"{AppPath.MyTestPath}/test.txt", "Hello World"); // MyTestPath will be auto-created if it does not exist
        var exist = Directory.Exists(AppPath.MySecTestPath);
        Console.WriteLine(exist); // Output: True
    }
}

Add Comments to Paths

public partial class AppPath
{
    /// <summary>
    /// Test path
    /// This comment will be automatically added to the auto-generated Name property
    /// </summary>
    [AutoPath]
    readonly static string myTestPath = "MyTestPath/Test";
    [AutoPath]
    readonly static string mySecTestPath = $"{MyTestPath}/Sec";
}

Use Partial Methods to Set the Get Method

public partial class AppPath
{
    [AutoPath]
    readonly static string myTestPath = "MyTestPath/Test";
    [AutoPath]
    readonly static string mySecTestPath = $"{MyTestPath}/Sec";

    static partial void GetMyTestPathProperty()
    {
        Console.WriteLine("MyTestPath was accessed");
    }
}