Skip to content

Instantly share code, notes, and snippets.

@mikewlange
Created May 16, 2017 19:55
Show Gist options
  • Save mikewlange/9a4020a286e1e6dd56a5afb54349ac99 to your computer and use it in GitHub Desktop.
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.
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