草庐IT

c# - ReSharper 突出显示 nameof 与 "Explicit argument passed to parameter with caller info attribute"的结合使用

coder 2023-07-11 原文

我使用 nameof 函数将属性名称作为字符串获取:

public bool IsRunning => ...;

...
RaisePropertyChanged(nameof(IsRunning));

ReSharper 通过警告突出显示这一点:

Explicit argument passed to parameter with caller info attribute

代码有效,我只是想知道上面的警告是否是我应该担心的事情。

最佳答案

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

当您附加了 CallerMemberName 属性时,您不必显式传递一个值,因为该属性会为您做这些。它会找到调用者的姓名并使用它,使您的 nameof 声明变得多余。这当然是假设您从实际属性实现中调用 RaisePropertyChanged

ReSharper 将这些调用标记为冗余 when you explicitly pass a string literal .它也应该使用 nameof 强制执行相同的逻辑。

关于c# - ReSharper 突出显示 nameof 与 "Explicit argument passed to parameter with caller info attribute"的结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31875261/

有关c# - ReSharper 突出显示 nameof 与 "Explicit argument passed to parameter with caller info attribute"的结合使用的更多相关文章

随机推荐