Tell Resharper that a lambda argument is not null

min*_*ill 5 c# resharper lambda

I have a method like this:

void Foo(object x, Action<object> f) {
    if (x != null)
        f (x);
}
Run Code Online (Sandbox Code Playgroud)

And I would like to use it like this:

void Bar () {
    Foo ("baz", g => g.ToString());
    Foo (null, g => g.ToString());
}
Run Code Online (Sandbox Code Playgroud)

But Resharper is complaining that the g in the lambdas might be null. Is it possibile to annotate the method to tell Resharper that g will never be null?

The*_*ulo -1

使用ReSharper,当您在可以改进的行上时,代码编辑器的左侧应该出现一个黄色灯泡,如果单击它,则会出现一个“检查:...”选项,单击它,然后点击Disable once with comment,评论如:

// ReSharper 禁用一次...

应出现在该行之前。您可以找到一种困难的方法来明确告诉“它不会为空”,或者只是让它忽略该问题。我希望它有帮助。

编辑:我想说我使用许可的 ReSharper 9,只是为了指定。