mh_frame_sps/APT.Infrastructure.Api/Extensions/ConfigurationSectionExtension.cs
2026-04-07 13:47:52 +08:00

74 lines
1.8 KiB
C#

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
namespace APT.Infrastructure.Api
{
public class ConfigurationSectionExtension : IConfigurationSection, IConfiguration
{
private readonly string sectionKey;
private IConfiguration configuration;
public string Key
{
get;
}
public string Path
{
get;
}
public string Value
{
get;
set;
}
public string this[string key]
{
get
{
string enviromentValue = GetEnviromentValue(key);
if (string.IsNullOrEmpty(enviromentValue))
{
return configuration.GetSection(sectionKey)[key];
}
return enviromentValue;
}
set
{
configuration.GetSection(sectionKey)[key] = value;
}
}
public ConfigurationSectionExtension(string sectionKey, IConfiguration configuration)
{
this.sectionKey = sectionKey;
this.configuration = configuration;
}
public IEnumerable<IConfigurationSection> GetChildren()
{
throw new NotImplementedException();
}
public IChangeToken GetReloadToken()
{
throw new NotImplementedException();
}
public IConfigurationSection GetSection(string key)
{
throw new NotImplementedException();
}
protected virtual string GetEnviromentValue(string key)
{
return System.Environment.GetEnvironmentVariable(key);
}
}
}