Skip to content

Instantly share code, notes, and snippets.

@jmhdez
Last active December 22, 2015 00:28
Show Gist options
  • Save jmhdez/6389001 to your computer and use it in GitHub Desktop.
Save jmhdez/6389001 to your computer and use it in GitHub Desktop.
Extension Method para convertir un objeto anónimo en un IDictinary
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