How to access and modify function expression from field?

I’m trying to write a macro which modifies all functions/methods from all compiled classes to inject custom code into them, but I am unable to find a way to even access the Function expression via the field.kind property like how you would do with matching and FVar.

var fields:Array<ClassField> = classType.fields.get();
for (i in 0...fields.length)
{
	var field:ClassField = fields[i];
	switch(field.kind)
	{
		case FieldKind.FMethod(f):
			// `f` only represents the function "kind", it doesn't give any info about the function itself
			// how can i modify the function code here???

		//case FFun(f):   <- can't get function info like this
		//case FVar(t,_)  <- but you can for variables?? why?
		default:
	}
}

You’d have to do this as a build macro. Type Building - Haxe - The Cross-platform Toolkit

Same with FVar, actually. The FVar you get from ClassField is not the same FVar that lets you make modifications.

I see, but is there no way of making this process automatic? I don’t want to have to put a build metadata on every single class in the source code of my game.

You can use --macro addGlobalMetadata('', '@:build(your.Macro.here())) to apply it to all classes - note that this will affect the stdlib too. You can avoid that by using a more restrictive pathFilter, like for example just the root package of your game, if you have one.