mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-04-14 04:56:37 +00:00
Updates merge methods to handle unkeyed arrays by replacing the template array with the system array
This commit is contained in:
parent
79b9059f1b
commit
5b1f1e683f
2 changed files with 25 additions and 18 deletions
|
|
@ -67,7 +67,7 @@ namespace PepperDash.Core.Config
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="doubleConfig"></param>
|
/// <param name="doubleConfig"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static JObject MergeConfigs(JObject doubleConfig)
|
public static JObject MergeConfigs(JObject doubleConfig)
|
||||||
{
|
{
|
||||||
var system = JObject.FromObject(doubleConfig["system"]);
|
var system = JObject.FromObject(doubleConfig["system"]);
|
||||||
var template = JObject.FromObject(doubleConfig["template"]);
|
var template = JObject.FromObject(doubleConfig["template"]);
|
||||||
|
|
@ -114,15 +114,21 @@ namespace PepperDash.Core.Config
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Merges the contents of a base and a delta array, matching the entries on a top-level property
|
/// Merges the contents of a base and a delta array, matching the entries on a top-level property
|
||||||
/// given by propertyName. Returns a merge of them. Items in the delta array that do not have
|
/// given by propertyName. Returns a merge of them. Items in the delta array that do not have
|
||||||
/// a matched item in base array will not be merged.
|
/// a matched item in base array will not be merged. Non keyed system items will replace the template items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static JArray MergeArraysOnTopLevelProperty(JArray a1, JArray a2, string propertyName, string path)
|
static JArray MergeArraysOnTopLevelProperty(JArray a1, JArray a2, string propertyName, string path)
|
||||||
{
|
{
|
||||||
var result = new JArray();
|
var result = new JArray();
|
||||||
if (a2 == null)
|
if (a2 == null || a2.Count == 0) // If the system array is null or empty, return the template array
|
||||||
result = a1;
|
return a1;
|
||||||
else if (a1 != null)
|
else if (a1 != null)
|
||||||
{
|
{
|
||||||
|
if (a2[0]["key"] == null) // If the first item in the system array has no key, overwrite the template array
|
||||||
|
{ // with the system array
|
||||||
|
return a2;
|
||||||
|
}
|
||||||
|
else // The arrays are keyed, merge them by key
|
||||||
|
{
|
||||||
for (int i = 0; i < a1.Count(); i++)
|
for (int i = 0; i < a1.Count(); i++)
|
||||||
{
|
{
|
||||||
var a1Dev = a1[i];
|
var a1Dev = a1[i];
|
||||||
|
|
@ -135,6 +141,7 @@ namespace PepperDash.Core.Config
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result.Add(a1Dev);
|
result.Add(a1Dev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,4 @@
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("Pepperdash_Core")]
|
[assembly: AssemblyProduct("Pepperdash_Core")]
|
||||||
[assembly: AssemblyCopyright("Copyright © PepperDash 2019")]
|
[assembly: AssemblyCopyright("Copyright © PepperDash 2019")]
|
||||||
[assembly: AssemblyVersion("1.0.13.*")]
|
[assembly: AssemblyVersion("1.0.15.*")]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue