Skip to content

Commit

Permalink
Allowing "recursive" value replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Feb 21, 2024
1 parent 6a1cb79 commit bf293f2
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/ControlzEx/Theming/ThemeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#nullable enable
namespace ControlzEx.Theming
namespace ControlzEx.Theming
{
using System.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;

// This class has to be kept in sync with https://github.com/batzen/XamlColorSchemeGenerator/blob/develop/src/ThemeGenerator.cs
// This class has to be kept in sync with https://github.com/batzen/XAMLTools/blob/develop/src/XAMLTools.Core/XAMLColorSchemeGenerator/ThemeGenerator.cs
// Please do not remove unused code/properties here as it makes syncing more difficult.
[PublicAPI]
public class ThemeGenerator
Expand Down Expand Up @@ -37,13 +36,30 @@ public virtual string GenerateColorSchemeFileContent(string templateContent, str
templateContent = templateContent.Replace("{{AlternativeColorScheme}}", alternativeColorScheme);
templateContent = templateContent.Replace("{{IsHighContrast}}", isHighContrast.ToString());

foreach (var valueSource in valueSources)
bool contentChanged;

// Loop till content does not change anymore.
do
{
foreach (var value in valueSource)
contentChanged = false;

foreach (var valueSource in valueSources)
{
templateContent = templateContent.Replace($"{{{{{value.Key}}}}}", value.Value);
foreach (var value in valueSource)
{
var finalValue = value.Value;
var newTemplateContent = templateContent.Replace($"{{{{{value.Key}}}}}", finalValue);

if (templateContent != newTemplateContent)
{
contentChanged = true;
}

templateContent = newTemplateContent;
}
}
}
while (contentChanged is true);

return templateContent;
}
Expand Down

0 comments on commit bf293f2

Please sign in to comment.