Skip to content

Class AppSettings

Namespace: Tool.Utils
Assembly: Tool.Net.dll

获取配置文件数据 (允许修改原文件异步队列式更新)

csharp
public sealed class AppSettings

Inheritance

objectAppSettings

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)

Fields

FileName

主配置文件名

csharp
public const string FileName = "appsettings.json"

Field Value

string

FileNameDevelopment

调试配置文件名

csharp
public const string FileNameDevelopment = "appsettings.Development.json"

Field Value

string

Properties

Configuration

项目配置文件获取对象

csharp
public static IConfigurationRoot Configuration { get; }

Property Value

IConfigurationRoot

CurrentDirectory

获取当前配置文件的路径

csharp
public static string CurrentDirectory { get; }

Property Value

string

this[string]

获取key值

csharp
public string this[string key] { get; }

Property Value

string

Methods

AddJsonFile(string)

根据你提供的地址获取配置文件信息

csharp
public static IConfiguration AddJsonFile(string filePath)

Parameters

filePath string

配置文件路径

Returns

IConfiguration

返回指定对象

Get(string, bool)

获取appSettings的value

csharp
public static string Get(string key, bool throwOnError = true)

Parameters

key string

名称

throwOnError bool

true 表示在找不到该键值时引发异常;false 则表示返回 null。

Returns

string

返回值,如果键值名称不存在则返回

GetChildren()

获取直接子代配置子节。

csharp
public static IEnumerable<IConfigurationSection> GetChildren()

Returns

IEnumerable<IConfigurationSection>

配置子部分。

GetInt(string, bool)

获取appSettings的value

csharp
public static int GetInt(string key, bool throwOnError = true)

Parameters

key string

名称

throwOnError bool

true 表示在找不到该键值时引发异常;false 则表示返回 null。

Returns

int

返回值,如果键值名称不存在则返回0

GetReloadToken()

返回Microsoft.Extensions.Primitives.IChangeToken,可用于观察重新加载此配置时。

csharp
public static IChangeToken GetReloadToken()

Returns

IChangeToken

一个Microsoft.Extensions.Primitives.IChangeToken。

GetSection(string)

获取具有指定键的配置子节。

csharp
public static IConfigurationSection GetSection(string key)

Parameters

key string

配置部分的键。

Returns

IConfigurationSection

这个 Microsoft.Extensions.Configuration.IConfigurationSection

SetEvent

注册修改 IConfiguration 值的事件 (将取消默认实现的同步修改文件)

csharp
public static event Action<string, string> SetEvent

Event Type

Action<string, string>

基于Apache-2.0协议开源