{
protected DbProviderFactory() { }
public virtual bool CanCreateDataSourceEnumerator { get { throw null; } }
+ public virtual bool CanCreateDataAdapter { get { throw null; } }
+ public virtual bool CanCreateCommandBuilder { get { throw null; } }
public virtual System.Data.Common.DbCommand CreateCommand() { throw null; }
public virtual System.Data.Common.DbCommandBuilder CreateCommandBuilder() { throw null; }
public virtual System.Data.Common.DbConnection CreateConnection() { throw null; }
{
public abstract partial class DbProviderFactory
{
+ private bool? _canCreateDataAdapter;
+ private bool? _canCreateCommandBuilder;
+
protected DbProviderFactory() { }
public virtual bool CanCreateDataSourceEnumerator => false;
+ public virtual bool CanCreateDataAdapter
+ {
+ get
+ {
+ if (!_canCreateDataAdapter.HasValue)
+ {
+ var adapter = CreateDataAdapter();
+ if (adapter == null)
+ {
+ _canCreateDataAdapter = false;
+ }
+ else
+ {
+ _canCreateDataAdapter = true;
+ adapter.Dispose();
+ }
+ }
+
+ return _canCreateDataAdapter.Value;
+ }
+ }
+
+ public virtual bool CanCreateCommandBuilder
+ {
+ get
+ {
+ if (!_canCreateCommandBuilder.HasValue)
+ {
+ var builder = CreateCommandBuilder();
+ if (builder == null)
+ {
+ _canCreateCommandBuilder = false;
+ }
+ else
+ {
+ _canCreateCommandBuilder = true;
+ builder.Dispose();
+ }
+ }
+
+ return _canCreateCommandBuilder.Value;
+ }
+ }
+
public virtual DbCommand CreateCommand() => null;
public virtual DbCommandBuilder CreateCommandBuilder() => null;
<Compile Include="System\Data\Common\DbDataAdapterTest.cs" />
<Compile Include="System\Data\Common\DbDataReaderMock.cs" />
<Compile Include="System\Data\Common\DbDataReaderTest.cs" />
+ <Compile Include="System\Data\Common\DbProviderFactoryTest.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="System\Data\Common\DbTransactionTest.cs" />
<Compile Include="System\Data\Common\RowUpdatedEventArgsTest.cs" />
<Compile Include="System\Data\Common\RowUpdatingEventArgsTest.cs" />
<ItemGroup>
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// See the LICENSE file in the project root for more information.
+
+using Xunit;
+using System.Data.Common;
+
+namespace System.Data.Tests.Common
+{
+ public class DbProviderFactoryTest
+ {
+ [Fact]
+ public void CanCreateDataAdapter()
+ {
+ Assert.True(ProviderFactoryWithExtras.Instance.CanCreateDataAdapter);
+ Assert.False(ProviderFactoryWithoutExtras.Instance.CanCreateDataAdapter);
+ }
+
+ [Fact]
+ public void CanCreateCommandBuilder()
+ {
+ Assert.True(ProviderFactoryWithExtras.Instance.CanCreateCommandBuilder);
+ Assert.False(ProviderFactoryWithoutExtras.Instance.CanCreateCommandBuilder);
+ }
+
+ public sealed class ProviderFactoryWithExtras : DbProviderFactory
+ {
+ public static readonly ProviderFactoryWithExtras Instance = new ProviderFactoryWithExtras();
+ private ProviderFactoryWithExtras() { }
+
+ public override DbDataAdapter CreateDataAdapter() => new MyAdapter();
+ public override DbCommandBuilder CreateCommandBuilder() => new MyCommandBuilder();
+ }
+
+ public sealed class ProviderFactoryWithoutExtras : DbProviderFactory
+ {
+ public static readonly ProviderFactoryWithoutExtras Instance = new ProviderFactoryWithoutExtras();
+ private ProviderFactoryWithoutExtras() { }
+ }
+
+ private class MyAdapter : DbDataAdapter {}
+
+ private class MyCommandBuilder : DbCommandBuilder
+ {
+ protected override string GetParameterPlaceholder(int parameterOrdinal) => null;
+ protected override string GetParameterName(string parameterName) => null;
+ protected override string GetParameterName(int parameterOrdinal) => null;
+ protected override void ApplyParameterInfo(DbParameter parameter, DataRow row, StatementType statementType, bool whereClause) {}
+ protected override void SetRowUpdatingHandler(DbDataAdapter adapter) {}
+ }
+ }
+}