title: Get and Set values of properties generic type
body: <p>I am actually struggling with generics :)</p>
  
  <p>How can I access properties of a type passed as generic into a method? Do I need to use reflection in any case?</p>
  
  <p>For example the following class</p>
  
  <pre><code>public class someClassA()
  {
      public int attributeA1;
      public string attributeA2;
  {
  
  public class someClassB()
  {
  public int attributeB1;
  public string attributeB2;
  {
  
  
  // Then a generic method
  private TItem GetSomeData&lt;TItem&gt;(Guid Id) where TItem: new()
      {
          TItem instanceOfClass = new TItem();
          // doing some data stuff
          // ....
          // finally group the result for better iteration
          var groupedById = result.ToList().GroupBy(x =&gt;
                                  (x["SomeId"]))
                                  .Select(grp =&gt; grp.ToList())
                                  .ToList();
  
          foreach (var item in groupedById)
          {
              // how can I access and set the properties of TItem -&gt; instanceOfClass?
              instanceOfClass.... = item.property1;
              instanceOfClass.... = item.property2;
              ....
          }
  
          return instanceOfClass;
      }
  </code></pre>
  
  <p>The above method is called like this for example</p>
  
  <pre><code>var data = GetSomeData&lt;someClassA&gt;(someId)
  </code></pre>
  
  <p>Any hint or advice is higly appreciated!</p>
  
  <p>I have already tried with reflection but I am unsure wether this is usefull or not.</p>