Last active
December 8, 2022 03:21
-
-
Save CorbyO/7d105d2cedf1176c174da7353ed4268b to your computer and use it in GitHub Desktop.
C# GetAllMembers for Type
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
using System; | |
using System.Collections.ObjctModel; | |
using System.Reflection; | |
public static class TypeExtension | |
{ | |
public static ReadOnlyCollection<MemberInfo> GetAllMembers(this Type type, int capacity = 50) | |
{ | |
var temp = new List<MemberInfo>(capacity); | |
for(var t = type; t != null; t = t.BaseType) | |
{ | |
temp.AddRange(t.GetMembers((BindingFlags)(-1))); | |
} | |
return temp.AsReadOnly(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.g. )
output: