Ludeon Forums

Ludeon Forums

  • June 19, 2021, 05:45:04 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How to call an internal/private method of a class and use it's returned values?  (Read 104 times)


  • Muffalo
  • *
  • Posts: 10
  • Refugee
    • View Profile

I solved it, solution for the future on the botton

I have a Pawn_DraftController instance __instance.drafter that has an internal method __instance.drafter.GetGizmos() which does several things and yields an IEnumerable<Gizmo>.

I searched in the forums and found that I could use


but I want to call the method and not get a private value.

Thanks in advance.


I tried to

IEnumerable<Gizmo> gizmos_drafter = Traverse.Create(__instance.drafter).Method("GetGizmos", null).GetValue<IEnumerable<Gizmo>>();

I think it didn't work


I managed to get something working

var getGizmosMethod = __instance.drafter.GetType().GetMethod("GetGizmos", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

IEnumerable<Gizmo> gizmos_drafter = (IEnumerable<Gizmo>) getGizmosMethod.Invoke(__instance.drafter, null);
« Last Edit: May 07, 2021, 12:22:58 PM by arkyte »