XFEExtension.NetCore.AutoConfig
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package XFEExtension.NetCore.AutoConfig --version 1.0.0
NuGet\Install-Package XFEExtension.NetCore.AutoConfig -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XFEExtension.NetCore.AutoConfig" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XFEExtension.NetCore.AutoConfig --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: XFEExtension.NetCore.AutoConfig, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XFEExtension.NetCore.AutoConfig as a Cake Addin #addin nuget:?package=XFEExtension.NetCore.AutoConfig&version=1.0.0 // Install XFEExtension.NetCore.AutoConfig as a Cake Tool #tool nuget:?package=XFEExtension.NetCore.AutoConfig&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
XFEExtension.NetCore.AutoConfig
描述
XFEExtension.NetCore.AutoConfig是一个可以自动实现配置文件存储的工具
自动实现配置文件的存储
基础用法
//创建配置文件类
partial class SystemConfig
{
[ConfigProperty]
string name;
[ConfigProperty]
int _age;
}
//使用配置文件
class Program
{
static void Main(string[] args)
{
SystemConfig.Name = "Test";//在设置值的时候会自动记录并储存
//SystemConfig.Age = 1;
Console.WriteLine(SystemConfig.Name);
Console.WriteLine(SystemConfig.Age);//下次打开程序会自动读取上次程序退出时储存的值
}
}
设置get和set方法
partial class SystemConfig
{
[ConfigProperty]
[ConfigPropertyAddGet(@"Console.WriteLine(""获取了Name"")")]
[ConfigPropertyAddGet("return Current.name")]
[ConfigPropertyAddSet(@"Console.WriteLine(""设置了Name"")")]
[ConfigPropertyAddSet("Current.name = value")]
string name = string.Empty;
[ConfigProperty]
[ConfigPropertyAddGet(@"Console.WriteLine(""获取了Age"")")]
[ConfigPropertyAddGet("return Current._age")]
[ConfigPropertyAddSet(@"Console.WriteLine(""设置了Age"")")]
[ConfigPropertyAddSet("Current._age = value")]
int _age;
}
设置初始值
partial class SystemConfig
{
[ConfigProperty]
string name = "John Wick";
[ConfigProperty]
int _age = 59;
}
为属性添加注释
partial class SystemConfig
{
/// <summary>
/// 名称
/// 这段注释会自动添加至自动生成的Name属性上
/// </summary>
[ConfigProperty]
string name;
[ConfigProperty]
int _age;
}
使用部分方法来设置get和set方法
partial class SystemConfig
{
[ConfigProperty]
string name;
[ConfigProperty]
int _age;
static partial void GetNameProperty()
{
Console.WriteLine("获取了Name");
}
static partial void SetNameProperty(string value)
{
Console.WriteLine($"设置了Name:从{Name}变为了{value}");
}
static partial void GetAgeProperty()
{
Console.WriteLine("获取了Age");
}
static partial void SetAgeProperty(int value)
{
Console.WriteLine($"设置了Age:从{Age}变为了{value}");
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- XFEExtension.NetCore (>= 2.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
First Release