Working on tenants and config
This commit is contained in:
parent
c10de11bbe
commit
f3352318f5
12 changed files with 309 additions and 19 deletions
57
Core/Configurations/Class1.cs
Normal file
57
Core/Configurations/Class1.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Configurations
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
public class KeyValueNester
|
||||
{
|
||||
private JObject _rootObject = new JObject();
|
||||
|
||||
public void AddKeyValue(string key, string jsonValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Parse input JSON value
|
||||
var valueObject = JsonConvert.DeserializeObject<JObject>(jsonValue);
|
||||
var parts = key.Split(':');
|
||||
|
||||
// Start med root object eller nuværende struktur
|
||||
JObject current = _rootObject;
|
||||
|
||||
// Gennemgå hver del af key'en
|
||||
for (int i = 0; i < parts.Length - 1; i++)
|
||||
{
|
||||
string part = parts[i];
|
||||
if (!current.ContainsKey(part))
|
||||
{
|
||||
current[part] = new JObject();
|
||||
}
|
||||
current = (JObject)current[part];
|
||||
}
|
||||
|
||||
// Tilføj den sidste værdi
|
||||
current[parts[^1]] = valueObject;
|
||||
}
|
||||
catch (JsonReaderException ex)
|
||||
{
|
||||
throw new ArgumentException("Invalid JSON value", nameof(jsonValue), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public JObject GetResult()
|
||||
{
|
||||
return _rootObject;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_rootObject = new JObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue