Skip to content
Bannerlord Wiki
Share
Explore
C#

Get Private Fields

private FieldInfo GetPrivateField(object target, string fieldname)
{
Type type = target.GetType();
while (type != null)
{
FieldInfo field = type.GetField(fieldname, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
return field;
}
type = type.BaseType;
}
throw new Exception("Error 50");
}

FieldInfo privateField = this.GetPrivateField(missionScreen, "_missionState");
MissionState missionState = (MissionState)privateField.GetValue(missionScreen);
missionState.Paused = this.isPaused;
private FieldInfo GetPrivateField(object target, string fieldname)
{
Type type = target.GetType();
while (type != null)
{
FieldInfo field = type.GetField(fieldname, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
return field;
}
type = type.BaseType;
}
throw new Exception("Error 50");
}

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.