Last active
December 22, 2015 00:28
-
-
Save jmhdez/6389001 to your computer and use it in GitHub Desktop.
Extension Method para convertir un objeto anónimo en un IDictinary
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
public static class Extensions | |
{ | |
public IDictionary<string, object> AsDict(this object obj) | |
{ | |
return obj.GetType().GetProperties().ToDictionary(x => x.Name, x => x.GetValue(obj, null)) | |
} | |
} | |
var obj = new { Name = "Lucas", Age = 14 }.AsDict(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment