Skip to content

Commit aecffec

Browse files
mgravellNickCraver
andauthored
attempt NRT makeover (#1928)
* 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 <[email protected]>
1 parent 8a68070 commit aecffec

File tree

112 files changed

+1736
-1509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1736
-1509
lines changed

Dapper.EntityFramework.StrongName/Dapper.EntityFramework.StrongName.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1111
<PackageId>Dapper.EntityFramework.StrongName</PackageId>
1212
<PackageTags>orm;sql;micro-orm</PackageTags>
13+
<Nullable>enable</Nullable>
1314
</PropertyGroup>
1415
<ItemGroup>
1516
<Compile Include="..\Dapper.EntityFramework\**\*.cs" Exclude="..\Dapper.EntityFramework\obj\**\*.cs" />
1617
</ItemGroup>
1718
<ItemGroup>
1819
<ProjectReference Include="..\Dapper.StrongName\Dapper.StrongName.csproj" />
19-
<!-- note: 6.2.0 has regressions; don't force the update -->
20-
<PackageReference Include="EntityFramework" Version="6.1.3" />
21-
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
20+
<PackageReference Include="EntityFramework" />
21+
<PackageReference Include="Microsoft.SqlServer.Types" />
2222
</ItemGroup>
2323
</Project>

Dapper.EntityFramework/Dapper.EntityFramework.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<Authors>Marc Gravell;Nick Craver</Authors>
88
<TargetFrameworks>net461</TargetFrameworks>
99
<PackageTags>orm;sql;micro-orm</PackageTags>
10+
<Nullable>enable</Nullable>
1011
</PropertyGroup>
1112
<ItemGroup>
1213
<ProjectReference Include="..\Dapper\Dapper.csproj" />
13-
<!-- note: 6.2.0 has regressions; don't force the update -->
14-
<PackageReference Include="EntityFramework" Version="6.1.3" />
15-
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
14+
<PackageReference Include="EntityFramework" />
15+
<PackageReference Include="Microsoft.SqlServer.Types" />
1616

17-
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
17+
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers">
1818
<PrivateAssets>all</PrivateAssets>
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2020
</PackageReference>

Dapper.EntityFramework/DbGeographyHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public class DbGeographyHandler : SqlMapper.TypeHandler<DbGeography>
2727
/// </summary>
2828
/// <param name="parameter">The parameter to configure.</param>
2929
/// <param name="value">Parameter value.</param>
30-
public override void SetValue(IDbDataParameter parameter, DbGeography value)
30+
public override void SetValue(IDbDataParameter parameter, DbGeography? value)
3131
{
32-
object parsed = null;
33-
if (value != null)
32+
object? parsed = null;
33+
if (value is not null)
3434
{
3535
parsed = SqlGeography.STGeomFromWKB(new SqlBytes(value.AsBinary()), value.CoordinateSystemId);
3636
}
@@ -46,9 +46,9 @@ public override void SetValue(IDbDataParameter parameter, DbGeography value)
4646
/// </summary>
4747
/// <param name="value">The value from the database.</param>
4848
/// <returns>The typed value.</returns>
49-
public override DbGeography Parse(object value)
49+
public override DbGeography? Parse(object? value)
5050
{
51-
if (value == null || value is DBNull) return null;
51+
if (value is null || value is DBNull) return null;
5252
if (value is SqlGeography geo)
5353
{
5454
return DbGeography.FromBinary(geo.STAsBinary().Value, geo.STSrid.Value);

Dapper.EntityFramework/DbGeometryHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public class DbGeometryHandler : SqlMapper.TypeHandler<DbGeometry>
2727
/// </summary>
2828
/// <param name="parameter">The parameter to configure.</param>
2929
/// <param name="value">Parameter value.</param>
30-
public override void SetValue(IDbDataParameter parameter, DbGeometry value)
30+
public override void SetValue(IDbDataParameter parameter, DbGeometry? value)
3131
{
32-
object parsed = null;
33-
if (value != null)
32+
object? parsed = null;
33+
if (value is not null)
3434
{
3535
parsed = SqlGeometry.STGeomFromWKB(new SqlBytes(value.AsBinary()), value.CoordinateSystemId);
3636
}
@@ -46,9 +46,9 @@ public override void SetValue(IDbDataParameter parameter, DbGeometry value)
4646
/// </summary>
4747
/// <param name="value">The value from the database.</param>
4848
/// <returns>The typed value.</returns>
49-
public override DbGeometry Parse(object value)
49+
public override DbGeometry? Parse(object? value)
5050
{
51-
if (value == null || value is DBNull) return null;
51+
if (value is null || value is DBNull) return null;
5252
if (value is SqlGeometry geo)
5353
{
5454
return DbGeometry.FromBinary(geo.STAsBinary().Value, geo.STSrid.Value);
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
Dapper.EntityFramework.DbGeographyHandler
1+
#nullable enable
2+
Dapper.EntityFramework.DbGeographyHandler
23
Dapper.EntityFramework.DbGeographyHandler.DbGeographyHandler() -> void
34
Dapper.EntityFramework.DbGeometryHandler
45
Dapper.EntityFramework.DbGeometryHandler.DbGeometryHandler() -> void
56
Dapper.EntityFramework.Handlers
6-
override Dapper.EntityFramework.DbGeographyHandler.Parse(object value) -> System.Data.Entity.Spatial.DbGeography
7-
override Dapper.EntityFramework.DbGeographyHandler.SetValue(System.Data.IDbDataParameter parameter, System.Data.Entity.Spatial.DbGeography value) -> void
8-
override Dapper.EntityFramework.DbGeometryHandler.Parse(object value) -> System.Data.Entity.Spatial.DbGeometry
9-
override Dapper.EntityFramework.DbGeometryHandler.SetValue(System.Data.IDbDataParameter parameter, System.Data.Entity.Spatial.DbGeometry value) -> void
7+
override Dapper.EntityFramework.DbGeographyHandler.Parse(object? value) -> System.Data.Entity.Spatial.DbGeography?
8+
override Dapper.EntityFramework.DbGeographyHandler.SetValue(System.Data.IDbDataParameter! parameter, System.Data.Entity.Spatial.DbGeography? value) -> void
9+
override Dapper.EntityFramework.DbGeometryHandler.Parse(object? value) -> System.Data.Entity.Spatial.DbGeometry?
10+
override Dapper.EntityFramework.DbGeometryHandler.SetValue(System.Data.IDbDataParameter! parameter, System.Data.Entity.Spatial.DbGeometry? value) -> void
1011
static Dapper.EntityFramework.Handlers.Register() -> void
11-
static readonly Dapper.EntityFramework.DbGeographyHandler.Default -> Dapper.EntityFramework.DbGeographyHandler
12-
static readonly Dapper.EntityFramework.DbGeometryHandler.Default -> Dapper.EntityFramework.DbGeometryHandler
12+
static readonly Dapper.EntityFramework.DbGeographyHandler.Default -> Dapper.EntityFramework.DbGeographyHandler!
13+
static readonly Dapper.EntityFramework.DbGeometryHandler.Default -> Dapper.EntityFramework.DbGeometryHandler!
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-

1+
#nullable enable

Dapper.ProviderTools/BulkCopy.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class BulkCopy : IDisposable
2020
/// </summary>
2121
public static BulkCopy? TryCreate(DbConnection connection)
2222
{
23-
if (connection == null) return null;
23+
if (connection is null) return null;
2424
var type = connection.GetType();
2525
if (!s_bcpFactory.TryGetValue(type, out var func))
2626
{
@@ -36,9 +36,9 @@ public abstract class BulkCopy : IDisposable
3636
public static BulkCopy Create(DbConnection connection)
3737
{
3838
var bcp = TryCreate(connection);
39-
if (bcp == null)
39+
if (bcp is null)
4040
{
41-
if (connection == null) throw new ArgumentNullException(nameof(connection));
41+
if (connection is null) throw new ArgumentNullException(nameof(connection));
4242
throw new NotSupportedException("Unable to create BulkCopy for " + connection.GetType().FullName);
4343
}
4444
return bcp;
@@ -64,10 +64,10 @@ private static readonly ConcurrentDictionary<Type, Func<DbConnection, object>?>
6464
{
6565
var prefix = match.Groups[1].Value;
6666
var bcpType = connectionType.Assembly.GetType($"{connectionType.Namespace}.{prefix}BulkCopy");
67-
if (bcpType != null)
67+
if (bcpType is not null)
6868
{
6969
var ctor = bcpType.GetConstructor(new[] { connectionType });
70-
if (ctor == null) return null;
70+
if (ctor is null) return null;
7171

7272
var p = Expression.Parameter(typeof(DbConnection), "conn");
7373
var body = Expression.New(ctor, Expression.Convert(p, connectionType));

Dapper.ProviderTools/Dapper.ProviderTools.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<Nullable>enable</Nullable>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
13+
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1616
</PackageReference>
1717
</ItemGroup>
1818
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
19-
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
19+
<PackageReference Include="Microsoft.CSharp" />
2020
</ItemGroup>
2121
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
2222
<Reference Include="Microsoft.CSharp" />

Dapper.ProviderTools/DbConnectionExtensions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ public static class DbConnectionExtensions
1717
public static bool TryGetClientConnectionId(this DbConnection connection, out Guid clientConnectionId)
1818
{
1919
clientConnectionId = default;
20-
return connection != null && ByTypeHelpers.Get(connection.GetType()).TryGetClientConnectionId(
20+
return connection is not null && ByTypeHelpers.Get(connection.GetType()).TryGetClientConnectionId(
2121
connection, out clientConnectionId);
2222
}
2323

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

3030
/// <summary>
3131
/// Clear the pools associated with the provided connection
3232
/// </summary>
3333
public static bool TryClearPool(this DbConnection connection)
34-
=> connection != null && ByTypeHelpers.Get(connection.GetType()).TryClearPool(connection);
34+
=> connection is not null && ByTypeHelpers.Get(connection.GetType()).TryClearPool(connection);
3535

3636
private sealed class ByTypeHelpers
3737
{
@@ -44,7 +44,7 @@ private static readonly ConcurrentDictionary<Type, ByTypeHelpers> s_byType
4444

4545
public bool TryGetClientConnectionId(DbConnection connection, out Guid clientConnectionId)
4646
{
47-
if (_getClientConnectionId == null)
47+
if (_getClientConnectionId is null)
4848
{
4949
clientConnectionId = default;
5050
return false;
@@ -55,14 +55,14 @@ public bool TryGetClientConnectionId(DbConnection connection, out Guid clientCon
5555

5656
public bool TryClearPool(DbConnection connection)
5757
{
58-
if (_clearPool == null) return false;
58+
if (_clearPool is null) return false;
5959
_clearPool(connection);
6060
return true;
6161
}
6262

6363
public bool TryClearAllPools()
6464
{
65-
if (_clearAllPools == null) return false;
65+
if (_clearAllPools is null) return false;
6666
_clearAllPools();
6767
return true;
6868
}
@@ -84,7 +84,7 @@ private ByTypeHelpers(Type type)
8484
{
8585
var clearAllPools = type.GetMethod("ClearAllPools", BindingFlags.Public | BindingFlags.Static,
8686
null, Type.EmptyTypes, null);
87-
if (clearAllPools != null)
87+
if (clearAllPools is not null)
8888
{
8989
_clearAllPools = (Action)Delegate.CreateDelegate(typeof(Action), clearAllPools);
9090
}
@@ -95,7 +95,7 @@ private ByTypeHelpers(Type type)
9595
{
9696
var clearPool = type.GetMethod("ClearPool", BindingFlags.Public | BindingFlags.Static,
9797
null, new[] { type }, null);
98-
if (clearPool != null)
98+
if (clearPool is not null)
9999
{
100100
var p = Expression.Parameter(typeof(DbConnection), "connection");
101101
var body = Expression.Call(clearPool, Expression.Convert(p, type));
@@ -111,7 +111,7 @@ private ByTypeHelpers(Type type)
111111
try
112112
{
113113
var prop = type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
114-
if (prop == null || !prop.CanRead) return null;
114+
if (prop is null || !prop.CanRead) return null;
115115
if (prop.PropertyType != typeof(T)) return null;
116116

117117
var p = Expression.Parameter(typeof(DbConnection), "connection");

Dapper.ProviderTools/DbExceptionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class DbExceptionExtensions
1515
/// Indicates whether the provided exception has an integer Number property with the supplied value
1616
/// </summary>
1717
public static bool IsNumber(this DbException exception, int number)
18-
=> exception != null && ByTypeHelpers.Get(exception.GetType()).IsNumber(exception, number);
18+
=> exception is not null && ByTypeHelpers.Get(exception.GetType()).IsNumber(exception, number);
1919

2020

2121
private sealed class ByTypeHelpers
@@ -25,7 +25,7 @@ private static readonly ConcurrentDictionary<Type, ByTypeHelpers> s_byType
2525
private readonly Func<DbException, int>? _getNumber;
2626

2727
public bool IsNumber(DbException exception, int number)
28-
=> _getNumber != null && _getNumber(exception) == number;
28+
=> _getNumber is not null && _getNumber(exception) == number;
2929

3030
public static ByTypeHelpers Get(Type type)
3131
{
@@ -46,7 +46,7 @@ private ByTypeHelpers(Type type)
4646
try
4747
{
4848
var prop = type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
49-
if (prop == null || !prop.CanRead) return null;
49+
if (prop is null || !prop.CanRead) return null;
5050
if (prop.PropertyType != typeof(T)) return null;
5151

5252
var p = Expression.Parameter(typeof(DbException), "exception");

0 commit comments

Comments
 (0)