XFEExtension.NetCore.AutoPath
📖 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");
}
}