Skip to content

Commit

Permalink
NRT annotations for main System.Data.Common types (dotnet#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Jul 2, 2020
1 parent 719c58c commit ec73c56
Show file tree
Hide file tree
Showing 30 changed files with 330 additions and 157 deletions.
137 changes: 86 additions & 51 deletions src/libraries/System.Data.Common/ref/System.Data.Common.cs

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions src/libraries/System.Data.Common/src/System/Data/Common/DbColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

namespace System.Data.Common
{
public abstract class DbColumn
{
public bool? AllowDBNull { get; protected set; }
public string BaseCatalogName { get; protected set; }
public string BaseColumnName { get; protected set; }
public string BaseSchemaName { get; protected set; }
public string BaseServerName { get; protected set; }
public string BaseTableName { get; protected set; }
public string ColumnName { get; protected set; }
public string? BaseCatalogName { get; protected set; }
public string? BaseColumnName { get; protected set; }
public string? BaseSchemaName { get; protected set; }
public string? BaseServerName { get; protected set; }
public string? BaseTableName { get; protected set; }
public string ColumnName { get; protected set; } = "";
public int? ColumnOrdinal { get; protected set; }
public int? ColumnSize { get; protected set; }
public bool? IsAliased { get; protected set; }
Expand All @@ -26,10 +28,10 @@ public abstract class DbColumn
public bool? IsUnique { get; protected set; }
public int? NumericPrecision { get; protected set; }
public int? NumericScale { get; protected set; }
public string UdtAssemblyQualifiedName { get; protected set; }
public Type DataType { get; protected set; }
public string DataTypeName { get; protected set; }
public virtual object this[string property] =>
public string? UdtAssemblyQualifiedName { get; protected set; }
public Type? DataType { get; protected set; }
public string? DataTypeName { get; protected set; }
public virtual object? this[string property] =>
property switch
{
nameof(AllowDBNull) => AllowDBNull,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using System.Threading;

Expand All @@ -16,6 +18,7 @@ protected DbCommand() : base()

[DefaultValue("")]
[RefreshProperties(RefreshProperties.All)]
[AllowNull]
public abstract string CommandText { get; set; }

public abstract int CommandTimeout { get; set; }
Expand All @@ -27,23 +30,23 @@ protected DbCommand() : base()
[Browsable(false)]
[DefaultValue(null)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DbConnection Connection
public DbConnection? Connection
{
get { return DbConnection; }
set { DbConnection = value; }
}

IDbConnection IDbCommand.Connection
IDbConnection? IDbCommand.Connection
{
get { return DbConnection; }
set { DbConnection = (DbConnection)value; }
set { DbConnection = (DbConnection?)value; }
}

protected abstract DbConnection DbConnection { get; set; }
protected abstract DbConnection? DbConnection { get; set; }

protected abstract DbParameterCollection DbParameterCollection { get; }

protected abstract DbTransaction DbTransaction { get; set; }
protected abstract DbTransaction? DbTransaction { get; set; }

// By default, the cmd object is visible on the design surface (i.e. VS7 Server Tray)
// to limit the number of components that clutter the design surface,
Expand All @@ -64,16 +67,16 @@ IDbConnection IDbCommand.Connection
[Browsable(false)]
[DefaultValue(null)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DbTransaction Transaction
public DbTransaction? Transaction
{
get { return DbTransaction; }
set { DbTransaction = value; }
}

IDbTransaction IDbCommand.Transaction
IDbTransaction? IDbCommand.Transaction
{
get { return DbTransaction; }
set { DbTransaction = (DbTransaction)value; }
set { DbTransaction = (DbTransaction?)value; }
}

[DefaultValue(System.Data.UpdateRowSource.Both)]
Expand Down Expand Up @@ -128,7 +131,7 @@ public virtual Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToke
CancellationTokenRegistration registration = default;
if (cancellationToken.CanBeCanceled)
{
registration = cancellationToken.Register(s => ((DbCommand)s).CancelIgnoreFailure(), this);
registration = cancellationToken.Register(s => ((DbCommand)s!).CancelIgnoreFailure(), this);
}

try
Expand Down Expand Up @@ -169,7 +172,7 @@ protected virtual Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior be
CancellationTokenRegistration registration = default;
if (cancellationToken.CanBeCanceled)
{
registration = cancellationToken.Register(s => ((DbCommand)s).CancelIgnoreFailure(), this);
registration = cancellationToken.Register(s => ((DbCommand)s!).CancelIgnoreFailure(), this);
}

try
Expand All @@ -187,30 +190,30 @@ protected virtual Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior be
}
}

public Task<object> ExecuteScalarAsync() =>
public Task<object?> ExecuteScalarAsync() =>
ExecuteScalarAsync(CancellationToken.None);

public virtual Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
public virtual Task<object?> ExecuteScalarAsync(CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return ADP.CreatedTaskWithCancellation<object>();
return ADP.CreatedTaskWithCancellation<object?>();
}
else
{
CancellationTokenRegistration registration = default;
if (cancellationToken.CanBeCanceled)
{
registration = cancellationToken.Register(s => ((DbCommand)s).CancelIgnoreFailure(), this);
registration = cancellationToken.Register(s => ((DbCommand)s!).CancelIgnoreFailure(), this);
}

try
{
return Task.FromResult<object>(ExecuteScalar());
return Task.FromResult<object?>(ExecuteScalar());
}
catch (Exception e)
{
return Task.FromException<object>(e);
return Task.FromException<object?>(e);
}
finally
{
Expand All @@ -219,7 +222,7 @@ public virtual Task<object> ExecuteScalarAsync(CancellationToken cancellationTok
}
}

public abstract object ExecuteScalar();
public abstract object? ExecuteScalar();

public abstract void Prepare();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;

#nullable enable

namespace System.Data.Common
{
public abstract class DbConnection : Component, IDbConnection, IAsyncDisposable
Expand All @@ -24,6 +27,7 @@ protected DbConnection() : base()
#pragma warning disable 618 // ignore obsolete warning about RecommendedAsConfigurable to use SettingsBindableAttribute
[RecommendedAsConfigurable(true)]
#pragma warning restore 618
[AllowNull]
public abstract string ConnectionString { get; set; }

public virtual int ConnectionTimeout => ADP.DefaultConnectionTimeout;
Expand All @@ -35,17 +39,17 @@ protected DbConnection() : base()
/// <summary>
/// The associated provider factory for derived class.
/// </summary>
protected virtual DbProviderFactory DbProviderFactory => null;
protected virtual DbProviderFactory? DbProviderFactory => null;

internal DbProviderFactory ProviderFactory => DbProviderFactory;
internal DbProviderFactory? ProviderFactory => DbProviderFactory;

[Browsable(false)]
public abstract string ServerVersion { get; }

[Browsable(false)]
public abstract ConnectionState State { get; }

public virtual event StateChangeEventHandler StateChange;
public virtual event StateChangeEventHandler? StateChange;

protected abstract DbTransaction BeginDbTransaction(IsolationLevel isolationLevel);

Expand Down Expand Up @@ -133,7 +137,7 @@ public virtual Task ChangeDatabaseAsync(string databaseName, CancellationToken c

protected abstract DbCommand CreateDbCommand();

public virtual void EnlistTransaction(System.Transactions.Transaction transaction)
public virtual void EnlistTransaction(System.Transactions.Transaction? transaction)
{
throw ADP.NotSupported();
}
Expand All @@ -150,7 +154,7 @@ public virtual DataTable GetSchema(string collectionName)
throw ADP.NotSupported();
}

public virtual DataTable GetSchema(string collectionName, string[] restrictionValues)
public virtual DataTable GetSchema(string collectionName, string?[] restrictionValues)
{
throw ADP.NotSupported();
}
Expand Down
Loading

0 comments on commit ec73c56

Please sign in to comment.