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

Commit c3fcc36

Browse files
committed
Upgrade to latest C# 6 version of Dapper
1 parent ce28a89 commit c3fcc36

Some content is hidden

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

46 files changed

+381
-403
lines changed

src/ServiceStack.OrmLite/Dapper/CommandDefinition.cs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
#if ASYNC
2-
#define ASYNC
3-
#endif
4-
5-
using System;
1+
using System;
62
using System.Data;
73
using System.Reflection;
84
using System.Reflection.Emit;
95
using System.Threading;
106

11-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
127
namespace ServiceStack.OrmLite.Dapper
138
{
149
/// <summary>
@@ -30,63 +25,53 @@ internal static CommandDefinition ForCallback(object parameters)
3025

3126
internal void OnCompleted()
3227
{
33-
var p = Parameters as SqlMapper.IParameterCallbacks;
34-
if (p != null) p.OnCompleted();
28+
(Parameters as SqlMapper.IParameterCallbacks)?.OnCompleted();
3529
}
3630

3731
/// <summary>
3832
/// The command (sql or a stored-procedure name) to execute
3933
/// </summary>
40-
public string CommandText { get; private set; }
34+
public string CommandText { get; }
4135

4236
/// <summary>
4337
/// The parameters associated with the command
4438
/// </summary>
45-
public object Parameters { get; private set; }
39+
public object Parameters { get; }
4640

4741
/// <summary>
4842
/// The active transaction for the command
4943
/// </summary>
50-
public IDbTransaction Transaction { get; private set; }
44+
public IDbTransaction Transaction { get; }
5145

5246
/// <summary>
5347
/// The effective timeout for the command
5448
/// </summary>
55-
public int? CommandTimeout { get; private set; }
49+
public int? CommandTimeout { get; }
5650

5751
/// <summary>
5852
/// The type of command that the command-text represents
5953
/// </summary>
60-
public CommandType? CommandType { get; private set; }
54+
public CommandType? CommandType { get; }
6155

6256
/// <summary>
6357
/// Should data be buffered before returning?
6458
/// </summary>
65-
public bool Buffered
66-
{
67-
get { return (Flags & CommandFlags.Buffered) != 0; }
68-
}
59+
public bool Buffered => (Flags & CommandFlags.Buffered) != 0;
6960

7061
/// <summary>
7162
/// Should the plan for this query be cached?
7263
/// </summary>
73-
internal bool AddToCache
74-
{
75-
get { return (Flags & CommandFlags.NoCache) == 0; }
76-
}
64+
internal bool AddToCache => (Flags & CommandFlags.NoCache) == 0;
7765

7866
/// <summary>
7967
/// Additional state flags against this command
8068
/// </summary>
81-
public CommandFlags Flags { get; set; }
69+
public CommandFlags Flags { get; }
8270

8371
/// <summary>
8472
/// Can async queries be pipelined?
8573
/// </summary>
86-
public bool Pipelined
87-
{
88-
get { return (Flags & CommandFlags.Pipelined) != 0; }
89-
}
74+
public bool Pipelined => (Flags & CommandFlags.Pipelined) != 0;
9075

9176
/// <summary>
9277
/// Initialize the command definition
@@ -96,7 +81,7 @@ public CommandDefinition(string commandText, object parameters = null, IDbTransa
9681
#if ASYNC
9782
, CancellationToken cancellationToken = default(CancellationToken)
9883
#endif
99-
) : this()
84+
)
10085
{
10186
CommandText = commandText;
10287
Parameters = parameters;
@@ -119,14 +104,14 @@ private CommandDefinition(object parameters) : this()
119104
/// <summary>
120105
/// For asynchronous operations, the cancellation-token
121106
/// </summary>
122-
public CancellationToken CancellationToken { get; private set; }
107+
public CancellationToken CancellationToken { get; }
123108
#endif
124109

125110
internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> paramReader)
126111
{
127112
var cmd = cnn.CreateCommand();
128113
var init = GetInit(cmd.GetType());
129-
if (init != null) init(cmd);
114+
init?.Invoke(cmd);
130115
if (Transaction != null)
131116
cmd.Transaction = Transaction;
132117
cmd.CommandText = CommandText;
@@ -140,7 +125,7 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> p
140125
}
141126
if (CommandType.HasValue)
142127
cmd.CommandType = CommandType.Value;
143-
if (paramReader != null) paramReader(cmd, Parameters);
128+
paramReader?.Invoke(cmd, Parameters);
144129
return cmd;
145130
}
146131

