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

Commit 440ab69

Browse files
committed
Convert latest C# 6 build errors to C# 5
1 parent e8abef7 commit 440ab69

15 files changed

+172
-157
lines changed

src/ServiceStack.OrmLite/Dapper/CommandDefinition.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,34 @@ internal static CommandDefinition ForCallback(object parameters)
3030

3131
internal void OnCompleted()
3232
{
33-
(Parameters as SqlMapper.IParameterCallbacks)?.OnCompleted();
33+
var p = Parameters as SqlMapper.IParameterCallbacks;
34+
if (p != null) p.OnCompleted();
3435
}
3536

3637
/// <summary>
3738
/// The command (sql or a stored-procedure name) to execute
3839
/// </summary>
39-
public string CommandText { get; set; }
40+
public string CommandText { get; private set; }
4041

4142
/// <summary>
4243
/// The parameters associated with the command
4344
/// </summary>
44-
public object Parameters { get; set; }
45+
public object Parameters { get; private set; }
4546

4647
/// <summary>
4748
/// The active transaction for the command
4849
/// </summary>
49-
public IDbTransaction Transaction { get; set; }
50+
public IDbTransaction Transaction { get; private set; }
5051

5152
/// <summary>
5253
/// The effective timeout for the command
5354
/// </summary>
54-
public int? CommandTimeout { get; set; }
55+
public int? CommandTimeout { get; private set; }
5556

5657
/// <summary>
5758
/// The type of command that the command-text represents
5859
/// </summary>
59-
public CommandType? CommandType { get; set; }
60+
public CommandType? CommandType { get; private set; }
6061

6162
/// <summary>
6263
/// Should data be buffered before returning?

