는 어설 션과 코드의 가독성이 아닌 코드 중복은 여러 곳에서 나는 그렇게 같은 동일한 조건에 대해 확인하는 Debug.Assert
사용 : 실제 목록 있지만,Debug.Assert-s가 동일한 오류 메시지를 사용합니다. 이 변수를 정적 변수로 승격시켜야합니까? 내가 사랑하는
Debug.Assert(kosherBaconList.SelectedIndex != -1, "An error message along the lines - you should not ever be able to click on edit button without selecting a kosher bacon first.");
이 실제 버그에 대한 응답입니다 정결 한 베이컨을 포함하지 않습니다. 어쨌든, 나는 두 가지 방법을 생각할 수 있습니다
private static readonly mustSelectKosherBaconBeforeEditAssertMessage =
"An error message along the lines - you should not ever be able to " +
"click on edit button without selecting a something first.";
...
Debug.Assert(
kosherBaconList.SelectedIndex != -1,
mustSelectKosherBaconBeforeEditAssertMessage)
또는 :
if (kosherBaconList.SelectedIndex == -1)
{
AssertMustSelectKosherBaconBeforeEdit();
}
...
[Conditional("DEBUG")]
private void AssertMustSelectKosherBaconBeforeEdit()
{
// Compiler will optimize away this variable.
string errorMessage =
"An error message along the lines - you should not ever be able to " +
"click on edit button without selecting a something first.";
Debug.Assert(false, errorMessage);
}
이상 둘 중 하나보다 짜증 세 번째 방법이? 공유하십시오. 일반적인 유용한 정보도 환영합니다.
는 제목에서 "C 번호"와 같은 태그를 보관하십시오. 태그에 남겨주세요. –