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

Commit ab2e478

Browse files
committed
Now onto fixing async C# 6 errors
1 parent d6ec280 commit ab2e478

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

src/ServiceStack.OrmLite/Dapper/SqlMapper.Async.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static Task<T> QuerySingleOrDefaultAsync<T>(this IDbConnection cnn, strin
111111
/// </summary>
112112
public static Task<IEnumerable<object>> QueryAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
113113
{
114-
if (type == null) throw new ArgumentNullException(nameof(type));
114+
if (type == null) throw new ArgumentNullException("type");
115115
return QueryAsync<object>(cnn, type, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered, default(CancellationToken)));
116116
}
117117

@@ -120,31 +120,31 @@ public static Task<IEnumerable<object>> QueryAsync(this IDbConnection cnn, Type
120120
/// </summary>
121121
public static Task<object> QueryFirstAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
122122
{
123-
if (type == null) throw new ArgumentNullException(nameof(type));
123+
if (type == null) throw new ArgumentNullException("type");
124124
return QueryRowAsync<object>(cnn, Row.First, type, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
125125
}
126126
/// <summary>
127127
/// Execute a single-row query asynchronously using .NET 4.5 Task.
128128
/// </summary>
129129
public static Task<object> QueryFirstOrDefaultAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
130130
{
131-
if (type == null) throw new ArgumentNullException(nameof(type));
131+
if (type == null) throw new ArgumentNullException("type");
132132
return QueryRowAsync<object>(cnn, Row.FirstOrDefault, type, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
133133
}
134134
/// <summary>
135135
/// Execute a single-row query asynchronously using .NET 4.5 Task.
136136
/// </summary>
137137
public static Task<object> QuerySingleAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
138138
{
139-
if (type == null) throw new ArgumentNullException(nameof(type));
139+
if (type == null) throw new ArgumentNullException("type");
140140
return QueryRowAsync<object>(cnn, Row.Single, type, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
141141
}
142142
/// <summary>
143143
/// Execute a single-row query asynchronously using .NET 4.5 Task.
144144
/// </summary>
145145
public static Task<object> QuerySingleOrDefaultAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
146146
{
147-
if (type == null) throw new ArgumentNullException(nameof(type));
147+
if (type == null) throw new ArgumentNullException("type");
148148
return QueryRowAsync<object>(cnn, Row.SingleOrDefault, type, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
149149
}
150150

@@ -205,7 +205,7 @@ private static Task<DbDataReader> ExecuteReaderWithFlagsFallbackAsync(DbCommand
205205
private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn, Type effectiveType, CommandDefinition command)
206206
{
207207
object param = command.Parameters;
208-
var identity = new Identity(command.CommandText, command.CommandType, cnn, effectiveType, param?.GetType(), null);
208+
var identity = new Identity(command.CommandText, command.CommandType, cnn, effectiveType, param != null ? param.GetType() : null, null);
209209
var info = GetCacheInfo(identity, param, command.AddToCache);
210210
bool wasClosed = cnn.State == ConnectionState.Closed;
211211
var cancel = command.CancellationToken;
@@ -267,7 +267,7 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
267267
private static async Task<T> QueryRowAsync<T>(this IDbConnection cnn, Row row, Type effectiveType, CommandDefinition command)
268268
{
269269
object param = command.Parameters;
270-
var identity = new Identity(command.CommandText, command.CommandType, cnn, effectiveType, param?.GetType(), null);
270+
var identity = new Identity(command.CommandText, command.CommandType, cnn, effectiveType, param != null ? param.GetType() : null, null);
271271
var info = GetCacheInfo(identity, param, command.AddToCache);
272272
bool wasClosed = cnn.State == ConnectionState.Closed;
273273
var cancel = command.CancellationToken;
@@ -452,7 +452,7 @@ private static async Task<int> ExecuteMultiImplAsync(IDbConnection cnn, CommandD
452452
}
453453
private static async Task<int> ExecuteImplAsync(IDbConnection cnn, CommandDefinition command, object param)
454454
{
455-
var identity = new Identity(command.CommandText, command.CommandType, cnn, null, param?.GetType(), null);
455+
var identity = new Identity(command.CommandText, command.CommandType, cnn, null, param != null ? param.GetType() : null, null);
456456
var info = GetCacheInfo(identity, param, command.AddToCache);
457457
bool wasClosed = cnn.State == ConnectionState.Closed;
458458
using (var cmd = (DbCommand)command.SetupCommand(cnn, info.ParamReader))
@@ -645,7 +645,7 @@ public static Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TFo
645645
private static async Task<IEnumerable<TReturn>> MultiMapAsync<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(this IDbConnection cnn, CommandDefinition command, Delegate map, string splitOn)
646646
{
647647
object param = command.Parameters;
648-
var identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(TFirst), param?.GetType(), new[] { typeof(TFirst), typeof(TSecond), typeof(TThird), typeof(TFourth), typeof(TFifth), typeof(TSixth), typeof(TSeventh) });
648+
var identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(TFirst), param != null ? param.GetType() : null, new[] { typeof(TFirst), typeof(TSecond), typeof(TThird), typeof(TFourth), typeof(TFifth), typeof(TSixth), typeof(TSeventh) });
649649
var info = GetCacheInfo(identity, param, command.AddToCache);
650650
bool wasClosed = cnn.State == ConnectionState.Closed;
651651
try
@@ -693,7 +693,7 @@ private static async Task<IEnumerable<TReturn>> MultiMapAsync<TReturn>(this IDbC
693693
}
694694

695695
object param = command.Parameters;
696-
var identity = new Identity(command.CommandText, command.CommandType, cnn, types[0], param?.GetType(), types);
696+
var identity = new Identity(command.CommandText, command.CommandType, cnn, types[0], param != null ? param.GetType() : null, types);
697697
var info = GetCacheInfo(identity, param, command.AddToCache);
698698
bool wasClosed = cnn.State == ConnectionState.Closed;
699699
try {
@@ -718,7 +718,8 @@ private static IEnumerable<T> ExecuteReaderSync<T>(IDataReader reader, Func<IDat
718718
yield return (T)func(reader);
719719
}
720720
while (reader.NextResult()) { }
721-
(parameters as IParameterCallbacks)?.OnCompleted();
721+
var callbacks = parameters as IParameterCallbacks;
722+
if (callbacks != null) callbacks.OnCompleted();
722723
}
723724
}
724725

@@ -739,7 +740,7 @@ public static Task<GridReader> QueryMultipleAsync(
739740
public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn, CommandDefinition command)
740741
{
741742
object param = command.Parameters;
742-
Identity identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(GridReader), param?.GetType(), null);
743+
Identity identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(GridReader), param != null ? param.GetType() : null, null);
743744
CacheInfo info = GetCacheInfo(identity, param, command.AddToCache);
744745

745746
DbCommand cmd = null;
@@ -833,7 +834,7 @@ private static async Task<IDataReader> ExecuteReaderImplAsync(IDbConnection cnn,
833834
finally
834835
{
835836
if (wasClosed) cnn.Close();
836-
cmd?.Dispose();
837+
if (cmd != null) cmd.Dispose();
837838
}
838839
}
839840

@@ -903,7 +904,7 @@ private static async Task<T> ExecuteScalarImplAsync<T>(IDbConnection cnn, Comman
903904
finally
904905
{
905906
if (wasClosed) cnn.Close();
906-
cmd?.Dispose();
907+
if (cmd != null) cmd.Dispose();
907908
}
908909
return Parse<T>(result);
909910
}

src/ServiceStack.OrmLite/Dapper/SqlMapper.GridReader.Async.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Task<dynamic> ReadSingleOrDefaultAsync()
7272
/// </summary>
7373
public Task<IEnumerable<object>> ReadAsync(Type type, bool buffered = true)
7474
{
75-
if (type == null) throw new ArgumentNullException(nameof(type));
75+
if (type == null) throw new ArgumentNullException("type");
7676
return ReadAsyncImpl<object>(type, buffered);
7777
}
7878

@@ -81,31 +81,31 @@ public Task<IEnumerable<object>> ReadAsync(Type type, bool buffered = true)
8181
/// </summary>
8282
public Task<object> ReadFirstAsync(Type type)
8383
{
84-
if (type == null) throw new ArgumentNullException(nameof(type));
84+
if (type == null) throw new ArgumentNullException("type");
8585
return ReadRowAsyncImpl<object>(type, Row.First);
8686
}
8787
/// <summary>
8888
/// Read an individual row of the next grid of results
8989
/// </summary>
9090
public Task<object> ReadFirstOrDefaultAsync(Type type)
9191
{
92-
if (type == null) throw new ArgumentNullException(nameof(type));
92+
if (type == null) throw new ArgumentNullException("type");
9393
return ReadRowAsyncImpl<object>(type, Row.FirstOrDefault);
9494
}
9595
/// <summary>
9696
/// Read an individual row of the next grid of results
9797
/// </summary>
9898
public Task<object> ReadSingleAsync(Type type)
9999
{
100-
if (type == null) throw new ArgumentNullException(nameof(type));
100+
if (type == null) throw new ArgumentNullException("type");
101101
return ReadRowAsyncImpl<object>(type, Row.Single);
102102
}
103103
/// <summary>
104104
/// Read an individual row of the next grid of results
105105
/// </summary>
106106
public Task<object> ReadSingleOrDefaultAsync(Type type)
107107
{
108-
if (type == null) throw new ArgumentNullException(nameof(type));
108+
if (type == null) throw new ArgumentNullException("type");
109109
return ReadRowAsyncImpl<object>(type, Row.SingleOrDefault);
110110
}
111111

@@ -160,7 +160,7 @@ private async Task NextResultAsync()
160160
// need for "Cancel" etc
161161
reader.Dispose();
162162
reader = null;
163-
callbacks?.OnCompleted();
163+
if (callbacks != null) callbacks.OnCompleted();
164164
Dispose();
165165
}
166166
}
@@ -234,23 +234,23 @@ private async Task<T> ReadRowAsyncImplViaDbReader<T>(DbDataReader reader, Type t
234234

235235
private async Task<IEnumerable<T>> ReadBufferedAsync<T>(int index, Func<IDataReader, object> deserializer, Identity typedIdentity)
236236
{
237-
try
238-
{
237+
//try
238+
//{
239239
var reader = (DbDataReader)this.reader;
240240
List<T> buffer = new List<T>();
241241
while (index == gridIndex && await reader.ReadAsync(cancel).ConfigureAwait(false))
242242
{
243243
buffer.Add((T)deserializer(reader));
244244
}
245245
return buffer;
246-
}
247-
finally // finally so that First etc progresses things even when multiple rows
248-
{
249-
if (index == gridIndex)
250-
{
251-
await NextResultAsync().ConfigureAwait(false);
252-
}
253-
}
246+
//}
247+
//finally // finally so that First etc progresses things even when multiple rows
248+
//{
249+
// if (index == gridIndex)
250+
// {
251+
// await NextResultAsync().ConfigureAwait(false);
252+
// }
253+
//}
254254
}
255255
}
256256

0 commit comments

Comments
 (0)