How is it possible to get the input parameters of a method by having just a generic delegate?
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?
精彩评论