Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit e5ab084

Browse files
committed
Upgrade embedded Dapper to latest version
1 parent aef70a8 commit e5ab084

Some content is hidden

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

45 files changed

+2133
-1670
lines changed

src/ServiceStack.OrmLite/Dapper/CommandDefinition.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ internal void OnCompleted()
7676
/// <summary>
7777
/// Initialize the command definition
7878
/// </summary>
79+
/// <param name="commandText">The text for this command.</param>
80+
/// <param name="parameters">The parameters for this command.</param>
81+
/// <param name="transaction">The transaction for this command to participate in.</param>
82+
/// <param name="commandTimeout">The timeout (in seconds) for this command.</param>
83+
/// <param name="commandType">The <see cref="CommandType"/> for this command.</param>
84+
/// <param name="flags">The behavior flags for this command.</param>
85+
/// <param name="cancellationToken">The cancellation token for this command.</param>
7986
public CommandDefinition(string commandText, object parameters = null, IDbTransaction transaction = null, int? commandTimeout = null,
8087
CommandType? commandType = null, CommandFlags flags = CommandFlags.Buffered
81-
#if ASYNC
8288
, CancellationToken cancellationToken = default(CancellationToken)
83-
#endif
8489
)
8590
{
8691
CommandText = commandText;
@@ -89,23 +94,18 @@ public CommandDefinition(string commandText, object parameters = null, IDbTransa
8994
CommandTimeout = commandTimeout;
9095
CommandType = commandType;
9196
Flags = flags;
92-
#if ASYNC
9397
CancellationToken = cancellationToken;
94-
#endif
9598
}
9699

97100
private CommandDefinition(object parameters) : this()
98101
{
99102
Parameters = parameters;
100103
}
101104

102-
#if ASYNC
103-
104105
/// <summary>
105106
/// For asynchronous operations, the cancellation-token
106107
/// </summary>
107108
public CancellationToken CancellationToken { get; }
108-
#endif
109109

110110
internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> paramReader)
111111
{
@@ -135,8 +135,7 @@ private static Action<IDbCommand> GetInit(Type commandType)
135135
{
136136
if (commandType == null)
137137
return null; // GIGO
138-
Action<IDbCommand> action;
139-
if (SqlMapper.Link<Type, Action<IDbCommand>>.TryGet(commandInitCache, commandType, out action))
138+
if (SqlMapper.Link<Type, Action<IDbCommand>>.TryGet(commandInitCache, commandType, out Action<IDbCommand> action))
140139
{
141140
return action;
142141
}
@@ -176,12 +175,11 @@ private static Action<IDbCommand> GetInit(Type commandType)
176175
private static MethodInfo GetBasicPropertySetter(Type declaringType, string name, Type expectedType)
177176
{
178177
var prop = declaringType.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
179-
if (prop != null && prop.CanWrite && prop.PropertyType == expectedType && prop.GetIndexParameters().Length == 0)
178+
if (prop?.CanWrite == true && prop.PropertyType == expectedType && prop.GetIndexParameters().Length == 0)
180179
{
181180
return prop.GetSetMethod();
182181
}
183182
return null;
184183
}
185184
}
186-
187185
}

src/ServiceStack.OrmLite/Dapper/CommandFlags.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace ServiceStack.OrmLite.Dapper
44
{
5-
65
/// <summary>
76
/// Additional state flags that control command behaviour
87
/// </summary>
@@ -26,5 +25,4 @@ public enum CommandFlags
2625
/// </summary>
2726
NoCache = 4,
2827
}
29-
3028
}

src/ServiceStack.OrmLite/Dapper/CustomPropertyTypeMap.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace ServiceStack.OrmLite.Dapper
55
{
6-
76
/// <summary>
87
/// Implements custom property mapping by user provided criteria (usually presence of some custom attribute with column to member mapping)
98
/// </summary>
@@ -19,14 +18,8 @@ public sealed class CustomPropertyTypeMap : SqlMapper.ITypeMap
1918
/// <param name="propertySelector">Property selector based on target type and DataReader column name</param>
2019
public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propertySelector)
2120
{
22-
if (type == null)
23-
throw new ArgumentNullException(nameof(type));
24-
25-
if (propertySelector == null)
26-
throw new ArgumentNullException(nameof(propertySelector));
27-
28-
_type = type;
29-
_propertySelector = propertySelector;
21+
_type = type ?? throw new ArgumentNullException(nameof(type));
22+
_propertySelector = propertySelector ?? throw new ArgumentNullException(nameof(propertySelector));
3023
}
3124

