0

This is function which checks which delegate should be bound to which method: Description is here

private static bool IsEquivalent(Delegate d, MethodInfo method)
 {
  var dm = d.Method;
  if (!method.ReturnType.IsAssignableFrom(dm.ReturnType))
      return false;
  var parameters = method.GetParameters();
  var dp = dm.GetParameters();
  if (parameters.Length != dp.Length)
      return false;
  for (int i = 0; i < parameters.Length; i++)
  {
      //BUG: does not take into account modifiers (like out, ref...)
      if (!parameters[i].ParameterType.IsAssignableFrom(dp[i].ParameterType))
          return false;
  }
  return true;

}

Here it checks that method return type and method parameters type are same as the one of the function, which is pointed by delegate. But what if there would be more than one function with the same parameter types? How can we deal in that case? Is it possible to read the function name, which some delegate points to it?

Simon
  • 1,955
  • 5
  • 35
  • 49

1 Answers1

0

Delegates actually does not have name property. The better way as I have done in my adoption of this code in my project, is to have class which contains passed delegates as its methods. In this way you can pass an instance of that class instead of all those delegate parameters and compare name of the methods of class with the invocation method name.

Polymorphic
  • 420
  • 3
  • 14