Tell Resharper that lambda argument is not null

I have a way like this:

void Foo(object x, Action<object> f) {
    if (x != null)
        f (x);
}

And I would like to use it as follows:

void Bar () {
    Foo ("baz", g => g.ToString());
    Foo (null, g => g.ToString());
}

But Resharper complains that g in lambdas may be null. Is it possible to annotate a method to tell Resharper that g will never be null?

+4
source share
1 answer

Using ReSharper, when you are on a line that can be improved, a yellow light should appear to the left of the code editor, if you click it, the “Inspection: ...” option will appear, click it, and then click Disable once with comment, a comment like:

// ReSharper disconnects once ...

. : " " . , .

EDIT: , ReSharper 9, .

0

All Articles