3225
/// <summary>
@@ -35,19 +28,14 @@ public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propert
3528
/// <param name="names">DataReader column names</param>
3629
/// <param name="types">DataReader column types</param>
3730
/// <returns>Default constructor</returns>
38-
public ConstructorInfo FindConstructor(string[] names, Type[] types)
39-
{
40-
return _type.GetConstructor(new Type[0]);
41-
}
31+
public ConstructorInfo FindConstructor(string[] names, Type[] types) =>
32+
_type.GetConstructor(new Type[0]);
4233

4334
/// <summary>
4435
/// Always returns null
4536
/// </summary>
4637
/// <returns></returns>
47-
public ConstructorInfo FindExplicitConstructor()
48-
{
49-
return null;
50-
}
38+
public ConstructorInfo FindExplicitConstructor() => null;
5139

5240
/// <summary>
5341
/// Not implemented as far as default constructor used for all cases

src/ServiceStack.OrmLite/Dapper/DataTableHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Data;
3-
#if !NETSTANDARD2_0
3+
#if !NETSTANDARD1_3
44
namespace ServiceStack.OrmLite.Dapper
55
{
6-
sealed class DataTableHandler : SqlMapper.ITypeHandler
6+
internal sealed class DataTableHandler : SqlMapper.ITypeHandler
77
{
88
public object Parse(Type destinationType, object value)
99
{

src/ServiceStack.OrmLite/Dapper/DbString.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,17 @@ public void AddParameter(IDbCommand command, string name)
5555
{
5656
throw new InvalidOperationException("If specifying IsFixedLength, a Length must also be specified");
5757
}
58-
var param = command.CreateParameter();
59-
param.ParameterName = name;
58+
bool add = !command.Parameters.Contains(name);
59+
IDbDataParameter param;
60+
if (add)
61+
{
62+
param = command.CreateParameter();
63+
param.ParameterName = name;
64+
}
65+
else
66+
{
67+
param = (IDbDataParameter)command.Parameters[name];
68+
}
6069
#pragma warning disable 0618
6170
param.Value = SqlMapper.SanitizeParameterValue(Value);
6271
#pragma warning restore 0618
@@ -69,7 +78,10 @@ public void AddParameter(IDbCommand command, string name)
6978
param.Size = Length;
7079
}
7180
param.DbType = IsAnsi ? (IsFixedLength ? DbType.AnsiStringFixedLength : DbType.AnsiString) : (IsFixedLength ? DbType.StringFixedLength : DbType.String);
72-
command.Parameters.Add(param);
81+
if (add)
82+
{
83+
command.Parameters.Add(param);
84+
}
7385
}
7486
}
7587
}

