I'm working on a C# project which provides users an on-demand method of importing data from various formats and then performs mail-merge-like actions to complete a template. The process works for basic data types. However, I need to add the ability to perform calculations on the existing data (which is not present in the source) so the results can be placed on the output.
Example 1:
Date range -- if there is data in both the start date and end date fields then the output should contain the two dates separated by " - ". If only one is present then just that date is output.
Example 2:
Conditionals -- if data in field X meets criteria Y then output Z.
Example 3:
Format text before conversion to number and format output as currency.
Source Field: "000059975"
Desired Output: "$599.75"
Note that the text version of the number was of fixed length and included both whole and partial units of currency (dollars and cents in this case).
I understand how to perform these actions in code; however, all configuration of the data sources and the "calculated" fields must be done at runtime via strings. All data, once imported, is placed in a DataTable, so any solution will have access to the capabilities thereof in C# 4.
Some ideas I've considered so far:
- lambda functions with a regex replace
- direct C# expressions
- scripting language (e.g., SQL / JavaScript / Python) processing
- A DSL (though I have no experience with designing/implementing such)
I've not successfully identified a way to implement any of the above possibilities. Note also that while this is an internal business application which will largely be used by a small group of IT staff, I'd prefer to stick with a solution which limits the possibility of arbitrary code execution.
What techniques exist to address this need?