title: Is there an easy way to parse a (lambda expression) string into an Action delegate?
body: <p>I have a method that alters an "Account" object based on the action delegate passed into it:</p>
  
  <pre><code>public static void AlterAccount(string AccountID, Action&lt;Account&gt; AccountAction) {
    Account someAccount = accountRepository.GetAccount(AccountID);
    AccountAction.Invoke(someAccount);
    someAccount.Save();
  }
  </code></pre>
  
  <p>This works as intended...</p>
  
  <pre><code>AlterAccount("Account1234", a =&gt; a.Enabled = false);
  </code></pre>
  
  <p>...but now what I'd like to try and do is have a method like this:</p>
  
  <pre><code>public static void AlterAccount(string AccountID, string AccountActionText) {
    Account someAccount = accountRepository.GetAccount(AccountID);
    Action&lt;Account&gt; AccountAction = MagicLibrary.ConvertMagically&lt;Action&lt;Account&gt;&gt;(AccountActionText);
    AccountAction.Invoke(someAccount);
    someAccount.Save();
  }
  </code></pre>
  
  <p>It can then be used like:</p>
  
  <pre><code>AlterAccount("Account1234", "a =&gt; a.Enabled = false");
  </code></pre>
  
  <p>to disable account "Account1234".</p>
  
  <p>I've had a look at the <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" rel="noreferrer">linq dynamic query library</a>, which seems to do more or less what I want but for Func type delegates, and my knowledge of Expression trees etc isn't quite good enough to work out how to achieve what I want.  </p>
  
  <p>Is there an easy way to do what I want, or do I need to learn expressions properly and write a load of code?</p>
  
  <p>(The reason I want to do this is to allow an easy way of bulk updating account objects from a powershell script where the user can specify a lambda expression to perform the changes.)</p>