Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2016 03:05
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 anonymous/aeab3b4f95e6efc0d7130cf91a773bfb to your computer and use it in GitHub Desktop.
Save anonymous/aeab3b4f95e6efc0d7130cf91a773bfb to your computer and use it in GitHub Desktop.
A C# method that recursively flattens a type into a list of basic properties
public static IEnumerable<PropertyInfo> FlattenType(Type type)
{
var properties = type.GetProperties();
foreach (PropertyInfo info in properties)
{
if (info.PropertyType.Assembly.GetName().Name == "mscorlib")
{
yield return info;
}
else
{
foreach (var childInfo in FlattenType(info.PropertyType))
{
yield return childInfo;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment