private static void ValidateDocumentTemplate(DocumentTemplate documentTemplate) { var fieldsInBody = Regex.Matches(documentTemplate.Body + " ", @"\$(\S+)\$"); foreach (var bodyField in fieldsInBody) { var bodyFieldName = bodyField.ToString(); if (documentTemplate.GetAllowedFieldsWithDelimeters().All(p => p != bodyFieldName)) { throw new BusinessRuleException("Body", string.Format( "The field {0} is not in the allowable list of fields for this template", bodyFieldName)); } } }