使用反射来获取方法名称和参数 [英] Using reflection to get method name and parameters
本文介绍了使用反射来获取方法名称和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想锻炼的方式来编程方式创建一个关键 Memcached的的基础上,方法名称和参数。所以,如果我有一个方法,
I am trying to workout a way to programatically create a key for Memcached, based on the method name and parameters. So if I have a method,
string GetName(int param1, int param2);
这将返回:
string key = "GetName(1,2)";
我知道你可以使用反射获得MethodBase,但我如何才能在字符串中的参数值,而不是参数类型?
I know you can get the MethodBase using reflection, but how do I get the parameters values in the string, not the parameter types?
推荐答案
您正在寻找的是一个拦截器。就像它的名字说,拦截器拦截方法调用,并允许您之前的方法被调用后执行的东西。这是许多缓存和日志框架很受欢迎。
What you're looking for is an interceptor. Like the name says, an interceptor intercepts a method invocation and allows you to perform things before and after a method is called. This is quite popular in many caching and logging frameworks.
这篇关于使用反射来获取方法名称和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文