title: C# - Send type as parameter and return a type based on it
body: <p>I have a function that receive a dynamic object and a type as string.
  I would like to cast the object to the type I have in my string.</p>
  
  <pre><code> public void PostAutomaticRule(dynamic automaticRuleObject, string ruleType)
          {
              switch (ruleType)
              {
                  case "Increase_budget":
                      ConvertToAutomaticRule(typeof(IncreaseBudgetRule), ref automaticRuleObject);
                      break;
              }
          }
  
  
   private void ConvertToAutomaticRule&lt;T&gt;(Type type, ref dynamic ruleObject)
          {
              var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
              var json = serializer.Serialize(ruleObject);
              var c = serializer.Deserialize&lt;type&gt;(json);
          }
  </code></pre>
  
  <p>The class I am trying to convert to:</p>
  
  <pre><code> public class IncreaseBudgetRule
      {
          public string automaticRuleName { get; set; }
          public string givePrioity { get; set; }
      }
  </code></pre>
  
  <p>I have many rules types so I want that function to receive a type and a object and will return an object of the type I sent in the function.
  How can I accomplish that?</p>