Created
May 16, 2017 19:55
-
-
Save mikewlange/9a4020a286e1e6dd56a5afb54349ac99 to your computer and use it in GitHub Desktop.
This is how you access necessary private fields in closed source libraries without having to decompile and recode their spaghetti.
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 T GetPrField<T>(this object obj, string name) | |
{ | |
BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic; | |
Type type = obj.GetType(); | |
FieldInfo field = type.GetField(name, flags); | |
return (T)field.GetValue(obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment