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

Commit 59f2dc1

Browse files
committed
Convert latest Dapper to use C# 5 so builds on CI
1 parent 55129bc commit 59f2dc1

File tree

9 files changed

+81
-25
lines changed

9 files changed

+81
-25
lines changed

src/ServiceStack.OrmLite/Dapper/CommandDefinition.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,18 @@ internal void OnCompleted()
6161
/// <summary>
6262
/// Should data be buffered before returning?
6363
/// </summary>
64-
public bool Buffered => (Flags & CommandFlags.Buffered) != 0;
64+
public bool Buffered
65+
{
66+
get { return (Flags & CommandFlags.Buffered) != 0; }
67+
}
6568

6669
/// <summary>
6770
/// Should the plan for this query be cached?
6871
/// </summary>
69-
internal bool AddToCache => (Flags & CommandFlags.NoCache) == 0;
72+
internal bool AddToCache
73+
{
74+
get { return (Flags & CommandFlags.NoCache) == 0; }
75+
}
7076

7177
/// <summary>
7278
/// Additional state flags against this command
@@ -76,7 +82,10 @@ internal void OnCompleted()
7682
/// <summary>
7783
/// Can async queries be pipelined?
7884
/// </summary>
79-
public bool Pipelined => (Flags & CommandFlags.Pipelined) != 0;
85+
public bool Pipelined
86+
{
87+
get { return (Flags & CommandFlags.Pipelined) != 0; }
88+
}
8089

8190
/// <summary>
8291
/// Initialize the command definition

src/ServiceStack.OrmLite/Dapper/DefaultTypeMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public SqlMapper.IMemberMap GetMember(string columnName)
166166
return new SimpleMemberMap(columnName, property);
167167

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

171171
// preference order is:
172172
// exact match over underscre match, exact case over wrong case, backing fields over regular fields, match-inc-underscores over match-exc-underscores
@@ -178,7 +178,7 @@ public SqlMapper.IMemberMap GetMember(string columnName)
178178
if (field == null && MatchNamesWithUnderscores)
179179
{
180180
var effectiveColumnName = columnName.Replace("_", "");
181-
backingFieldName = $"<{effectiveColumnName}>k__BackingField";
181+
backingFieldName = String.Format("<{0}>k__BackingField", effectiveColumnName);
182182

183183
field = _fields.FirstOrDefault(p => string.Equals(p.Name, effectiveColumnName, StringComparison.Ordinal))
184184
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))

src/ServiceStack.OrmLite/Dapper/DynamicParameters.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
306306
/// <summary>
307307
/// All the names of the param in the bag, use Get to yank them out
308308
/// </summary>
309-
public IEnumerable<string> ParameterNames => parameters.Select(p => p.Key);
309+
public IEnumerable<string> ParameterNames
310+
{
311+
get { return parameters.Select(p => p.Key); }
312+
}
310313

311314

312315
/// <summary>
@@ -404,7 +407,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
404407
if (setter != null) goto MAKECALLBACK;
405408

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

410413
il.Emit(OpCodes.Ldarg_0); // [object]

src/ServiceStack.OrmLite/Dapper/SimpleMemberMap.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ public SimpleMemberMap(string columnName, ParameterInfo parameter)
6868
/// <summary>
6969
/// Target member type
7070
/// </summary>
71-
public Type MemberType => Field?.FieldType ?? Property?.PropertyType ?? Parameter?.ParameterType;
71+
public Type MemberType
72+
{
73+
get { return Field != null ? Field.FieldType : (Property != null ? Property.PropertyType : (Parameter != null ? Parameter.ParameterType : null)); }
74+
}
7275

7376
/// <summary>
7477
/// Target property

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, objec
136136
return dic.Remove(item.Key);
137137
}
138138

139-
bool ICollection<KeyValuePair<string, object>>.IsReadOnly => false;
139+
bool ICollection<KeyValuePair<string, object>>.IsReadOnly
140+
{
141+
get { return false; }
142+
}
143+
140144
#endregion
141145

142146
#region Implementation of IDictionary<string,object>

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ private sealed class DapperTable
1111
string[] fieldNames;
1212
readonly Dictionary<string, int> fieldNameLookup;
1313

14-
internal string[] FieldNames => fieldNames;
14+
internal string[] FieldNames
15+
{
16+
get { return fieldNames; }
17+
}
1518

1619
public DapperTable(string[] fieldNames)
1720
{
@@ -43,9 +46,15 @@ internal int AddField(string name)
4346
return oldLen;
4447
}
4548

46-
internal bool FieldExists(string key) => key != null && fieldNameLookup.ContainsKey(key);
49+
internal bool FieldExists(string key)
50+
{
51+
return key != null && fieldNameLookup.ContainsKey(key);
52+
}
4753

48-
public int FieldCount => fieldNames.Length;
54+
public int FieldCount
55+
{
56+
get { return fieldNames.Length; }
57+
}
4958
}
5059
}
5160
}

src/ServiceStack.OrmLite/Dapper/SqlMapper.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ public static DbType GetDbType(object value)
356356
/// <summary>
357357
/// OBSOLETE: For internal usage only. Lookup the DbType and handler for a given Type and member
358358
/// </summary>
359+
/// <exception cref="NotSupportedException"></exception>
359360
[Obsolete(ObsoleteInternalUsageOnly, false)]
360361
#if !COREFX
361362
[Browsable(false)]
@@ -403,7 +404,8 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
403404
}
404405
#endif
405406
if(demand)
406-
throw new NotSupportedException($"The member {name} of type {type.FullName} cannot be used as a parameter value");
407+
throw new NotSupportedException(
408+
String.Format("The member {0} of type {1} cannot be used as a parameter value", name, type.FullName));
407409
return DbType.Object;
408410

