Can I get the signature of a C# delegate by its type?

2,577
    MethodInfo method = delegateType.GetMethod("Invoke");
    Console.WriteLine(method.ReturnType.Name + " (ret)");
    foreach (ParameterInfo param in method.GetParameters()) { 
        Console.WriteLine("{0} {1}", param.ParameterType.Name, param.Name);
    }
Share:
2,577
qqqwww
Author by

qqqwww

Updated on June 23, 2022

Comments

  • qqqwww
    qqqwww almost 2 years

    Python question:

    print(sum(range(5),-1)) 
    from numpy import * 
    print(sum(range(5),-1))
    
    9
    10
    

    What is logical behind it? Thank you

    • Carcigenicate
      Carcigenicate about 7 years
      Numpy must be redefining range, and it has different boundry rules.
    • jkr
      jkr about 7 years
      The first line is equivalent to 0+1+2+3+4+(-1). The third line is equivalent to 0+1+2+3+4 on axis=-1. Use import numpy as np and then rewrite the third line as np.sum(range(5),-1). And read the documentation for np.sum()
    • jkr
      jkr about 7 years
      Numpy does not redefine range. The second argument in np.sum() is axis. It will only sum the items in the first argument.
    • Carcigenicate
      Carcigenicate about 7 years
      Ahh, my bad. Shot in the dark. I didn't think a summing function could have different behavior.
  • miradulo
    miradulo about 7 years
    It's not so important, but sum doesn't add the start value at the end of the operation - it rather starts with the start value which defaults to 0, and adds the sequence to it. Like in CPython here.