jeudi 1 avril 2021

How to get a method's parameter values from within the method using reflection?

I have hundreds of functions, each with different names and parameters. Every time a function is called, I need to log the method name, the parameter names and the values which the client passes in via the parameters. But I don't want to write the logging code for every function. It takes a long time, and every time a function's parameters are changed the logging code needs to change too.

So I hope I can write one block of code, and insert it into the beginning of every function. This block of code uses reflection to get the method name, names of the parameters, and most importantly, the values passed into the function via the parameters.

How do I do that?





Aucun commentaire:

Enregistrer un commentaire