DbProviderFactory.CreateCommandBuilder 实际上 return 可以为 null 吗?
Can the DbProviderFactory.CreateCommandBuilder actually return a null?
我使用以下模式来清理数据库名称:
var dbProviderFactory = DbProviderFactories.GetFactory(connection);
using (var commandBuilder = dbProviderFactory.CreateCommandBuilder())
{
var fooSafe = commandBuilder.QuoteIdentifier(foo)
}
但每次我这样做时 R# 都会抱怨 commandBuilder
并说
Possible System.NullReference exception.
为了摆脱这个警告,我通常把
Debug.Assert(commandBuilder != null);
创建命令生成器后。
我主要使用 SqlConnection
或 SQLiteConnection
。
documentation中没有太多内容,只是说:
Returns a new instance of the provider's class that implements the DbCommandBuilder class.
我不确定是否应该检查命令生成器是否为 null 或忽略警告?
因为文档说它将 return 一个 "new instance" 我不担心 null 检查。
Resharper 抱怨可能是因为它是一个虚拟方法,任何自定义实现都可能 return null。
我使用以下模式来清理数据库名称:
var dbProviderFactory = DbProviderFactories.GetFactory(connection);
using (var commandBuilder = dbProviderFactory.CreateCommandBuilder())
{
var fooSafe = commandBuilder.QuoteIdentifier(foo)
}
但每次我这样做时 R# 都会抱怨 commandBuilder
并说
Possible System.NullReference exception.
为了摆脱这个警告,我通常把
Debug.Assert(commandBuilder != null);
创建命令生成器后。
我主要使用 SqlConnection
或 SQLiteConnection
。
documentation中没有太多内容,只是说:
Returns a new instance of the provider's class that implements the DbCommandBuilder class.
我不确定是否应该检查命令生成器是否为 null 或忽略警告?
因为文档说它将 return 一个 "new instance" 我不担心 null 检查。
Resharper 抱怨可能是因为它是一个虚拟方法,任何自定义实现都可能 return null。