src/ServiceStack.OrmLite/Dapper/CustomPropertyTypeMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public sealed class CustomPropertyTypeMap : SqlMapper.ITypeMap
2121
public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propertySelector)
2222
{
2323
if (type == null)
24-
throw new ArgumentNullException(nameof(type));
24+
throw new ArgumentNullException("type");
2525

2626
if (propertySelector == null)
27-
throw new ArgumentNullException(nameof(propertySelector));
27+
throw new ArgumentNullException("propertySelector");
2828

2929
_type = type;
3030
_propertySelector = propertySelector;

src/ServiceStack.OrmLite/Dapper/DynamicParameters.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
274274
p.DbType = dbType.Value;
275275
}
276276
var s = val as string;
277-
if (s?.Length <= DbString.DefaultLength)
277+
if ((s != null ? s.Length : (int?) null) <= DbString.DefaultLength)
278278
{
279279
p.Size = DbString.DefaultLength;
280280
}
@@ -377,11 +377,11 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
377377
{
378378
// Insert the names in the right order so expression
379379
// "Post.Author.Name" becomes parameter "PostAuthorName"
380-
names.Insert(0, diving?.Member.Name);
380+
names.Insert(0, diving != null ? diving.Member.Name : null);
381381
chain.Insert(0, diving);
382382

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

386386
if (constant != null &&
387387
constant.Type == typeof(T))
@@ -462,7 +462,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
462462
{
463463
// Finally, prep the parameter and attach the callback to it
464464
ParamInfo parameter;
465-
var targetMemberType = lastMemberAccess?.Type;
465+
var targetMemberType = lastMemberAccess != null ? lastMemberAccess.Type : null;
466466
int sizeToSet = (!size.HasValue && targetMemberType == typeof(string)) ? DbString.DefaultLength : size ?? 0;
467467

468468
if (parameters.TryGetValue(dynamicParamName, out parameter))
@@ -479,7 +479,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
479479
SqlMapper.ITypeHandler handler;
480480
dbType = (!dbType.HasValue)
481481
#pragma warning disable 618
482-
? SqlMapper.LookupDbType(targetMemberType, targetMemberType?.Name, true, out handler)
482+
? SqlMapper.LookupDbType(targetMemberType, targetMemberType != null ? targetMemberType.Name : null, true, out handler)
483483
#pragma warning restore 618
484484
: dbType;
485485

@@ -502,7 +502,7 @@ void SqlMapper.IParameterCallbacks.OnCompleted()
502502
{
503503
foreach (var param in (from p in parameters select p.Value))
504504
{
505-
param.OutputCallback?.Invoke(param.OutputTarget, this);
505+
if (param.OutputCallback != null) param.OutputCallback(param.OutputTarget, this);
506506
}
507507
}
508508
}

src/ServiceStack.OrmLite/Dapper/FeatureSupport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private static readonly FeatureSupport
1818
/// </summary>
1919
public static FeatureSupport Get(IDbConnection connection)
2020
{
21-
string name = connection?.GetType().Name;
21+
string name = connection != null ? connection.GetType().Name : null;
2222
if (string.Equals(name, "npgsqlconnection", StringComparison.OrdinalIgnoreCase)) return Postgres;
2323
return Default;
2424
}

src/ServiceStack.OrmLite/Dapper/SimpleMemberMap.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ sealed class SimpleMemberMap : SqlMapper.IMemberMap
1717
public SimpleMemberMap(string columnName, PropertyInfo property)
1818
{
1919
if (columnName == null)
20-
throw new ArgumentNullException(nameof(columnName));
20+
throw new ArgumentNullException("columnName");
2121

2222
if (property == null)
23-
throw new ArgumentNullException(nameof(property));
23+
throw new ArgumentNullException("property");
2424

2525
ColumnName = columnName;
2626
Property = property;
@@ -34,10 +34,10 @@ public SimpleMemberMap(string columnName, PropertyInfo property)
3434
public SimpleMemberMap(string columnName, FieldInfo field)
3535
{
3636
if (columnName == null)
37-
throw new ArgumentNullException(nameof(columnName));
37+
throw new ArgumentNullException("columnName");
3838

3939
if (field == null)
40-
throw new ArgumentNullException(nameof(field));
40+
throw new ArgumentNullException("field");
4141

4242
ColumnName = columnName;
4343
Field = field;
@@ -51,10 +51,10 @@ public SimpleMemberMap(string columnName, FieldInfo field)
5151
public SimpleMemberMap(string columnName, ParameterInfo parameter)
5252
{
5353
if (columnName == null)
54-
throw new ArgumentNullException(nameof(columnName));
54+
throw new ArgumentNullException("columnName");
5555

5656
if (parameter == null)
57-
throw new ArgumentNullException(nameof(parameter));
57+
throw new ArgumentNullException("parameter");
5858

5959
ColumnName = columnName;
6060
Parameter = parameter;

src/ServiceStack.OrmLite/Dapper/SqlDataRecordListTVPParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public SqlDataRecordListTVPParameter(IEnumerable<Microsoft.SqlServer.Server.SqlD
2424
static readonly Action<System.Data.SqlClient.SqlParameter, string> setTypeName;
2525
static SqlDataRecordListTVPParameter()
2626
{
27-
var prop = typeof(System.Data.SqlClient.SqlParameter).GetProperty(nameof(System.Data.SqlClient.SqlParameter.TypeName), BindingFlags.Instance | BindingFlags.Public);
27+
var prop = typeof(System.Data.SqlClient.SqlParameter).GetProperty("TypeName", BindingFlags.Instance | BindingFlags.Public);
2828
if (prop != null && prop.PropertyType == typeof(string) && prop.CanWrite)
2929
{
3030
setTypeName = (Action<System.Data.SqlClient.SqlParameter, string>)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ private sealed class DapperRow
1717

1818
public DapperRow(DapperTable table, object[] values)
1919
{
20-
if (table == null) throw new ArgumentNullException(nameof(table));
21-
if (values == null) throw new ArgumentNullException(nameof(values));
20+
if (table == null) throw new ArgumentNullException("table");
21+
if (values == null) throw new ArgumentNullException("values");
2222
this.table = table;
2323
this.values = values;
2424
}
@@ -178,7 +178,7 @@ public object SetValue(string key, object value)
178178

179179
private object SetValue(string key, object value, bool isAdd)
180180
{
181-
if (key == null) throw new ArgumentNullException(nameof(key));
181+
if (key == null) throw new ArgumentNullException("key");
182182
int index = table.IndexOfName(key);
183183
if (index < 0)
184184
{
@@ -187,7 +187,7 @@ private object SetValue(string key, object value, bool isAdd)
187187
else if (isAdd && index < values.Length && !(values[index] is DeadValue))
188188
{
189189
// then semantically, this value already exists
190-
throw new ArgumentException("An item with the same key has already been added", nameof(key));
190+
throw new ArgumentException("An item with the same key has already been added", "key");
191191
}
192192
int oldLength = values.Length;
193193
if (oldLength <= index)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal string[] FieldNames
1818

1919
public DapperTable(string[] fieldNames)
2020
{
21-
if (fieldNames == null) throw new ArgumentNullException(nameof(fieldNames));
21+
if (fieldNames == null) throw new ArgumentNullException("fieldNames");
2222
this.fieldNames = fieldNames;
2323

2424
fieldNameLookup = new Dictionary<string, int>(fieldNames.Length, StringComparer.Ordinal);
@@ -37,7 +37,7 @@ internal int IndexOfName(string name)
3737
}
3838
internal int AddField(string name)
3939
{
40-
if (name == null) throw new ArgumentNullException(nameof(name));
40+
if (name == null) throw new ArgumentNullException("name");
4141
if (fieldNameLookup.ContainsKey(name)) throw new InvalidOperationException("Field already exists: " + name);
4242
int oldLen = fieldNames.Length;
4343
Array.Resize(ref fieldNames, oldLen + 1); // yes, this is sub-optimal, but this is not the expected common case

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public T ReadSingleOrDefault<T>()
110110
/// </summary>
111111
public IEnumerable<object> Read(Type type, bool buffered = true)
112112
{
113-
if (type == null) throw new ArgumentNullException(nameof(type));
113+
if (type == null) throw new ArgumentNullException("type");
114114
return ReadImpl<object>(type, buffered);
115115
}
116116

@@ -119,31 +119,31 @@ public IEnumerable<object> Read(Type type, bool buffered = true)
119119
/// </summary>
120120
public object ReadFirst(Type type)
121121
{
122-
if (type == null) throw new ArgumentNullException(nameof(type));
122+
if (type == null) throw new ArgumentNullException("type");
123123
return ReadRow<object>(type, Row.First);
124124
}
125125
/// <summary>
126126
/// Read an individual row of the next grid of results
127127
/// </summary>
128128
public object ReadFirstOrDefault(Type type)
129129
{
130-
if (type == null) throw new ArgumentNullException(nameof(type));
130+
if (type == null) throw new ArgumentNullException("type");
131131
return ReadRow<object>(type, Row.FirstOrDefault);
132132
}
133133
/// <summary>
134134
/// Read an individual row of the next grid of results
135135
/// </summary>
136136
public object ReadSingle(Type type)
137137
{
138-
if (type == null) throw new ArgumentNullException(nameof(type));
138+
if (type == null) throw new ArgumentNullException("type");
139139
return ReadRow<object>(type, Row.Single);
140140
}
141141
/// <summary>
142142
/// Read an individual row of the next grid of results
143143
/// </summary>
144144
public object ReadSingleOrDefault(Type type)
145145
{
146-
if (type == null) throw new ArgumentNullException(nameof(type));
146+
if (type == null) throw new ArgumentNullException("type");
147147
return ReadRow<object>(type, Row.SingleOrDefault);
148148
}
149149

@@ -356,7 +356,7 @@ private void NextResult()
356356
// need for "Cancel" etc
357357
reader.Dispose();
358358
reader = null;
359-
callbacks?.OnCompleted();
359+
if (callbacks != null) callbacks.OnCompleted();
360360
Dispose();
361361
}
362362
}
@@ -367,7 +367,7 @@ public void Dispose()
367367
{
368368
if (reader != null)
369369
{
370-
if (!reader.IsClosed) Command?.Cancel();
370+
if (!reader.IsClosed) if (Command != null) Command.Cancel();
371371
reader.Dispose();
372372
reader = null;
373373
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ private Identity(string sql, CommandType? commandType, string connectionString,
4646
hashCode = 17; // we *know* we are using this in a dictionary, so pre-compute this
4747
hashCode = hashCode * 23 + commandType.GetHashCode();
4848
hashCode = hashCode * 23 + gridIndex.GetHashCode();
49-
hashCode = hashCode * 23 + (sql?.GetHashCode() ?? 0);
50-
hashCode = hashCode * 23 + (type?.GetHashCode() ?? 0);
49+
hashCode = hashCode * 23 + (sql != null ? sql.GetHashCode() : 0);
50+
hashCode = hashCode * 23 + (type != null ? type.GetHashCode() : 0);
5151
if (otherTypes != null)
5252
{
5353
foreach (var t in otherTypes)
5454
{
55-
hashCode = hashCode * 23 + (t?.GetHashCode() ?? 0);
55+
hashCode = hashCode * 23 + (t != null ? t.GetHashCode() : 0);
5656
}
5757
}
5858
hashCode = hashCode * 23 + (connectionString == null ? 0 : connectionStringComparer.GetHashCode(connectionString));
59-
hashCode = hashCode * 23 + (parametersType?.GetHashCode() ?? 0);
59+
hashCode = hashCode * 23 + (parametersType != null ? parametersType.GetHashCode() : 0);
6060
}
6161
}
6262

0 commit comments

Comments
 (0)