src/ServiceStack.OrmLite/Dapper/CommandFlags.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22

3-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
43
namespace ServiceStack.OrmLite.Dapper
54
{
65

src/ServiceStack.OrmLite/Dapper/CustomPropertyTypeMap.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Reflection;
33

4-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
54
namespace ServiceStack.OrmLite.Dapper
65
{
76

@@ -21,10 +20,10 @@ public sealed class CustomPropertyTypeMap : SqlMapper.ITypeMap
2120
public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propertySelector)
2221
{
2322
if (type == null)
24-
throw new ArgumentNullException("type");
23+
throw new ArgumentNullException(nameof(type));
2524

2625
if (propertySelector == null)
27-
throw new ArgumentNullException("propertySelector");
26+
throw new ArgumentNullException(nameof(propertySelector));
2827

2928
_type = type;
3029
_propertySelector = propertySelector;

src/ServiceStack.OrmLite/Dapper/DataTableHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.Data;
3-
43
#if !COREFX
5-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
64
namespace ServiceStack.OrmLite.Dapper
75
{
86
sealed class DataTableHandler : SqlMapper.ITypeHandler

src/ServiceStack.OrmLite/Dapper/DbString.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Data;
33

4-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
54
namespace ServiceStack.OrmLite.Dapper
65
{
76
/// <summary>

src/ServiceStack.OrmLite/Dapper/DefaultTypeMap.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Reflection;
55

6-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
76
namespace ServiceStack.OrmLite.Dapper
87
{
98
/// <summary>
@@ -21,7 +20,7 @@ public sealed class DefaultTypeMap : SqlMapper.ITypeMap
2120
public DefaultTypeMap(Type type)
2221
{
2322
if (type == null)
24-
throw new ArgumentNullException("type");
23+
throw new ArgumentNullException(nameof(type));
2524

2625
_fields = GetSettableFields(type);
2726
Properties = GetSettableProps(type);
@@ -166,7 +165,7 @@ public SqlMapper.IMemberMap GetMember(string columnName)
166165
return new SimpleMemberMap(columnName, property);
167166

168167
// roslyn automatically implemented properties, in particular for get-only properties: <{Name}>k__BackingField;
169-
var backingFieldName = String.Format("<{0}>k__BackingField", columnName);
168+
var backingFieldName = "<" + columnName + ">k__BackingField";
170169

171170
// preference order is:
172171
// exact match over underscre match, exact case over wrong case, backing fields over regular fields, match-inc-underscores over match-exc-underscores
@@ -178,7 +177,7 @@ public SqlMapper.IMemberMap GetMember(string columnName)
178177
if (field == null && MatchNamesWithUnderscores)
179178
{
180179
var effectiveColumnName = columnName.Replace("_", "");
181-
backingFieldName = String.Format("<{0}>k__BackingField", effectiveColumnName);
180+
backingFieldName = "<" +effectiveColumnName + ">k__BackingField";
182181

183182
field = _fields.FirstOrDefault(p => string.Equals(p.Name, effectiveColumnName, StringComparison.Ordinal))
184183
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
@@ -199,6 +198,6 @@ public SqlMapper.IMemberMap GetMember(string columnName)
199198
/// <summary>
200199
/// The settable properties for this typemap
201200
/// </summary>
202-
public List<PropertyInfo> Properties { get; set; }
201+
public List<PropertyInfo> Properties { get; }
203202
}
204203
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections;
22

3-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
43
namespace ServiceStack.OrmLite.Dapper
54
{
65
partial class DynamicParameters

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Data;
33

4-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
54
namespace ServiceStack.OrmLite.Dapper
65
{
76
partial class DynamicParameters

src/ServiceStack.OrmLite/Dapper/DynamicParameters.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using ApplicationException = System.InvalidOperationException;
1111
#endif
1212

13-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
1413
namespace ServiceStack.OrmLite.Dapper
1514
{
1615

@@ -274,7 +273,7 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
274273
p.DbType = dbType.Value;
275274
}
276275
var s = val as string;
277-
if ((s != null ? s.Length : (int?) null) <= DbString.DefaultLength)
276+
if (s?.Length <= DbString.DefaultLength)
278277
{
279278
p.Size = DbString.DefaultLength;
280279
}
@@ -306,10 +305,7 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
306305
/// <summary>
307306
/// All the names of the param in the bag, use Get to yank them out
308307
/// </summary>
309-
public IEnumerable<string> ParameterNames
310-
{
311-
get { return parameters.Select(p => p.Key); }
312-
}
308+
public IEnumerable<string> ParameterNames => parameters.Select(p => p.Key);
313309

314310

315311
/// <summary>
@@ -377,11 +373,11 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
377373
{
378374
// Insert the names in the right order so expression
379375
// "Post.Author.Name" becomes parameter "PostAuthorName"
380-
names.Insert(0, diving != null ? diving.Member.Name : null);
376+
names.Insert(0, diving?.Member.Name);
381377
chain.Insert(0, diving);
382378

383-
var constant = diving != null ? diving.Expression as ParameterExpression : null;
384-
diving = diving != null ? diving.Expression as MemberExpression : null;
379+
var constant = diving?.Expression as ParameterExpression;
380+
diving = diving?.Expression as MemberExpression;
385381

386382
if (constant != null &&
387383
constant.Type == typeof(T))
@@ -407,7 +403,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
407403
if (setter != null) goto MAKECALLBACK;
408404

409405
// Come on let's build a method, let's build it, let's build it now!
410-
var dm = new DynamicMethod(String.Format("ExpressionParam{0}", Guid.NewGuid()), null, new[] { typeof(object), GetType() }, true);
406+
var dm = new DynamicMethod("ExpressionParam" + Guid.NewGuid().ToString(), null, new[] { typeof(object), GetType() }, true);
411407
var il = dm.GetILGenerator();
412408

413409
il.Emit(OpCodes.Ldarg_0); // [object]
@@ -462,7 +458,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
462458
{
463459
// Finally, prep the parameter and attach the callback to it
464460
ParamInfo parameter;
465-
var targetMemberType = lastMemberAccess != null ? lastMemberAccess.Type : null;
461+
var targetMemberType = lastMemberAccess?.Type;
466462
int sizeToSet = (!size.HasValue && targetMemberType == typeof(string)) ? DbString.DefaultLength : size ?? 0;
467463

468464
if (parameters.TryGetValue(dynamicParamName, out parameter))
@@ -479,7 +475,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
479475
SqlMapper.ITypeHandler handler;
480476
dbType = (!dbType.HasValue)
481477
#pragma warning disable 618
482-
? SqlMapper.LookupDbType(targetMemberType, targetMemberType != null ? targetMemberType.Name : null, true, out handler)
478+
? SqlMapper.LookupDbType(targetMemberType, targetMemberType?.Name, true, out handler)
483479
#pragma warning restore 618
484480
: dbType;
485481

@@ -502,7 +498,7 @@ void SqlMapper.IParameterCallbacks.OnCompleted()
502498
{
503499
foreach (var param in (from p in parameters select p.Value))
504500
{
505-
if (param.OutputCallback != null) param.OutputCallback(param.OutputTarget, this);
501+
param.OutputCallback?.Invoke(param.OutputTarget, this);
506502
}
507503
}
508504
}

src/ServiceStack.OrmLite/Dapper/ExplicitConstructorAttribute.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22

3-
//Apache 2.0 License: https://github.com/StackExchange/dapper-dot-net/blob/master/License.txt
43
namespace ServiceStack.OrmLite.Dapper
54
{
65
/// <summary>

0 commit comments

Comments
 (0)