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.
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
Post a Comment