Skip to content

Commit 53989b4

Browse files
Added base files.
1 parent d87b2a4 commit 53989b4

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

C9S.Extensions.Configuration.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Debug|x64 = Debug|x64
10+
Debug|x86 = Debug|x86
11+
Release|Any CPU = Release|Any CPU
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(SolutionProperties) = preSolution
16+
HideSolutionNode = FALSE
17+
EndGlobalSection
18+
EndGlobal
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
3+
namespace C9S.Extensions.Configuration
4+
{
5+
public static class ConfigurationRootExtensions
6+
{
7+
public static void ResolveVariables(this IConfigurationRoot configuration)
8+
{
9+
foreach (var configSection in configuration.GetChildren())
10+
{
11+
foreach (Match match in variableRegex.Matches(configSection.Value ?? ""))
12+
{
13+
var variable = match.Groups["var"].Value;
14+
var sections = new List<string>(variable.Split('.', System.StringSplitOptions.RemoveEmptyEntries));
15+
IConfigurationSection section = configSection;
16+
if (sections.Any())
17+
{
18+
section = Configuration.GetSection(sections[0]);
19+
var key = sections.Last();
20+
21+
sections.RemoveAt(0);
22+
sections.RemoveAt(sections.Count - 1);
23+
foreach (var sec in sections)
24+
{
25+
section = section.GetSection(sec);
26+
}
27+
28+
configSection.Value = configSection.Value.Replace($"{{{{{variable}}}}}", section[key]);
29+
}
30+
}
31+
32+
ResolveVariables(configSection);
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)