using System.Collections;
using System.Collections.Generic;
public static void Main()
var placeholders = GetExamplePlaceholders();
var pagePayloadObject = GetExamplePagePayload();
var serializedPagePayloadObject = JsonConvert.SerializeObject(pagePayloadObject);
Console.WriteLine(serializedPagePayloadObject);
serializedPagePayloadObject = ReplacePlaceholderValues(serializedPagePayloadObject, placeholders);
Console.WriteLine("*********************************************");
var deserializedPagePayloadObject = JsonConvert.DeserializeObject(serializedPagePayloadObject);
Console.WriteLine(deserializedPagePayloadObject);
private static string ReplacePlaceholderValues(string source, Dictionary<string, string> placeholders)
var replacedText = placeholders.Aggregate(source, (current, replacement) =>
return current.Replace(replacement.Key, replacement.Value);
private static PagePayload GetExamplePagePayload()
var dummyContentBlocks = new List<ContentBlock>();
for (var i = 1; i <= 3; i++)
dummyContentBlocks.Add(GenerateDummyContentBlock(i));
ContentBlocks = dummyContentBlocks,
AltContentBlocks = dummyContentBlocks,
BasicContent = "<p>Some other html content that may or may not contain placeholders: \"[!BasicPlaceholder]\"</p>",
BasicContentAlt = "<p>Another placeholder: \"[!Placeholder1]\"</p>"
private static Dictionary<string, string> GetExamplePlaceholders()
return new Dictionary<string, string>()
{ "[!Placeholder1]", "<p>Some text which contains a nested placeholder: \"[!NestedPlaceholder1]\"</p>" },
{ "[!NestedPlaceholder1]", "<span>Nested Placeholder 1 value, contains another placeholder: \"[!NestedPlaceholder2]\"</span>" },
{ "[!NestedPlaceholder2]", "A Simple string with no html content" },
{ "[!BaseUrl]", "https://example.com" },
{ "[!BasicPlaceholder]", "More simple text" }
private static ContentBlock GenerateDummyContentBlock(int id)
Title = "Smart Marketing Block Title " + id.ToString(),
Description = "Smart Marketing Block Description " + id.ToString(),
Link = GenerateDummyLink(id)
private static Link GenerateDummyLink(int id)
Name = "Link Name " + id.ToString(),
Url = "[!BaseUrl]/a-relative-page"
public IEnumerable<ContentBlock> ContentBlocks { get; set; }
public IEnumerable<ContentBlock> AltContentBlocks { get; set; }
public string BasicContent { get; set ; }
public string BasicContentAlt { get; set ; }
public class ContentBlock
public string Title { get; set; }
public string Description { get; set; }
public Link Link { get; set; }
public string ImageUrl { get; set; }
public string ImageAltText { get; set; }
public string Name { get; set; }
public string Url { get; set; }