pardeike / HarmonyRimWorld

A RimWorld mod that installs Harmony for all other mods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to patch a getter in internal class?

QQLQ opened this issue · comments

commented

Greetings, Brrainz, thank you for your last reply and that did huge help.
One thing that I found that is that I was trying to patch a getter in internal class. Use TypeByName and TargetMethod did solve the access to internal class problem, but patching a getter needs annotations like [HarmonyPatch(typeof(....),"somegetter",MethodType.Getter)], by doing so the whole thing cameback to its start----that typeof() does not allow me to access internal class from another assembly.
So anything I could do with that?

You use TargetMethod instead of the annotation (keep an empty annotation on the class so Harmony will consider it). In there you use all the reflection to return the MethodInfo. Properties have a reflection method to get their get_ or set_ methods.