Skip to content

Instantly share code, notes, and snippets.

@wolf99
Last active May 5, 2017 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolf99/502a1e1ec0c98d3aacfd9abc1de628a2 to your computer and use it in GitHub Desktop.
Save wolf99/502a1e1ec0c98d3aacfd9abc1de628a2 to your computer and use it in GitHub Desktop.
C# function to get a Dictionary of the names and values of the properties of a given object
using System.Reflection
public class Gists
{
public Dictionary<string, object> GetDictionaryOfProperties(o As Object)
{
Dictionary<string,string> Properties;
Properties = (from x in o.GetType().GetProperties() select x).ToDictionary
( x => x.Name, x => x.GetGetMethod().Invoke (o, null));
return Properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment