private ProcessedDocument MapDocument(Document document, CustomerDocumentFieldValues customerDocumentFieldValues) { string documentBody = document.Body; const string pattern = @"\$\((?'property'\S+?)\)"; Func<Match, Dictionary<String, String>, String> RegexMatchEvaluator = (Match match, Dictionary<String, String> customerFieldValues) => { string propertyName = match.Groups["property"].Value; return customerFieldValues[propertyName]; }; documentBody = Regex.Replace(documentBody, pattern, new MatchEvaluator( match => RegexMatchEvaluator(match, customerDocumentFieldValues.DocumentFields)), RegexOptions.ExplicitCapture); return new ProcessedDocument { Title = document.Title, Body = documentBody, }; }