Created
August 11, 2014 01:13
-
-
Save RyuaNerin/ba211255d514ea004ff3 to your computer and use it in GitHub Desktop.
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
// | |
// net { A = "B", C = 1, D = 0.22 } | |
// => Dictionary<string, object> | |
// | |
public static IDictionary<string, object> PropertyToDictionary(object values) | |
{ | |
try | |
{ | |
Dictionary<string, object> dic = new Dictionary<string, object>(); | |
foreach (PropertyInfo p in values.GetType().GetProperties()) | |
{ | |
if (!p.CanRead) continue; | |
dic.Add(Convert.ToString(p.Name), p.GetValue(values, null)); | |
} | |
return dic; | |
} | |
catch | |
{ | |
throw new FormatException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment