mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-07-08 17:57:02 +00:00
This change looks dramatic, but it's just separating out the already-split namespaces into separate top-level folders. In theory, every single one could be built into their own Nuget package. `SabreTools.IO.Meta` builds the normal Nuget package that is used by all other projects and includes all namespaces. `SabreTools.IO` builds to `SabreTools.IO.Common` to avoid overwriting issues on publish.
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace SabreTools.IO.Extensions
|
|
{
|
|
public static class DictionaryExtensions
|
|
{
|
|
/// <summary>
|
|
/// Merge a dictionary into an existing one, if possible
|
|
/// </summary>
|
|
/// <param name="dict">Source dictionary to add to</param>
|
|
/// <param name="other">Second dictionary to add from</param>
|
|
/// <remarks>This only performs a shallow copy</remarks>
|
|
public static void MergeWith(this Dictionary<string, List<string>> dict, Dictionary<string, List<string>> other)
|
|
{
|
|
// Ignore if there are no values to append
|
|
if (other.Count == 0)
|
|
return;
|
|
|
|
// Loop through and add from the new dictionary
|
|
foreach (var kvp in other)
|
|
{
|
|
// Ignore empty values
|
|
if (kvp.Value.Count == 0)
|
|
continue;
|
|
|
|
if (!dict.ContainsKey(kvp.Key))
|
|
dict[kvp.Key] = [];
|
|
|
|
dict[kvp.Key].AddRange(kvp.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|