Skip to content

Instantly share code, notes, and snippets.

@camarin24
Created December 27, 2016 21:52
Show Gist options
  • Save camarin24/1a4dc869cd687b25d954ea0d2f288988 to your computer and use it in GitHub Desktop.
Save camarin24/1a4dc869cd687b25d954ea0d2f288988 to your computer and use it in GitHub Desktop.
Reflection Extension Method
private T DeserializeYahooRequest<T>(string response) where T : class, new()
{
T model = new T();
string[] parameters = response.Split('&');
foreach (var item in parameters)
{
var elem = item.Split('=');
PropertyInfo propertyInfo = model.GetType().GetProperty(elem[0]);
propertyInfo.SetValue(model, Convert.ChangeType(elem[1], propertyInfo.PropertyType), null);
}
return model;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment