title: GetValue of PropertieInfo throws TargetParameterCountException (System.Reflection)
body: <p>I mistakenly posted this question already at the <a href="https://sharepoint.stackexchange.com/questions/177826/getvalue-of-propertieinfo-throws-targetparametercountexception-system-reflectio">SharePoint</a> part.</p>
  
  <p>I need to map one model onto an other. Everything works well but the last property throws a TargetParameterCountException. The property which throws the exception is called "Item" this property is not defined by me, I assume that this is a property from the dictionary.</p>
  
  <p>I already tried to use all five parameters instead of only one (as described here <a href="https://stackoverflow.com/questions/7714551/moq-unit-testing-system-reflection-targetparametercountexception-parameter">Moq + Unit Testing - System.Reflection.TargetParameterCountException: Parameter count mismatch</a>) but unfortunately i will get the same exception. I would really appreciate it if someone could help me.</p>
  
  <p>Kinde Regards and Thanks</p>
  
  <p>Sandro</p>
  
  <p>That is a excerpt of the Source Model, all other properties are implemented in exactly the same way:</p>
  
  <pre><code>public class DataModel : Dictionary&lt;string, object&gt; {}
  public class DiscussionDataModel : DataModel
  {
    public DiscussionDataModel(Dictionary dictionary) : base(dictionary){}
  
    public FieldUserValue Author
    {
      get { return (FieldUserValue) this["Author"]; }
      set { this["Author"] = value; }
    }
  
    public double AverageRating
    {
      get { return (double) this["AverageRating"]; }
      set { this["AverageRating"] = value; }
    }
  }
  </code></pre>
  
  <p>And that is a excerpt the target Model, all other properties are implemented in exactly the same way: </p>
  
  <pre><code>public class DiscussionModel : BaseModel
  {
    public FieldUserValue Author { get; set; }
    public double AverageRating { get; set; }
  }
  </code></pre>
  
  <p>And this is the generic extension method to map the DataModel onto the BaseModel: </p>
  
  <pre><code>public static T ToModel(this DataModel dataModel) where T : BaseModel
  {
    try
    {
      T model = Activator.CreateInstance();
      if (dataModel != null)
      {
        PropertyInfo[] propertyInfos = dataModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
  
        foreach (PropertyInfo propertyInfo in propertyInfos)
        {
          object value = propertyInfo.GetValue(dataModel);
          if (value == null) { break; }
          PropertyInfo modelPropertyInfo = model.GetType().GetProperty(propertyInfo.Name);
          modelPropertyInfo?.SetValue(model, value);
        }
        return model;
      }
    }
    catch (Exception ex)
    {
      throw;
    }
    return null;
  }
  </code></pre>