using System.Linq.Expressions;
using System.Text.RegularExpressions;
using System.Collections.Generic;
public static void Main()
var j = new Job { Id = 1, Name = "Tod", Description="Nothing", Customer = c };
var jj = new Job { Id = 1, Name = "Tod", Description="Nothing" };
var vv = new List<Job>(){j, j};
Console.WriteLine(vv.Count);
Console.WriteLine(ReplaceMacro(@"{items[0].Customer.Name} job for admin", vv));
Console.WriteLine(ReplaceMacro(@"{Job.Name} job for admin", j));
public static string ReplaceMacro(string value, object @object)
return Regex.Replace(value, @"{(.+?)}",
var p = Expression.Parameter(@object.GetType(), @object.GetType().Name);
if(@object.GetType().Equals(typeof(List<Job>)))
p = Expression.Parameter(@object.GetType(), "items");
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 Customer Customer {get; set; }
public int Id { get; set; }
public string Name { get; set; }