Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add public .ctor to identiy (for AOT) #1999

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dapper/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Dapper.SqlMapper.ICustomQueryParameter.AddParameter(System.Data.IDbCommand! comm
Dapper.SqlMapper.Identity
Dapper.SqlMapper.Identity.Equals(Dapper.SqlMapper.Identity? other) -> bool
Dapper.SqlMapper.Identity.ForDynamicParameters(System.Type! type) -> Dapper.SqlMapper.Identity!
Dapper.SqlMapper.Identity.Identity(string! sql, System.Data.CommandType commandType, System.Data.IDbConnection! connection, System.Type? type, System.Type? parametersType) -> void
Dapper.SqlMapper.IDynamicParameters
Dapper.SqlMapper.IDynamicParameters.AddParameters(System.Data.IDbCommand! command, Dapper.SqlMapper.Identity! identity) -> void
Dapper.SqlMapper.IMemberMap
Expand Down
26 changes: 15 additions & 11 deletions Dapper/SqlMapper.Identity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ internal sealed class Identity<TFirst, TSecond, TThird, TFourth, TFifth, TSixth,
private static readonly int s_typeHash;
private static readonly int s_typeCount = CountNonTrivial(out s_typeHash);

internal Identity(string sql, CommandType? commandType, string connectionString, Type type, Type? parametersType, int gridIndex = 0)
internal Identity(string sql, CommandType commandType, string connectionString, Type type, Type? parametersType, int gridIndex = 0)
: base(sql, commandType, connectionString, type, parametersType, s_typeHash, gridIndex)
{}
internal Identity(string sql, CommandType? commandType, IDbConnection connection, Type type, Type? parametersType, int gridIndex = 0)
internal Identity(string sql, CommandType commandType, IDbConnection connection, Type type, Type? parametersType, int gridIndex = 0)
: base(sql, commandType, connection.ConnectionString, type, parametersType, s_typeHash, gridIndex)
{ }

Expand Down Expand Up @@ -56,12 +56,12 @@ internal sealed class IdentityWithTypes : Identity
private readonly Type[] _types;

internal IdentityWithTypes(string sql, CommandType? commandType, string connectionString, Type type, Type? parametersType, Type[] otherTypes, int gridIndex = 0)
: base(sql, commandType, connectionString, type, parametersType, HashTypes(otherTypes), gridIndex)
: base(sql, commandType.GetValueOrDefault(), connectionString, type, parametersType, HashTypes(otherTypes), gridIndex)
{
_types = otherTypes ?? Type.EmptyTypes;
}
internal IdentityWithTypes(string sql, CommandType? commandType, IDbConnection connection, Type type, Type? parametersType, Type[] otherTypes, int gridIndex = 0)
: base(sql, commandType, connection.ConnectionString, type, parametersType, HashTypes(otherTypes), gridIndex)
: base(sql, commandType.GetValueOrDefault(), connection.ConnectionString, type, parametersType, HashTypes(otherTypes), gridIndex)
{
_types = otherTypes ?? Type.EmptyTypes;
}
Expand Down Expand Up @@ -95,14 +95,14 @@ public class Identity : IEquatable<Identity>

#pragma warning disable CS0618 // Type or member is obsolete
internal Identity ForGrid<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(Type primaryType, int gridIndex) =>
new Identity<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(sql, commandType, connectionString, primaryType, parametersType, gridIndex);
new Identity<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(sql, commandType.GetValueOrDefault(), connectionString, primaryType, parametersType, gridIndex);

internal Identity ForGrid(Type primaryType, int gridIndex) =>
new Identity(sql, commandType, connectionString, primaryType, parametersType, 0, gridIndex);
new Identity(sql, commandType.GetValueOrDefault(), connectionString, primaryType, parametersType, 0, gridIndex);

internal Identity ForGrid(Type primaryType, Type[] otherTypes, int gridIndex) =>
(otherTypes is null || otherTypes.Length == 0)
? new Identity(sql, commandType, connectionString, primaryType, parametersType, 0, gridIndex)
? new Identity(sql, commandType.GetValueOrDefault(), connectionString, primaryType, parametersType, 0, gridIndex)
: new IdentityWithTypes(sql, commandType, connectionString, primaryType, parametersType, otherTypes, gridIndex);

/// <summary>
Expand All @@ -111,13 +111,17 @@ internal Identity ForGrid(Type primaryType, Type[] otherTypes, int gridIndex) =>
/// <param name="type">The parameters type to create an <see cref="Identity"/> for.</param>
/// <returns></returns>
public Identity ForDynamicParameters(Type type) =>
new Identity(sql, commandType, connectionString, this.type, type, 0, -1);
new Identity(sql, commandType.GetValueOrDefault(), connectionString, this.type, type, 0, -1);
#pragma warning restore CS0618 // Type or member is obsolete

internal Identity(string sql, CommandType? commandType, IDbConnection connection, Type? type, Type? parametersType)
/// <summary>
/// Create a new <see cref="Identity"/> instance.
/// </summary>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] // discourage usage
public Identity(string sql, CommandType commandType, IDbConnection connection, Type? type, Type? parametersType)
: this(sql, commandType, connection.ConnectionString, type, parametersType, 0, 0) { /* base call */ }

private protected Identity(string sql, CommandType? commandType, string connectionString, Type? type, Type? parametersType, int otherTypesHash, int gridIndex)
private protected Identity(string sql, CommandType commandType, string connectionString, Type? type, Type? parametersType, int otherTypesHash, int gridIndex)
{
#pragma warning disable CS0618 // Type or member is obsolete
this.sql = sql;
Expand Down Expand Up @@ -165,7 +169,7 @@ private protected Identity(string sql, CommandType? commandType, string connecti
/// </summary>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Please use " + nameof(CommandType) + ". This API may be removed at a later date.")]
public readonly CommandType? commandType;
public readonly CommandType? commandType; // in addition to field hell, this should now be non-nullable

/// <summary>
/// The SQL command type.
Expand Down