title: Using CSharpCodeProvider to allow user created functions
body: <p>I have an existing asp.net (c#) application. I need to provide users with a way to create flexibles rules to calculate an effective date given a hiredate and an enrollmentdate.</p>
  
  <p>Some examples of rules that might be used:</p>
  
  <ol>
  <li>The later of hiredate or enrollmentdate</li>
  <li>HireDate + 90 Days</li>
  <li>The first of the Month after the enrollment date</li>
  <li>If the enrollment date is before the 15 of the month, then the effective date is the 1st of the next month. If it is on the 15 or after, it's the 1st of the month after that.</li>
  </ol>
  
  <p>I started out with a handful of offset fields (day offset, month offset, etc...), but as I come across new requirements, I'm coming to realize the current approach isn't flexible enough.</p>
  
  <p>What I would like to do is allow the end user to define a function that returns a date given two parameters (hiredate, enrollmentdate), and store that function in the database. When I need to calculate the effectivedate I'd pull this function out of the database execute it passing in the parameters to get my effectivedate.</p>
  
  <p>My intial reaction was to look for a DSL that would allow me to define date manipulation functions and integrate that into my solution. However my search for an appropriate DSL has turned up nothing. </p>
  
  <p>Now I am wondering whether CSharpCodeProvider might work as a component to the solution.
  If I pull a string out of a database, and compile it via CsharpCodeProvider, can I enforce that the resulting code matches a function signature (takes 2 datetime parameters, and returns a datatime)?</p>
  
  <p>Is there a way to ensure that the function doesn't have any side effects? For example, No I/O. No reading or session, cache, or application. </p>