ReSharper là đủ thông minh để biết rằng một string.Format
đòi hỏi một không null format
luận nên nó cảnh báo tôi về điều đó khi tôi chỉ đơn giản là viếtTôi có thể dạy ReSharper một kiểm tra null tùy chỉnh không?
_message = string.Format(messageFormat, args);
nơi messageFormat
thực sự có thể được null. Ngay sau khi tôi thêm điều kiện cho biến này:
if (!string.IsNullOrEmpty(messageFormat))
{
_message = string.Format(messageFormat, args);
}
cảnh báo biến mất. Unfortunatelly nó không khi tôi sử dụng một phương pháp khuyến nông:
if (messageFormat.IsNotNullOrEmpty())
{
_message = string.Format(messageFormat, args); // possible 'null' assignment warning
}
Câu hỏi của tôi là: là có một cách để dạy ReSharper rằng phương pháp khuyến nông của tôi có ý nghĩa tương tự như !string.IsNullOrEmpty(messageFormat)
?
Việc gia hạn được định nghĩa là:
public static bool IsNotNullOrEmpty([CanBeNull] this string value) => !IsNullOrEmpty(value);
Liệu công việc này? '' chuỗi tĩnh EmptyIfNull (chuỗi này) { chuỗi trả về.IsNullOrEmpty (s)? "": s; } '' rồi '' _message = string.Format (messageFormat.EmptyIfNull(), args); '' – dumetrulo