Skip to content

Commit

Permalink
attempt NRT makeover (#1928)
Browse files Browse the repository at this point in the history
* attempt NRT makeover

- annotate NRTs on GridReader API
- add protected access to some of the GridReader internals
- switch GridReader callbacks to be more type-independent

docs

lib updates; deal with yellow warnings and test failures (SQL server certs and cancellation surfacing differently)

fix break

simplify proposed GridReader changes to protected OnBeforeGrid and OnAfterGrid[Async]

Builds: Bump library versions (#1935)

Tests: Upgrade dependencies for Dependabot (#1936)

I'll do a pass at all of these later, but getting CVE versions out of the pipe.

Resolving 4 alerts here: https://github.com/DapperLib/Dapper/security/dependabot

merge and lib updates

allow Identity to be constructed on-the-fly inside GridReader

fix build warnings

include readme

rev minor

- enable [SkipLocalsInit] everywhere
- use NET5_0_OR_GREATER
 for remoting check

# Conflicts:
#	Dapper/CommandDefinition.cs
#	Dapper/DefaultTypeMap.cs
#	Dapper/SqlMapper.Async.cs
#	Dapper/SqlMapper.IDataReader.cs
#	Dapper/SqlMapper.Link.cs
#	Dapper/SqlMapper.cs
#	Directory.Build.props

* shipped, not unshipped

* fixup SqlBuilder; use is null / is not null

* use central package management (#1949)

* Nullable test tweaks

* Nuget: let's just remove it!

* 2 test fixes from review

* fix FindExplicitConstructor

* add GetPropertySetterOrThrow

* fix NRT on FindConstructor

* DapperRow: value is object?

* use NotNullWhen

* make constructor problem more obvious

* test fixes

---------

Co-authored-by: Nick Craver <nrcraver@gmail.com>
  • Loading branch information
mgravell and NickCraver committed Sep 12, 2023
1 parent 8a68070 commit aecffec
Show file tree
Hide file tree
Showing 112 changed files with 1,736 additions and 1,509 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Dapper.EntityFramework.StrongName</PackageId>
<PackageTags>orm;sql;micro-orm</PackageTags>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper.EntityFramework\**\*.cs" Exclude="..\Dapper.EntityFramework\obj\**\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper.StrongName\Dapper.StrongName.csproj" />
<!-- note: 6.2.0 has regressions; don't force the update -->
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
<PackageReference Include="EntityFramework" />
<PackageReference Include="Microsoft.SqlServer.Types" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions Dapper.EntityFramework/Dapper.EntityFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net461</TargetFrameworks>
<PackageTags>orm;sql;micro-orm</PackageTags>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<!-- note: 6.2.0 has regressions; don't force the update -->
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
<PackageReference Include="EntityFramework" />
<PackageReference Include="Microsoft.SqlServer.Types" />

<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
10 changes: 5 additions & 5 deletions Dapper.EntityFramework/DbGeographyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public class DbGeographyHandler : SqlMapper.TypeHandler<DbGeography>
/// </summary>
/// <param name="parameter">The parameter to configure.</param>
/// <param name="value">Parameter value.</param>
public override void SetValue(IDbDataParameter parameter, DbGeography value)
public override void SetValue(IDbDataParameter parameter, DbGeography? value)
{
object parsed = null;
if (value != null)
object? parsed = null;
if (value is not null)
{
parsed = SqlGeography.STGeomFromWKB(new SqlBytes(value.AsBinary()), value.CoordinateSystemId);
}
Expand All @@ -46,9 +46,9 @@ public override void SetValue(IDbDataParameter parameter, DbGeography value)
/// </summary>
/// <param name="value">The value from the database.</param>
/// <returns>The typed value.</returns>
public override DbGeography Parse(object value)
public override DbGeography? Parse(object? value)
{
if (value == null || value is DBNull) return null;
if (value is null || value is DBNull) return null;
if (value is SqlGeography geo)
{
return DbGeography.FromBinary(geo.STAsBinary().Value, geo.STSrid.Value);
Expand Down
10 changes: 5 additions & 5 deletions Dapper.EntityFramework/DbGeometryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public class DbGeometryHandler : SqlMapper.TypeHandler<DbGeometry>
/// </summary>
/// <param name="parameter">The parameter to configure.</param>
/// <param name="value">Parameter value.</param>
public override void SetValue(IDbDataParameter parameter, DbGeometry value)
public override void SetValue(IDbDataParameter parameter, DbGeometry? value)
{
object parsed = null;
if (value != null)
object? parsed = null;
if (value is not null)
{
parsed = SqlGeometry.STGeomFromWKB(new SqlBytes(value.AsBinary()), value.CoordinateSystemId);
}
Expand All @@ -46,9 +46,9 @@ public override void SetValue(IDbDataParameter parameter, DbGeometry value)
/// </summary>
/// <param name="value">The value from the database.</param>
/// <returns>The typed value.</returns>
public override DbGeometry Parse(object value)
public override DbGeometry? Parse(object? value)
{
if (value == null || value is DBNull) return null;
if (value is null || value is DBNull) return null;
if (value is SqlGeometry geo)
{
return DbGeometry.FromBinary(geo.STAsBinary().Value, geo.STSrid.Value);
Expand Down
15 changes: 8 additions & 7 deletions Dapper.EntityFramework/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Dapper.EntityFramework.DbGeographyHandler
#nullable enable
Dapper.EntityFramework.DbGeographyHandler
Dapper.EntityFramework.DbGeographyHandler.DbGeographyHandler() -> void
Dapper.EntityFramework.DbGeometryHandler
Dapper.EntityFramework.DbGeometryHandler.DbGeometryHandler() -> void
Dapper.EntityFramework.Handlers
override Dapper.EntityFramework.DbGeographyHandler.Parse(object value) -> System.Data.Entity.Spatial.DbGeography
override Dapper.EntityFramework.DbGeographyHandler.SetValue(System.Data.IDbDataParameter parameter, System.Data.Entity.Spatial.DbGeography value) -> void
override Dapper.EntityFramework.DbGeometryHandler.Parse(object value) -> System.Data.Entity.Spatial.DbGeometry
override Dapper.EntityFramework.DbGeometryHandler.SetValue(System.Data.IDbDataParameter parameter, System.Data.Entity.Spatial.DbGeometry value) -> void
override Dapper.EntityFramework.DbGeographyHandler.Parse(object? value) -> System.Data.Entity.Spatial.DbGeography?
override Dapper.EntityFramework.DbGeographyHandler.SetValue(System.Data.IDbDataParameter! parameter, System.Data.Entity.Spatial.DbGeography? value) -> void
override Dapper.EntityFramework.DbGeometryHandler.Parse(object? value) -> System.Data.Entity.Spatial.DbGeometry?
override Dapper.EntityFramework.DbGeometryHandler.SetValue(System.Data.IDbDataParameter! parameter, System.Data.Entity.Spatial.DbGeometry? value) -> void
static Dapper.EntityFramework.Handlers.Register() -> void
static readonly Dapper.EntityFramework.DbGeographyHandler.Default -> Dapper.EntityFramework.DbGeographyHandler
static readonly Dapper.EntityFramework.DbGeometryHandler.Default -> Dapper.EntityFramework.DbGeometryHandler
static readonly Dapper.EntityFramework.DbGeographyHandler.Default -> Dapper.EntityFramework.DbGeographyHandler!
static readonly Dapper.EntityFramework.DbGeometryHandler.Default -> Dapper.EntityFramework.DbGeometryHandler!
2 changes: 1 addition & 1 deletion Dapper.EntityFramework/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

#nullable enable
10 changes: 5 additions & 5 deletions Dapper.ProviderTools/BulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class BulkCopy : IDisposable
/// </summary>
public static BulkCopy? TryCreate(DbConnection connection)
{
if (connection == null) return null;
if (connection is null) return null;
var type = connection.GetType();
if (!s_bcpFactory.TryGetValue(type, out var func))
{
Expand All @@ -36,9 +36,9 @@ public abstract class BulkCopy : IDisposable
public static BulkCopy Create(DbConnection connection)
{
var bcp = TryCreate(connection);
if (bcp == null)
if (bcp is null)
{
if (connection == null) throw new ArgumentNullException(nameof(connection));
if (connection is null) throw new ArgumentNullException(nameof(connection));
throw new NotSupportedException("Unable to create BulkCopy for " + connection.GetType().FullName);
}
return bcp;
Expand All @@ -64,10 +64,10 @@ public static BulkCopy Create(DbConnection connection)
{
var prefix = match.Groups[1].Value;
var bcpType = connectionType.Assembly.GetType($"{connectionType.Namespace}.{prefix}BulkCopy");
if (bcpType != null)
if (bcpType is not null)
{
var ctor = bcpType.GetConstructor(new[] { connectionType });
if (ctor == null) return null;
if (ctor is null) return null;

var p = Expression.Parameter(typeof(DbConnection), "conn");
var body = Expression.New(ctor, Expression.Convert(p, connectionType));
Expand Down
4 changes: 2 additions & 2 deletions Dapper.ProviderTools/Dapper.ProviderTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="Microsoft.CSharp" />
Expand Down
18 changes: 9 additions & 9 deletions Dapper.ProviderTools/DbConnectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public static class DbConnectionExtensions
public static bool TryGetClientConnectionId(this DbConnection connection, out Guid clientConnectionId)
{
clientConnectionId = default;
return connection != null && ByTypeHelpers.Get(connection.GetType()).TryGetClientConnectionId(
return connection is not null && ByTypeHelpers.Get(connection.GetType()).TryGetClientConnectionId(
connection, out clientConnectionId);
}

/// <summary>
/// Clear all pools associated with the provided connection type
/// </summary>
public static bool TryClearAllPools(this DbConnection connection)
=> connection != null && ByTypeHelpers.Get(connection.GetType()).TryClearAllPools();
=> connection is not null && ByTypeHelpers.Get(connection.GetType()).TryClearAllPools();

/// <summary>
/// Clear the pools associated with the provided connection
/// </summary>
public static bool TryClearPool(this DbConnection connection)
=> connection != null && ByTypeHelpers.Get(connection.GetType()).TryClearPool(connection);
=> connection is not null && ByTypeHelpers.Get(connection.GetType()).TryClearPool(connection);

private sealed class ByTypeHelpers
{
Expand All @@ -44,7 +44,7 @@ private sealed class ByTypeHelpers

public bool TryGetClientConnectionId(DbConnection connection, out Guid clientConnectionId)
{
if (_getClientConnectionId == null)
if (_getClientConnectionId is null)
{
clientConnectionId = default;
return false;
Expand All @@ -55,14 +55,14 @@ public bool TryGetClientConnectionId(DbConnection connection, out Guid clientCon

public bool TryClearPool(DbConnection connection)
{
if (_clearPool == null) return false;
if (_clearPool is null) return false;
_clearPool(connection);
return true;
}

public bool TryClearAllPools()
{
if (_clearAllPools == null) return false;
if (_clearAllPools is null) return false;
_clearAllPools();
return true;
}
Expand All @@ -84,7 +84,7 @@ private ByTypeHelpers(Type type)
{
var clearAllPools = type.GetMethod("ClearAllPools", BindingFlags.Public | BindingFlags.Static,
null, Type.EmptyTypes, null);
if (clearAllPools != null)
if (clearAllPools is not null)
{
_clearAllPools = (Action)Delegate.CreateDelegate(typeof(Action), clearAllPools);
}
Expand All @@ -95,7 +95,7 @@ private ByTypeHelpers(Type type)
{
var clearPool = type.GetMethod("ClearPool", BindingFlags.Public | BindingFlags.Static,
null, new[] { type }, null);
if (clearPool != null)
if (clearPool is not null)
{
var p = Expression.Parameter(typeof(DbConnection), "connection");
var body = Expression.Call(clearPool, Expression.Convert(p, type));
Expand All @@ -111,7 +111,7 @@ private ByTypeHelpers(Type type)
try
{
var prop = type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
if (prop == null || !prop.CanRead) return null;
if (prop is null || !prop.CanRead) return null;
if (prop.PropertyType != typeof(T)) return null;

var p = Expression.Parameter(typeof(DbConnection), "connection");
Expand Down
6 changes: 3 additions & 3 deletions Dapper.ProviderTools/DbExceptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class DbExceptionExtensions
/// Indicates whether the provided exception has an integer Number property with the supplied value
/// </summary>
public static bool IsNumber(this DbException exception, int number)
=> exception != null && ByTypeHelpers.Get(exception.GetType()).IsNumber(exception, number);
=> exception is not null && ByTypeHelpers.Get(exception.GetType()).IsNumber(exception, number);


private sealed class ByTypeHelpers
Expand All @@ -25,7 +25,7 @@ private sealed class ByTypeHelpers
private readonly Func<DbException, int>? _getNumber;

public bool IsNumber(DbException exception, int number)
=> _getNumber != null && _getNumber(exception) == number;
=> _getNumber is not null && _getNumber(exception) == number;

public static ByTypeHelpers Get(Type type)
{
Expand All @@ -46,7 +46,7 @@ private ByTypeHelpers(Type type)
try
{
var prop = type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
if (prop == null || !prop.CanRead) return null;
if (prop is null || !prop.CanRead) return null;
if (prop.PropertyType != typeof(T)) return null;

var p = Expression.Parameter(typeof(DbException), "exception");
Expand Down
2 changes: 1 addition & 1 deletion Dapper.ProviderTools/Internal/DynamicBulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Dapper.ProviderTools.Internal
internal sealed class DynamicBulkCopy : BulkCopy
{
internal static BulkCopy? Create(object? wrapped)
=> wrapped == null ? null : new DynamicBulkCopy(wrapped);
=> wrapped is null ? null : new DynamicBulkCopy(wrapped);

private DynamicBulkCopy(object wrapped)
=> _wrapped = wrapped;
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Rainbow/Dapper.Rainbow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="Microsoft.CSharp" />
Expand Down
5 changes: 3 additions & 2 deletions Dapper.SqlBuilder/Dapper.SqlBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />

<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="Microsoft.CSharp" />
Expand Down
39 changes: 20 additions & 19 deletions Dapper.SqlBuilder/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
Dapper.SqlBuilder
Dapper.SqlBuilder.AddClause(string name, string sql, object parameters, string joiner, string prefix = "", string postfix = "", bool isInclusive = false) -> Dapper.SqlBuilder
Dapper.SqlBuilder.AddParameters(dynamic parameters) -> Dapper.SqlBuilder
Dapper.SqlBuilder.AddTemplate(string sql, dynamic parameters = null) -> Dapper.SqlBuilder.Template
Dapper.SqlBuilder.GroupBy(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.Having(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.InnerJoin(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.Intersect(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.Join(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.LeftJoin(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.OrderBy(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.OrWhere(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.RightJoin(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.Select(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.Set(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
#nullable enable
Dapper.SqlBuilder
Dapper.SqlBuilder.AddClause(string! name, string! sql, object? parameters, string! joiner, string! prefix = "", string! postfix = "", bool isInclusive = false) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.AddParameters(dynamic! parameters) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.AddTemplate(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder.Template!
Dapper.SqlBuilder.GroupBy(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.Having(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.InnerJoin(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.Intersect(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.Join(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.LeftJoin(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.OrderBy(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.OrWhere(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.RightJoin(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.Select(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.Set(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
Dapper.SqlBuilder.SqlBuilder() -> void
Dapper.SqlBuilder.Template
Dapper.SqlBuilder.Template.Parameters.get -> object
Dapper.SqlBuilder.Template.RawSql.get -> string
Dapper.SqlBuilder.Template.Template(Dapper.SqlBuilder builder, string sql, dynamic parameters) -> void
Dapper.SqlBuilder.Where(string sql, dynamic parameters = null) -> Dapper.SqlBuilder
Dapper.SqlBuilder.Template.Parameters.get -> object?
Dapper.SqlBuilder.Template.RawSql.get -> string!
Dapper.SqlBuilder.Template.Template(Dapper.SqlBuilder! builder, string! sql, dynamic? parameters) -> void
Dapper.SqlBuilder.Where(string! sql, dynamic? parameters = null) -> Dapper.SqlBuilder!
2 changes: 1 addition & 1 deletion Dapper.SqlBuilder/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

#nullable enable

0 comments on commit aecffec

Please sign in to comment.