We are using the MailMerge functionality quite a lot and most of the times we are merging data stored in a custom type. In order to achieve this, we had to implement our own IMailMergeDataSource which gets the value of mergefields using reflection. So far so good :).
However, during the MailMerge process the only way to ‘hook’ into the process is to use a custom MergeFieldEventHandler. Within such an eventhandler we get some information about the field being merged and it’s value (found within the datasource using the (custom) MailMergeDataSource). What we are missing is a reference to the actual MailMergeDataSource which was used to get the field value from. If that reference could be added to the MailMergeEventArgs we could:
- Determine whether the field was found within the datasource (whenever multiple datasources are merged with the same template). This is usefull information whenever you would like to adjust the document based on the information of the value of a mergefield (e.g. delete the parent row of a mergefield whenever it’s value is ‘null’.)
- Make use of information stored in e.g. custom attributes which are added to the properties of the custom type being merged. (This gives us the flexibility to format the value of a field according to the settings of it’s attribute.)
- and more…
So in short my question is: Can you add/expose a reference to the IMailMergeDataSource, that was used to get the value of mergefield, within the MergeFieldEventArgs?