Created
September 16, 2016 03:05
-
-
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
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 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