Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper highlights use of nameof with "Explicit argument passed to parameter with caller info attribute"

I'm using the nameof function to get a property name as a string thus:

public bool IsRunning => ...;

...
RaisePropertyChanged(nameof(IsRunning));

ReSharper highlights this with the warning:

Explicit argument passed to parameter with caller info attribute

The code works, I was just wondering if the above warning is something I should worry about.

like image 836
Tim Rutter Avatar asked Aug 07 '15 10:08

Tim Rutter


2 Answers

was just wondering if the above warning is something I should worry about.

When you have CallerMemberName attribute attached, you don't have to explicitly pass a value, because the attribute will do exactly that for you. It will find the caller's name and use it, making your nameof declaration redundant. This is of course assuming you call RaisePropertyChanged from the actual property implementation.

ReSharper marks these calls as redundant when you explicitly pass a string literal. It should force the same logic with nameof as well.

like image 189
Yuval Itzchakov Avatar answered Nov 12 '22 09:11

Yuval Itzchakov


Not as long as your code is called from the IsRunning property (which makes the warning valid. Specifying the property name would be redundant in that case). It doesn't seem you are doing that.

The warning just tells you that the RaisePropertyChanged has the CallerMemberNameAttribute set on the property, which it should. It is safe to ignore.

like image 41
Patrick Hofman Avatar answered Nov 12 '22 07:11

Patrick Hofman