title: How to convert a model to it's viewmodel based on model name
body: <p>I am trying to figure out something that I am not sure if it is possible.  My goal is that I have an extension method called convertToPersonModel that copies my PersonViewModel to the PersonModel.  Is it possible that I can change the parameters to accept any ViewModel and convert it to it's normal model.  For instance, I could pass in the EmployeeViewModel to be converted to EmployeeModel, or RoleViewModel to the RoleModel all in one method.</p>
  
  <p>This is my extension method:</p>
  
  <pre><code>public static PersonModel ConvertToPersonModel(this PersonViewModel viewModel) 
  {
  
      var model = new Product(){
          FirstName = viewModel.FirstName;
          LastName = viewModel.LastName;
      }
    return model;
  }
  </code></pre>
  
  <p>So the goal would be to be able to pass in any view model and figure out the properties of the relevant model (which properties the normal model has) and assign those values depending on which viewmodel/model pair it is.  This may be confusing, let me know if you need more clarification.</p>
  
  <p>Somethings like:</p>
  
  <pre><code>public static Model ConvertToModel(this ViewModel viewModel) 
  {
      var model = new findWhichModelisRelatesToViewModel(){
          1stproperty = viewModel.relevantProperty;
          2ndproperty = viewModel.relevantProperty;
      }
    return model;
  }
  </code></pre>
  
  <p>With Model being the model that correlates to the sent in view model.</p>