Zhy.Components.Configuration
2.0.5
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.0
This package targets .NET Core 3.0. The package is compatible with this framework or higher.
.NET Framework 4.6.1
This package targets .NET Framework 4.6.1. The package is compatible with this framework or higher.
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Zhy.Components.Configuration --version 2.0.5
NuGet\Install-Package Zhy.Components.Configuration -Version 2.0.5
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="Zhy.Components.Configuration" Version="2.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zhy.Components.Configuration" Version="2.0.5" />
<PackageReference Include="Zhy.Components.Configuration" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zhy.Components.Configuration --version 2.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Zhy.Components.Configuration, 2.0.5"
#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.
#:package Zhy.Components.Configuration@2.0.5
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zhy.Components.Configuration&version=2.0.5
#tool nuget:?package=Zhy.Components.Configuration&version=2.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Zhy.Components.Configuration
Doc
Config配置文件组件,支持运行时读取、写入配置、加解密、运行时类型转换器,修改静态配置文件无感刷新运行时配置...
Demo
加密器:
/// <summary>
/// 加密器
/// </summary>
public class TestEncipher : IConfigurationEncipher
{
public string Decrypt(string ciphertext)
{
return ciphertext.Replace("加密了:", "");
}
public string Encrypt(string plaintext)
{
return "加密了:" + plaintext;
}
}
转换器:
/// <summary>
/// 类型转换器
/// </summary>
public class IntNullableConfigurationConverter : IConfigurationConverter
{
public object Read(string value)
{
if (value == null)
{
return null;
}
int? valueAsInt = int.Parse(value);
return valueAsInt;
}
public string Write(object value)
{
if (value == null)
{
return string.Empty;
}
return value + "";
}
}
配置上下文:
/// <summary>
/// 配置上下文
/// </summary>
[ConfigurationContext(isHotLoad: true, isInitialGeneration: true)]
public class AppConfig : ConfigurationContextBase
{
public string? ActiveToken { get; set; }
[ConfigurationItem(key: "active_user")]
public string? ActiveUser { get; set; }
[ConfigurationItem(key: "active_user_pwd", encipherType: typeof(TestEncipher))]
public string? ActiveUserPassword { get; set; }
[ConfigurationItem(key: "request_timeout_s", defaultValue: 10, converterType: typeof(IntNullableConfigurationConverter))]
public int? TimeOut { get; set; }
private static AppConfig? _instance;
private AppConfig() { }
public static AppConfig Instance
{
get => _instance ??= new AppConfig();
}
public override string GetPersistentPath()
{
return AppDomain.CurrentDomain.BaseDirectory + "conf\\app.config";
}
}
配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="active_user" value="admin" />
<add key="active_user_pwd" value="加密了:admin123" />
<add key="request_timeout_s" value="10" />
</appSettings>
</configuration>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
| .NET Framework | net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.0
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETCoreApp 3.1
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETFramework 4.6.1
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETFramework 4.6.2
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETFramework 4.7
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETFramework 4.7.1
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETFramework 4.7.2
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETFramework 4.8
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
.NETFramework 4.8.1
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
net5.0
- System.Configuration.ConfigurationManager (>= 4.6.0)
-
net6.0
- System.Configuration.ConfigurationManager (>= 6.0.0)
-
net7.0
- System.Configuration.ConfigurationManager (>= 6.0.0)
-
net8.0
- System.Configuration.ConfigurationManager (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
1. 解决初始化生成配置文件未使用指定默认值问题;