409411
}
@@ -2152,7 +2154,7 @@ internal static Action<IDbCommand, object> CreateParamInfoGenerator(Identity ide
21522154
{
21532155
filterParams = !smellsLikeOleDb.IsMatch(identity.sql);
21542156
}
2155-
var dm = new DynamicMethod($"ParamInfo{Guid.NewGuid()}", null, new[] { typeof(IDbCommand), typeof(object) }, type, true);
2157+
var dm = new DynamicMethod(String.Format("ParamInfo{0}", Guid.NewGuid()), null, new[] { typeof(IDbCommand), typeof(object) }, type, true);
21562158

21572159
var il = dm.GetILGenerator();
21582160

@@ -2812,7 +2814,7 @@ private static Func<IDataReader, object> GetTypeDeserializerImpl(
28122814
)
28132815
{
28142816
var returnType = type.IsValueType() ? typeof(object) : type;
2815-
var dm = new DynamicMethod($"Deserialize{Guid.NewGuid()}", returnType, new[] { typeof(IDataReader) }, type, true);
2817+
var dm = new DynamicMethod(String.Format("Deserialize{0}", Guid.NewGuid()), returnType, new[] { typeof(IDataReader) }, type, true);
28162818
var il = dm.GetILGenerator();
28172819
il.DeclareLocal(typeof(int));
28182820
il.DeclareLocal(type);
@@ -2886,8 +2888,12 @@ private static Func<IDataReader, object> GetTypeDeserializerImpl(
28862888
var ctor = typeMap.FindConstructor(names, types);
28872889
if (ctor == null)
28882890
{
2889-
string proposedTypes = $"({string.Join(", ", types.Select((t, i) => t.FullName + " " + names[i]).ToArray())})";
2890-
throw new InvalidOperationException($"A parameterless default constructor or one matching signature {proposedTypes} is required for {type.FullName} materialization");
2891+
string proposedTypes = String.Format("({0})",
2892+
string.Join(", ", types.Select((t, i) => t.FullName + " " + names[i]).ToArray()));
2893+
throw new InvalidOperationException(
2894+
String.Format(
2895+
"A parameterless default constructor or one matching signature {0} is required for {1} materialization",
2896+
proposedTypes, type.FullName));
28912897
}
28922898

28932899
if (ctor.GetParameters().Length == 0)
@@ -3328,7 +3334,8 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade
33283334
formattedValue = valEx.Message;
33293335
}
33303336
}
3331-
toThrow = new DataException($"Error parsing column {index} ({name}={formattedValue})", ex);
3337+
toThrow = new DataException(
3338+
String.Format("Error parsing column {0} ({1}={2})", index, name, formattedValue), ex);
33323339
}
33333340
catch
33343341
{ // throw the **original** exception, wrapped as DataException

src/ServiceStack.OrmLite/Dapper/WrappedReader.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ void IDataReader.Close()
3838
reader?.Close();
3939
}
4040

41-
int IDataReader.Depth => Reader.Depth;
41+
int IDataReader.Depth
42+
{
43+
get { return Reader.Depth; }
44+
}
4245

4346
DataTable IDataReader.GetSchemaTable()
4447
{
4548
return Reader.GetSchemaTable();
4649
}
4750

48-
bool IDataReader.IsClosed => reader?.IsClosed ?? true;
51+
bool IDataReader.IsClosed
52+
{
53+
get { return reader != null ? reader.IsClosed : true; }
54+
}
4955

5056
bool IDataReader.NextResult()
5157
{
@@ -57,7 +63,10 @@ bool IDataReader.Read()
5763
return Reader.Read();
5864
}
5965

60-
int IDataReader.RecordsAffected => Reader.RecordsAffected;
66+
int IDataReader.RecordsAffected
67+
{
68+
get { return Reader.RecordsAffected; }
69+
}
6170

6271
void IDisposable.Dispose()
6372
{
@@ -68,7 +77,10 @@ void IDisposable.Dispose()
6877
cmd = null;
6978
}
7079

71-
int IDataRecord.FieldCount => Reader.FieldCount;
80+
int IDataRecord.FieldCount
81+
{
82+
get { return Reader.FieldCount; }
83+
}
7284

7385
bool IDataRecord.GetBoolean(int i)
7486
{
@@ -180,8 +192,14 @@ bool IDataRecord.IsDBNull(int i)
180192
return Reader.IsDBNull(i);
181193
}
182194

183-
object IDataRecord.this[string name] => Reader[name];
195+
object IDataRecord.this[string name]
196+
{
197+
get { return Reader[name]; }
198+
}
184199

185-
object IDataRecord.this[int i] => Reader[i];
200+
object IDataRecord.this[int i]
201+
{
202+
get { return Reader[i]; }
203+
}
186204
}
187205
}

src/ServiceStack.OrmLite/Dapper/XmlHandlers.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ protected override XmlDocument Parse(string xml)
2020
doc.LoadXml(xml);
2121
return doc;
2222
}
23-
protected override string Format(XmlDocument xml) => xml.OuterXml;
23+
protected override string Format(XmlDocument xml)
24+
{
25+
return xml.OuterXml;
26+
}
2427
}
2528
}

0 commit comments

Comments
 (0)