Created
December 27, 2016 21:52
-
-
Save camarin24/1a4dc869cd687b25d954ea0d2f288988 to your computer and use it in GitHub Desktop.
Reflection Extension Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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