using System.Linq.Expressions;
using System.Text.RegularExpressions;
public static void Main()
Console.WriteLine(ReplaceMacro("{Job.Name} job for admin",
new Job { Id = 1, Name = "Todo", Description="Nothing" }));
Console.WriteLine(ReplaceMacro(@"Using Customer Type:
Customer Name: {Customer.Name}
Customer Id: {Customer.Id}",
new Customer { Id = 1, Name = "Jack" }));
public static string ReplaceMacro(string value, object @object)
return Regex.Replace(value, @"{(.+?)}",
var p = Expression.Parameter(@object.GetType(), @object.GetType().Name);
var e = System.Linq.Dynamic.DynamicExpression.ParseLambda(new[] { p }, null, match.Groups[1].Value);
return (e.Compile().DynamicInvoke(@object) ?? "").ToString();
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int Id { get; set; }
public string Name { get; set; }