/// <summary> /// Replaces all hard {{{data_fieldname}}} and soft {{data_fieldname}} fields if mached with <c>data</c> PropertyCollection key values. /// </summary> /// <param name="template">Any string that has {{{}}} template tags within</param> /// <param name="data">Collection with <c>key</c> values matching template tags</param> /// <param name="removeUnMatched">If TRUE it will remove all remaining/unmached tags. Use this if collection is the last PropertyCollection to apply</param> /// <returns>String with matched template tags replaced with content from <c>data</c> collection</returns> public static String applyToContent(this String template, PropertyCollection data, Boolean removeUnMatched = false) { reportTemplatePlaceholderCollection plc = new reportTemplatePlaceholderCollection(); plc.loadTemplateString(template); return(plc.applyToContent(data, template, removeUnMatched)); }
/// <summary> /// Replaces all template placeholder fields if mached with <c>data</c> PropertyCollection key values. /// </summary> /// <param name="template">Any string that has {{{}}} template tags within</param> /// <param name="dataset">Multiple PropertyCollection or IEnumerable collections with PropertyCollection instances</param> /// <param name="removeUnMatched">If TRUE it will remove all remaining/unmached tags in the last iteration / PropertyCollection supplied.</param> /// <returns>String with matched template tags replaced with content from <c>data</c> collection.</returns> /// <remarks> /// It uses internally <see cref="reportTemplatePlaceholderCollection"/> for template mechanism. /// You may provide any and multiple IEnumerable PropertyCollection collections as part of <c>dataset</c> params array. /// </remarks> /// <example> /// <code> /// String templateString = "His is {{{title}}} {{{first_name}}} {{{last_name}}} working with {{{company_name}}}." /// String output = templateString.applyToContent(true, contactBean, accountBean); /// </code> /// Where <c>contactBean</c> and <c>accountBean</c> contain data from a corporate CRM. /// </example> /// <example> /// <code> /// String output = templateString.applyToContent(true, contactBean, allCrmBeans, accountBean); /// </code> /// Where <c>allCrmBeans</c> is IEnumerable with multiple PropertyCollection instances. /// </example> public static String applyToContent(this String template, Boolean removeUnMatched, params PropertyCollection[] dataset) { PropertyCollection[] data = dataset.getFlatArray <PropertyCollection>(); String mContent = template; var dcl = data.Last(); // plc.loadTemplateString(template); if (template.isTemplate()) { reportTemplatePlaceholderCollection plc = new reportTemplatePlaceholderCollection(template); foreach (PropertyCollection dc in data) { mContent = plc.applyToContent(dc, mContent, ((dcl == dc) && removeUnMatched)); } } return(mContent); }