Skip to content

Commit 93bb59f

Browse files
committed
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
1 parent 67f7a1f commit 93bb59f

File tree

98 files changed

+1355
-1249
lines changed

Some content is hidden

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

98 files changed

+1355
-1249
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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" />

Dapper.EntityFramework/Dapper.EntityFramework.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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" />

Dapper.EntityFramework/DbGeographyHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ 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;
32+
object? parsed = null;
3333
if (value != null)
3434
{
3535
parsed = SqlGeography.STGeomFromWKB(new SqlBytes(value.AsBinary()), value.CoordinateSystemId);
@@ -46,7 +46,7 @@ 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
{
5151
if (value == null || value is DBNull) return null;
5252
if (value is SqlGeography geo)

Dapper.EntityFramework/DbGeometryHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ 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;
32+
object? parsed = null;
3333
if (value != null)
3434
{
3535
parsed = SqlGeometry.STGeomFromWKB(new SqlBytes(value.AsBinary()), value.CoordinateSystemId);
@@ -46,7 +46,7 @@ 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
{
5151
if (value == null || value is DBNull) return null;
5252
if (value is SqlGeometry geo)
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.StrongName/Dapper.StrongName.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
99
<SignAssembly>true</SignAssembly>
1010
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
11+
<Nullable>enable</Nullable>
12+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1113
</PropertyGroup>
1214
<ItemGroup>
1315
<Folder Include="Properties\" />
1416
<Compile Include="..\Dapper\**\*.cs" Exclude="..\Dapper\obj\**\*.cs" />
1517
</ItemGroup>
1618

17-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0'">
18-
<DefineConstants>$(DefineConstants);PLAT_NO_REMOTING;PLAT_SKIP_LOCALS_INIT</DefineConstants>
19-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
20-
</PropertyGroup>
2119
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
2220
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
2321
</ItemGroup>

Dapper.sln

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28917.182
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.33906.173
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A34907DF-958A-4E4C-8491-84CF303FD13E}"
77
ProjectSection(SolutionItems) = preProject
@@ -31,9 +31,6 @@ EndProject
3131
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper.Rainbow", "Dapper.Rainbow\Dapper.Rainbow.csproj", "{8A74F0B6-188F-45D2-8A4B-51E4F211805A}"
3232
EndProject
3333
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4E956F6B-6BD8-46F5-BC85-49292FF8F9AB}"
34-
ProjectSection(SolutionItems) = preProject
35-
Directory.Build.props = Directory.Build.props
36-
EndProjectSection
3734
EndProject
3835
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{568BD46C-1C65-4D44-870C-12CD72563262}"
3936
ProjectSection(SolutionItems) = preProject
@@ -51,6 +48,7 @@ EndProject
5148
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{9D960D4D-80A2-4DAC-B386-8F4235EC73E6}"
5249
ProjectSection(SolutionItems) = preProject
5350
docs\index.md = docs\index.md
51+
docs\readme.md = docs\readme.md
5452
EndProjectSection
5553
EndProject
5654
Global

Dapper/CommandDefinition.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Dapper
1111
/// </summary>
1212
public readonly struct CommandDefinition
1313
{
14-
internal static CommandDefinition ForCallback(object parameters)
14+
internal static CommandDefinition ForCallback(object? parameters)
1515
{
1616
if (parameters is DynamicParameters)
1717
{
@@ -36,12 +36,12 @@ internal void OnCompleted()
3636
/// <summary>
3737
/// The parameters associated with the command
3838
/// </summary>
39-
public object Parameters { get; }
39+
public object? Parameters { get; }
4040

4141
/// <summary>
4242
/// The active transaction for the command
4343
/// </summary>
44-
public IDbTransaction Transaction { get; }
44+
public IDbTransaction? Transaction { get; }
4545

4646
/// <summary>
4747
/// The effective timeout for the command
@@ -83,7 +83,7 @@ internal void OnCompleted()
8383
/// <param name="commandType">The <see cref="CommandType"/> for this command.</param>
8484
/// <param name="flags">The behavior flags for this command.</param>
8585
/// <param name="cancellationToken">The cancellation token for this command.</param>
86-
public CommandDefinition(string commandText, object parameters = null, IDbTransaction transaction = null, int? commandTimeout = null,
86+
public CommandDefinition(string commandText, object? parameters = null, IDbTransaction? transaction = null, int? commandTimeout = null,
8787
CommandType? commandType = null, CommandFlags flags = CommandFlags.Buffered
8888
, CancellationToken cancellationToken = default
8989
)
@@ -97,17 +97,18 @@ public CommandDefinition(string commandText, object parameters = null, IDbTransa
9797
CancellationToken = cancellationToken;
9898
}
9999

100-
private CommandDefinition(object parameters) : this()
100+
private CommandDefinition(object? parameters) : this()
101101
{
102102
Parameters = parameters;
103+
CommandText = "";
103104
}
104105

105106
/// <summary>
106107
/// For asynchronous operations, the cancellation-token
107108
/// </summary>
108109
public CancellationToken CancellationToken { get; }
109110

110-
internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> paramReader)
111+
internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object?>? paramReader)
111112
{
112113
var cmd = cnn.CreateCommand();
113114
var init = GetInit(cmd.GetType());
@@ -129,16 +130,16 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> p
129130
return cmd;
130131
}
131132

132-
private static SqlMapper.Link<Type, Action<IDbCommand>> commandInitCache;
133+
private static SqlMapper.Link<Type, Action<IDbCommand>>? commandInitCache;
133134

134135
internal static void ResetCommandInitCache()
135136
=> SqlMapper.Link<Type, Action<IDbCommand>>.Clear(ref commandInitCache);
136137

137-
private static Action<IDbCommand> GetInit(Type commandType)
138+
private static Action<IDbCommand>? GetInit(Type commandType)
138139
{
139140
if (commandType == null)
140141
return null; // GIGO
141-
if (SqlMapper.Link<Type, Action<IDbCommand>>.TryGet(commandInitCache, commandType, out Action<IDbCommand> action))
142+
if (SqlMapper.Link<Type, Action<IDbCommand>>.TryGet(commandInitCache, commandType, out Action<IDbCommand>? action))
142143
{
143144
return action;
144145
}
@@ -184,11 +185,11 @@ private static Action<IDbCommand> GetInit(Type commandType)
184185
action = (Action<IDbCommand>)method.CreateDelegate(typeof(Action<IDbCommand>));
185186
}
186187
// cache it
187-
SqlMapper.Link<Type, Action<IDbCommand>>.TryAdd(ref commandInitCache, commandType, ref action);
188+
SqlMapper.Link<Type, Action<IDbCommand>>.TryAdd(ref commandInitCache, commandType, ref action!);
188189
return action;
189190
}
190191

191-
private static MethodInfo GetBasicPropertySetter(Type declaringType, string name, Type expectedType)
192+
private static MethodInfo? GetBasicPropertySetter(Type declaringType, string name, Type expectedType)
192193
{
193194
var prop = declaringType.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
194195
if (prop?.CanWrite == true && prop.PropertyType == expectedType && prop.GetIndexParameters().Length == 0)

Dapper/CustomPropertyTypeMap.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propert
2929
/// <param name="types">DataReader column types</param>
3030
/// <returns>Default constructor</returns>
3131
public ConstructorInfo FindConstructor(string[] names, Type[] types) =>
32-
_type.GetConstructor(Array.Empty<Type>());
32+
_type.GetConstructor(Array.Empty<Type>())!;
3333

3434
/// <summary>
3535
/// Always returns null
3636
/// </summary>
3737
/// <returns></returns>
38-
public ConstructorInfo FindExplicitConstructor() => null;
38+
public ConstructorInfo FindExplicitConstructor() => null!;
3939

4040
/// <summary>
4141
/// Not implemented as far as default constructor used for all cases
@@ -53,7 +53,7 @@ public SqlMapper.IMemberMap GetConstructorParameter(ConstructorInfo constructor,
5353
/// </summary>
5454
/// <param name="columnName">DataReader column name</param>
5555
/// <returns>Property member map</returns>
56-
public SqlMapper.IMemberMap GetMember(string columnName)
56+
public SqlMapper.IMemberMap? GetMember(string columnName)
5757
{
5858
var prop = _propertySelector(_type, columnName);
5959
return prop != null ? new SimpleMemberMap(columnName, prop) : null;

0 commit comments

Comments
 (0)