Skip to content

Commit 4856d1f

Browse files
committed
Add option to have arrays defined
You can add arrays to the settings like so: "EASYCONFIG__peng__0": "null", "EASYCONFIG__peng__1": "eins", +semver: feature Thanks to @d03n3rfr1tz3
1 parent f26b927 commit 4856d1f

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

.vscode/launch.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"ASPNETCORE_ENVIRONMENT": "Development",
2424
"EASYCONFIG__apiUrl": "https://codez.one/api",
2525
"EASYCONFIG__test__value": "blubb",
26+
"EASYCONFIG__peng__0": "null",
27+
"EASYCONFIG__peng__1": "eins",
2628
//"KeyVault__Uri": "peng"
2729
//"KeyVault__Uri__0": "peng",
2830
//"KeyVault__Uri__1": "puff"

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "3.0.100"
3+
"version": "3.0.101"
44
}
55
}

src/EasyConfig.SiteExtension/Controllers/ConfigController.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace EasyConfig.SiteExtension.Controllers
22
{
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Text.Json;
56
using Microsoft.AspNetCore.Mvc;
67
using Microsoft.Extensions.Configuration;
@@ -34,18 +35,36 @@ public JToken GetEnvironment()
3435

3536
private JToken Serialize(IConfiguration config)
3637
{
37-
var obj = new JObject();
38-
foreach (var child in config.GetChildren())
39-
{
40-
obj.Add(child.Key, this.Serialize(child));
41-
}
38+
var childs = config.GetChildren();
39+
var isArray = childs.Any() && childs.All(child => int.TryParse(child.Key, out var number));
4240

43-
if (!obj.HasValues && config is IConfigurationSection section)
41+
if (isArray)
4442
{
45-
return new JValue(section.Value);
43+
var obj = new JArray();
44+
45+
foreach (var child in childs)
46+
{
47+
obj.Add(this.Serialize(child));
48+
}
49+
50+
return obj;
4651
}
52+
else
53+
{
54+
var obj = new JObject();
55+
56+
foreach (var child in childs)
57+
{
58+
obj.Add(child.Key, this.Serialize(child));
59+
}
4760

48-
return obj;
61+
if (!obj.HasValues && config is IConfigurationSection section)
62+
{
63+
return new JValue(section.Value);
64+
}
65+
66+
return obj;
67+
}
4968
}
5069
}
5170
}

0 commit comments

Comments
 (0)