Get the name of a method using an expression

后端 未结 6 1162
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 12:03

I know there are a few answers on the site on this and i apologize if this is in any way duplicate, but all of the ones I found does not do what I am trying to do.

I

6条回答
  •  孤城傲影
    2020-11-28 12:16

    The problem with this is that x.DoSomething represents a method group. And you have to somehow explicitly specify what delegate type do you want to convert that method group into, so that the correct member of the group can be selected. And it doesn't matter if that group contains only one member.

    The compiler could infer that you mean that one, but it doesn't do that. (I think it's this way so that your code won't break if you add another overload of that method.)

    Snowbear's answer contains good advice on possible solutions.

提交回复
热议问题