src/ServiceStack.OrmLite/Dapper/DefaultTypeMap.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public DefaultTypeMap(Type type)
2626
Properties = GetSettableProps(type);
2727
_type = type;
2828
}
29-
#if NETSTANDARD2_0
30-
static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
29+
#if NETSTANDARD1_3
30+
private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
3131
{
3232
if (ReferenceEquals(x, y)) return true;
3333
if (x == null || y == null) return false;
@@ -40,7 +40,7 @@ static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
4040
internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type type)
4141
{
4242
if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);
43-
#if NETSTANDARD2_0
43+
#if NETSTANDARD1_3
4444
return propertyInfo.DeclaringType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
4545
.Single(x => x.Name == propertyInfo.Name
4646
&& x.PropertyType == propertyInfo.PropertyType
@@ -91,15 +91,15 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
9191
int i = 0;
9292
for (; i < ctorParameters.Length; i++)
9393
{
94-
if (!String.Equals(ctorParameters[i].Name, names[i], StringComparison.OrdinalIgnoreCase))
94+
if (!string.Equals(ctorParameters[i].Name, names[i], StringComparison.OrdinalIgnoreCase))
9595
break;
9696
if (types[i] == typeof(byte[]) && ctorParameters[i].ParameterType.FullName == SqlMapper.LinqBinary)
9797
continue;
9898
var unboxedType = Nullable.GetUnderlyingType(ctorParameters[i].ParameterType) ?? ctorParameters[i].ParameterType;
9999
if ((unboxedType != types[i] && !SqlMapper.HasTypeHandler(unboxedType))
100-
&& !(unboxedType.IsEnum && Enum.GetUnderlyingType(unboxedType) == types[i])
100+
&& !(unboxedType.IsEnum() && Enum.GetUnderlyingType(unboxedType) == types[i])
101101
&& !(unboxedType == typeof(char) && types[i] == typeof(string))
102-
&& !(unboxedType.IsEnum && types[i] == typeof(string)))
102+
&& !(unboxedType.IsEnum() && types[i] == typeof(string)))
103103
{
104104
break;
105105
}
@@ -118,7 +118,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
118118
public ConstructorInfo FindExplicitConstructor()
119119
{
120120
var constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
121-
#if NETSTANDARD2_0
121+
#if NETSTANDARD1_3
122122
var withAttr = constructors.Where(c => c.CustomAttributes.Any(x => x.AttributeType == typeof(ExplicitConstructorAttribute))).ToList();
123123
#else
124124
var withAttr = constructors.Where(c => c.GetCustomAttributes(typeof(ExplicitConstructorAttribute), true).Length > 0).ToList();
@@ -152,13 +152,13 @@ public SqlMapper.IMemberMap GetConstructorParameter(ConstructorInfo constructor,
152152
/// <returns>Mapping implementation</returns>
153153
public SqlMapper.IMemberMap GetMember(string columnName)
154154
{
155-
var property = Properties.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
156-
?? Properties.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase));
155+
var property = Properties.Find(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
156+
?? Properties.Find(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase));
157157

158158
if (property == null && MatchNamesWithUnderscores)
159159
{
160-
property = Properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
161-
?? Properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
160+
property = Properties.Find(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
161+
?? Properties.Find(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
162162
}
163163

164164
if (property != null)
@@ -169,20 +169,20 @@ public SqlMapper.IMemberMap GetMember(string columnName)
169169

170170
// preference order is:
171171
// exact match over underscre match, exact case over wrong case, backing fields over regular fields, match-inc-underscores over match-exc-underscores
172-
var field = _fields.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
173-
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
174-
?? _fields.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase))
175-
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
172+
var field = _fields.Find(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
173+
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
174+
?? _fields.Find(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase))
175+
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
176176

177177
if (field == null && MatchNamesWithUnderscores)
178178
{
179179
var effectiveColumnName = columnName.Replace("_", "");
180-
backingFieldName = "<" +effectiveColumnName + ">k__BackingField";
180+
backingFieldName = "<" + effectiveColumnName + ">k__BackingField";
181181

182-
field = _fields.FirstOrDefault(p => string.Equals(p.Name, effectiveColumnName, StringComparison.Ordinal))
183-
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
184-
?? _fields.FirstOrDefault(p => string.Equals(p.Name, effectiveColumnName, StringComparison.OrdinalIgnoreCase))
185-
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
182+
field = _fields.Find(p => string.Equals(p.Name, effectiveColumnName, StringComparison.Ordinal))
183+
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
184+
?? _fields.Find(p => string.Equals(p.Name, effectiveColumnName, StringComparison.OrdinalIgnoreCase))
185+
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
186186
}
187187

188188
if (field != null)

src/ServiceStack.OrmLite/Dapper/DynamicParameters.CachedOutputSetters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ServiceStack.OrmLite.Dapper
44
{
5-
partial class DynamicParameters
5+
public partial class DynamicParameters
66
{
77
// The type here is used to differentiate the cache by type via generics
88
// ReSharper disable once UnusedTypeParameter

src/ServiceStack.OrmLite/Dapper/DynamicParameters.ParamInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace ServiceStack.OrmLite.Dapper
55
{
6-
partial class DynamicParameters
6+
public partial class DynamicParameters
77
{
8-
sealed class ParamInfo
8+
private sealed class ParamInfo
99
{
1010
public string Name { get; set; }
1111
public object Value { get; set; }

0 commit comments

Comments
 (0)