title: How can I pass a property of a class as a parameter of a method?
body: <p>I have a class that has a dozen or so properties that represent various financial fields. I have another class that needs to perform some calculations on each of those fields separately. The code inside those calculation methods are identical except for the field that it does the calculation on.</p>
  
  <p>Is there a way that I can pass a property name as a parameter and just have one method that does all of the performing work instead of the 12 methods for each property?</p>
  
  <p>Also, I'm sure this can be accomplished via reflection, but I've seen in other code where lambdas are used in this same kind of fashion and was wondering if this is a candidate where this can be used.</p>
  
  <p>As requested, here is an example:</p>
  
  <pre><code>public class FinancialInfo
  {
      public virtual DateTime AuditDate { get; set; }
      public virtual decimal ReleasedFederalAmount { get; set; }
      public virtual decimal ReleasedNonFederalAmount { get; set; }
      public virtual decimal ReleasedStateAmount { get; set; }
      public virtual decimal ReleasedLocalAmount { get; set; }
      public virtual decimal ReleasedPrivateAmount { get; set; }
      // more fields like this
  }
  
  public class FinancialLedger()
  {
      public virtual DateTime? BeginDate { get; set; }
      public virtual DateTime? EndDate { get; set; }
      public virtual IList&lt;FinancialInfo&gt; Financials { get; set; } //not actual implementation, but you get the idea
      public decimal GetTotalReleasedFederalAmountByDate()
      {
          if (BeginDate == null &amp;&amp; EndDate == null)
              return 0;
          decimal total = 0;
          foreach (var fi in Financials)
          {
              if (someCondition)
                  if (someSubCondition)
                      total += fi.ReleasedFederalAmount;
              else if (someOtherCondition)
                  if (someOtherSubCondition)
                      total += fi.ReleasedFederalAmount;
              else if (anotherCondigion)
                  total += fi.ReleasedFederalAmount;
          }
          return total;
      }
      public decimal GetTotalReleasedNonFederalAmountByDate()
      {
          // same logic as above method, 
          // but it accesses fi.ReleasedNonFederalAmount;
      }
      // More methods the same as the previous, just accessing different
      // members of FinancialInfo
  }
  </code></pre>
  
  <p>My goal is to just make one method called GetTotalAmountByDate() and pass in a begin date, and end date and the name of the property (ReleasedFederalAmount or ReleasedLocalAmount, etc.) it needs to access.</p>
  
  <p>I hope this depicts accurately what I'm trying to accomplish.</p>