How to check if a variable of type Func<...> is a specific class method

339 Views Asked by At

I would like to check in runtime that a variable of type Func<...> is a specific class method. E.g.

class Foo
{
    public static int MyMethod(int a, int b)
    {
        //...
    }
}

Func<int, int, int> myFunc;
myFunc = Foo.MyMethod;

if(myFunc is Foo.MyMethod)
{
    //do something
}
1

There are 1 best solutions below

3
On BEST ANSWER

You should be able to compare the two directly using ==:

if (myFunc == Foo.MyMethod) { ... }