开发者

How is it possible to get the input parameters of a method by having just a generic delegate?

开发者 https://www.devze.com 2023-03-24 09:40 出处:网络
string CreateCacheKey(delegate methodDelegate) { // return cache key based on the input parameters of the method passed to this
string CreateCacheKey(delegate methodDelegate)
{
 // return cache key based on the input parameters of the method passed to this
}

User[] GetAll(short id, string name)
{
  CreateCacheKey (this.GetAll);
}

How is i开发者_JAVA百科t possible to get the input parameters of a method by having just a generic delegate?

I think the only option should be reflection.

Thanks,


A delegate has a .Method (assuming it is a single delegate, not composite - you may need to call GetInvocationList).

From the method you can query GetParameters().


Rather than a regular delegate, could you specify a delegate with fixed parameters, or use a generic delegate type (GetAllHandler<T>)?

Could you explain a little more about what CreateCacheKey is doing and why? Perhaps a real-world example?

0

精彩评论

暂无评论...
验证码 换一张
取 消