ReSharper가이 코드에 대해 나를 판단하는 이유는 무엇입니까?
    private Control GetCorrespondingInputControl(SupportedType supportedType, object settingValue)
    {
        this.ValidateCorrespondingValueType(supportedType, settingValue);
        switch(supportedType)
        {
            case SupportedType.String:
                return new TextBox { Text = (string)settingValue };
            case SupportedType.DateTime:
                return new MonthPicker { Value = (DateTime)settingValue, ShowUpDown = true };
            default:
                throw new ArgumentOutOfRangeException(string.Format("The supported type value, {0} has no corresponding user control defined.", supportedType));
        }
    }
    private void ValidateCorrespondingValueType(SupportedType supportedType, object settingValue)
    {
        Type type;
        switch(supportedType)
        {
            case SupportedType.String:
                type = typeof(string);
                break;
            case SupportedType.DateTime:
                type = typeof(DateTime);
                break;
            default:
                throw new ArgumentOutOfRangeException(string.Format("The supported type value, {0} has no corresponding Type defined.", supportedType));
        }
        string exceptionMessage = string.Format("The specified setting value is not assignable to the supported type, [{0}].", supportedType);
        if(settingValue.GetType() != type)
        {
            throw new InvalidOperationException(exceptionMessage);
        }
    }두 번째 메서드 ValidateCorrespondingValueType의 “settingValue”매개 변수는 ReSharper에서 다음 메시지와 함께 회색으로 표시됩니다. “Parameter ‘settingValue’는 사전 조건 검사에만 사용됩니다.”
답변
판단하는 것이 아니라 도움을 주려는 것입니다. 🙂
ReSharper에서 매개 변수가 예외를 발생시키기위한 검사로만 사용되는 것을 확인하면이를 회색으로 표시하여 실제로 “실제”작업에 사용하고 있지 않음을 나타냅니다. 이것은 실수 일 가능성이 큽니다. 사용하지 않을 매개 변수를 전달하는 이유는 무엇입니까? 일반적으로 사전 조건에서 사용했지만 코드의 다른 곳에서 사용하는 것을 잊었거나 더 이상 사용할 필요가 없음을 나타냅니다.
메서드가 어설 션 메서드이므로 (즉, 유효하다고 ValidateCorrespondingValueType어설 션하는 것뿐입니다) ReSharper의 주석 속성 , 특히 속성을 사용하여을 어설 션 메서드로 표시하여 메시지를 억제 할 수 있습니다 [AssertionMethod].
[AssertionMethod]
private void ValidateCorrespondingValueType(SupportedType supportedType, object settingValue)
{
  // …
}답변
흥미롭게도 ReSharper nameof는 C # 6 의 새로운 기능 을 사용하면 백 오프됩니다 .
static void CheckForNullParameters(IExecutor executor, ILogger logger)
{
    if (executor == null)
    {
        throw new ArgumentNullException(nameof(executor));
    }
    if (logger == null)
    {
        throw new ArgumentNullException(nameof(logger));
    }
}답변
다음은 문제를 해결하지만 (ReSharper 2016.1.1, VS2015에서) ‘올바른’문제가 해결되는지 확실하지 않습니다. 어쨌든이 주제와 관련하여 ReSharper의 메커니즘이 모호함을 보여줍니다.
그러면 다음과 같은 경고가 표시됩니다.
    private void CheckForNull(object obj)
    {
        if (ReferenceEquals(obj, null))
        {
            throw new Exception();
        }
    }그러나 이것은 그렇지 않습니다.
    private void CheckForNull(object obj)
    {
        if (!ReferenceEquals(obj, null))
        {
            return;
        }
        throw new Exception();
    }동등한 코드 (ReSharper : D에 의해 반전이 수행됨)가 다른 결과를 제공한다는 것은 흥미 롭습니다. 패턴 매칭은 단순히 두 번째 버전을 선택하지 않는 것 같습니다.
답변
이 문제에 대한 내가 선호하는 해결책은 매개 변수 가 사용 되었다고 생각하게 만드는 것 입니다. 이 같은 속성을 사용을 통해 장점을 가지고 UsedImplicitly당신이 이제까지 경우 때문에   할 정류장이 매개 변수를 사용하여, ReSharper에서 당신을 다시 경고를 시작합니다. 속성을 사용하는 경우 resharper는 향후 실제 경고도 포착하지 않습니다.
resharper가 매개 변수가 사용되었다고 생각하게 만드는 쉬운 방법 throw은 메소드 로 대체 하는 것입니다. 그래서 대신 …
if(myPreconditionParam == wrong)
    throw new Exception(...);…당신은 쓰기:
if(myPreconditionParam == wrong)
    new Exception(...).ThrowPreconditionViolation();이것은 미래의 프로그래머를 위해 훌륭하게 자체 문서화되며 resharper는 징징 대는 것을 그만 둡니다.
ThrowPreconditionViolation의 구현은 간단합니다.
public static class WorkAroundResharperBugs
{
    //NOT [Pure] so resharper shuts up; the aim of this method is to make resharper 
    //shut up about "Parameter 'Foobaar' is used only for precondition checks" 
    //optionally: [DebuggerHidden]
    public static void ThrowPreconditionViolation(this Exception e)
    {
        throw e;
    }
}Exception의 확장 메서드 는 네임 스페이스 오염이지만 상당히 포함되어 있습니다.
답변
다른 사람들은 이미 질문에 대답했지만 아무도 경고를 끄는 다음과 같은 방법을 언급하지 않았습니다.
해당 메서드에 대해서만 해제하려면 메서드 서명 위에 이것을 추가합니다.
    // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local전체 파일에 대해 해제하려면 클래스 선언 위에 이것을 추가하십시오.
     // ReSharper disable ParameterOnlyUsedForPreconditionCheck.Local답변
