c# - Do Resharper NotNull attributes work on Extension Methods? -


we using extension methods to, instance, return empty list if list null clean code bit. simplified example included below.

the method unfortunately still triggers warning resharper. using notnull attribute works in cases, not when using method extension method.

code example. image include squiggly lines resharper.

i included screenshot show squiggly lines. notice blue squiggly line. notice how notnull attribute supposed when method not called extension method, not when used way. able call method extension method.

is not possible? there other attribute can use?

(the green squiggly line complaining fact calling method extension method.)

it's because use ? (null-conditional) operator, doesn't chain - shortcircuit statement if input null. thus, if input null, list evaluate null , list.count throw nullreference-exception.

you can wrap entire thing in parenthesis, like

var list = (input?.list).emptyifnull(); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -