title: Using generic or nor knowing type of a property in a method
body: <p>I want to write a method that takes two parameters:</p>
  
  <ol>
  <li>string [PropertyName],</li>
  <li>unknown [new propertyValue]  --- could be a string, int, or bool</li>
  </ol>
  
  <p>I am using it to update key values in the <code>web.config</code> app settings keys. So, if I want to update a string value in the settings, e.g. <code>GlobalEmail</code>, I could use the method as so:</p>
  
  <pre><code>UpdateSettingsKeyToNewValue("GlobalEmail", "newAddress@outlook.com");
  </code></pre>
  
  <p>Or I could update a switch like so:</p>
  
  <pre><code>UpdateSettingsKeyToNewValue("IsUserSet", false);
  </code></pre>
  
  <p>How could I go about doing this? The current code is a basic as follows, but not sure how to type check, and then cast correctly, and then apply the new value.</p>
  
  <pre><code>public void UpdateKeyValue(string propertyName, Object newValue)
  {
      Type genericType = typeof(newValue["newValue"]);  //not sure how to get here....
      Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);           
      config.AppSettings.Settings.Remove(propertyName);
      config.AppSettings.Settings.Add(propertyName, newValue);
      config.Save();
  }
  </code></pre>
  
  <p>Thanks in advance!</p>