SqlCommand.ExecuteReader()
메서드를 호출 할 때 ReSharper는 나중에 SqlDataReader 개체를 사용할 때 가능한 NullReference 예외가 있음을 알립니다. 다음 코드로SqlCommand.ExecuteReader()는 언제 null을 반환합니까?
그래서이 :
using (SqlConnection connection = GetConnection())
{
using (SqlCommand cmd = connection.CreateCommand())
{
cmd.CommandText = ; //snip
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
//snip
}
}
}
}
while (reader.Read())
라인은 밑줄이 그어집니다.
제 질문은 독자 객체가 언제 null인지 궁금합니다. 나는 그것을 가로 질러 본 적이 없으며 문서에 그것이있을 수 있음을 언급하지 않았다. null인지 또는 무시하는 것이 안전한지 확인해야합니까?
ReSharper는 null이 될 수 있다고 생각하는 이유는 무엇입니까? 예를 들어 SqlCommand를 null로 검사하지 말고 사용할 수 있습니까? ExecuteReader 메서드에 특성이있는 것 같습니다.