title: Get result of executed method in Command Pattern
body: <p>Currently I'm trying to implement Transaction Script pattern (Exactly how Martin Fowler <a href="http://www.martinfowler.com/eaaCatalog/transactionScript.html" rel="noreferrer">described</a> by using <a href="http://www.dofactory.com/Patterns/PatternCommand.aspx#_self1" rel="noreferrer">Command Pattern</a>) in a simple test project, everything just work fine, the problem is where I don't know how to get result(s) when specified method executed in concrete class which is inherited from ICommand interface.</p>
  
  <p>Let's show you some code to clarify what functionality I have.
  I've a simple CalculateSalaryCommand class which inherited from ICommand interface</p>
  
  <pre><code>public class CalculateSalaryCommand : ICommand
  {
      private readonly CalculateSalaryTS _salaryTs;
      private readonly int _hour;
      private readonly int _salaryPerHour;
  
      public CalculateSalaryCommand(CalculateSalaryTS salaryTs, int hour, int salaryPerHour)
      {
          _salaryTs = salaryTs;
          _hour = hour;
          _salaryPerHour = salaryPerHour;
      }
  
      public void Execute()
      {
          _salaryTs.CalculateSalary(_hour, _salaryPerHour);
      }
  }
  </code></pre>
  
  <p>and a simple Transaction Script class named CalculateSalaryTS</p>
  
  <pre><code>public class CalculateSalaryTS {
      public void CalculateSalary(int _hour, int _salaryPerHour) {
          Result = _hour * _salaryPerHour;
      }
  }
  </code></pre>
  
  <p>as you can see I pass the instance of to concrete command class, then inside the Execute method I execute a operations from that instance. Well, everything just look good. but there is a problem I can't return the result of executed method which is should be a integer.
  To handle this problem, I decided to add some code to Transaction Script layer which each transaction should inherit from a generic <code>ITransactionResult</code> interface, which is look like following:</p>
  
  <pre><code>public interface ITransactionResult&lt;TResult&gt;
  {
      TResult Result { get; set; }
  }
  </code></pre>
  
  <p>Then CalculateSalaryTS class became like this :</p>
  
  <pre><code>public class CalculateSalaryTS : ITransactionResult&lt;Int32&gt; {
  
      public void CalculateSalary(int _hour, int _salaryPerHour) {
          Result = _hour * _salaryPerHour;
      }
  
      public int Result { get; set; }
  
  }
  </code></pre>
  
  <p><strong>Usage :</strong></p>
  
  <pre><code>    var script = new CalculateSalaryTS();
      var command = new CalculateSalaryCommand(script, 10, 20);           
      command.Execute();
      Console.WriteLine("Salary is {0}", script.Result);
  </code></pre>
  
  <p>I know this way has its own limitation but I don't have any choice till you give me another idea to handle this situation.</p>
  
  <p>Thanks in advance.</p>