0

How can I compare an Action with a specific Method?

void MyMethod(string param1, int param2) { }

Action theAction = () => MyMethod(string, int)
MyQueue.Enqueue(theAction)

if (MyQueue.Peek() == MyMethod()) { //Do Thing }

How do I do that last line and have it compile? I dont need to check parameters, just the method itself, but it won't let me do this.

  • Your code won't compile: `MyMethod` has 2 parameters but `Action` requires zero parameters. If you're employing currying (which your example does not) then you must use an anonymous function, which by definition, does not share identity with the function it curries. So the only alternative is to dump the IL bytecode of the delegate's target and look for inner `call` or `callvirt` instructions and map them yourself. If you're trying to employ FP techniques that require _referential transparency_ in C# then prepare for more pain because C#/.NET does not support RT in any way like Haskell does. – Dai Mar 29 '22 at 02:03
  • Have you seen this? https://stackoverflow.com/questions/30898428/comparing-delegates-in-c-sharp – Dai Mar 29 '22 at 02:09
  • Or this? https://stackoverflow.com/questions/6701041/compare-delegates-actiont – Dai Mar 29 '22 at 02:10

0 Answers0