안녕하세요 나는 방법이 울부 짖는 소리 나열했습니다 : CodeContract.Requires (param! = null)는 param이 null이 아님을 증명하지 못합니까?
public static PasswordCredential Create(string password, string username, string pinCode = null)
{
Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(password), "Invalid Argument: password");
Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(username), "Invalid Argument: username");
PasswordCredential credential = new PasswordCredential();
UTF8Encoding encoder = new UTF8Encoding();
SHA512Managed sha512hasher = new SHA512Managed();
credential.PasswordHash = sha512hasher.ComputeHash(encoder.GetBytes(password)); <-- Requires unproven: s != null
credential.Username = username;
credential.PinCode = pinCode;
return credential;
}
이이 Contract.Requires이 식을 증명하지 않는다는 것을 의미합니까? 그렇다면 그 용도는 무엇입니까? :?
확인
UPDATE, 나는 코드 계약의 매우 이상한 행동을 발견했다. 나는이 방법을 다른 프로젝트로 옮겼다. 더 이상 증명되지 않은 경고가 필요하지 않습니다. 그런 다음 원래 프로젝트로 돌아가서 메시지 창에서 다음 줄을 발견했습니다. 메시지 1 CodeContracts : 제안 된 전제 조건 : Contract.Requires (password! = null); 이 항목을 두 번 클릭하면 PasswordCredential의 PinCode 속성으로 이동합니다.
[DataMember]
public string PinCode
{
get { return _PinCode; }
set { _PinCode = value == null ? null : value.Trim(); } <-- I'm navigated here
}
경고 항목을 클릭하면 encoder.GetBytes (암호) 행으로 이동합니다. 무엇이 잘못되었는지 이해하지 못합니다. 그게 버그 야?
런타임 검사를 사용하도록 설정 했습니까? 이것 없이는 작동하지 않습니다. –
런타임과 정적 모두. 런타임이 가득 참으로 설정되었습니다 – Davita
이걸 재현 할 수 없습니다. 나는 당신의 코드를 복사했고 경고를받지 못했다. "contract.Requires'에'password'를 주석 처리하면 같은 경고가 나타납니다. –