title: Sum up all the properties of a collection and dynamically assigned it to another object
body: <p>I have a collection of object in <code>lst</code> of type <code>DataResponse</code> and what I would like to do is sum up all the properties that are <code>int</code> and <code>decimal</code> of this collection and assign the result of each property to another object <code>DataContainerResponse</code> that has the same exact property names(and types) as the those that are being summed up.  </p>
  
  <p>I can do this manually by typing out each property by hand and do a <code>.Sum(s=&gt;s.&lt;propertyname&gt;</code>.  But that so 90s.  Below is my fruitless attempt to juice it out.   Frankly, I never assigned a var to a lambda expression before and I don't even know if it's possible <code>.Sum(s=&gt;&lt;var name&gt;)</code>;</p>
  
  <pre><code> public DataAggragationResponse doAggregation(List&lt;DataResponse&gt; lst)
      {
          if (lst.Count == 0)
              return null;
          DataContainerResponse rd = new DataContainerResponse();
  
          //If I do it manually typing each prop by hand.
          rd.VIOL = lst.Sum(s =&gt; s.VIOL);
  
  
          //Automation!!!
          foreach (PropertyInfo propertyInfo in typeof(DataResponse).GetProperties())
          {
  
                  rd.GetType().GetProperties().SetValue(lst.Sum(s =&gt; propertyInfo.Name[0]));
  
          }
      }
  </code></pre>