Skip to content

Commit d267739

Browse files
committed
More C#6 changes.
1 parent ed6f0c5 commit d267739

28 files changed

Lines changed: 178 additions & 520 deletions

SQLitePCL.pretty.Async/AsyncBlobStream.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,11 @@ internal AsyncBlobStream(Stream blobStream, IAsyncDatabaseConnection queue)
3434
this.queue = queue;
3535
}
3636

37-
public override bool CanRead
38-
{
39-
get
40-
{
41-
return !disposed;
42-
}
43-
}
37+
public override bool CanRead => !disposed;
4438

45-
public override bool CanSeek
46-
{
47-
get
48-
{
49-
return !disposed;
50-
}
51-
}
39+
public override bool CanSeek => !disposed;
5240

53-
public override bool CanWrite
54-
{
55-
get
56-
{
57-
return !disposed && blobStream.CanWrite;
58-
}
59-
}
41+
public override bool CanWrite => !disposed && blobStream.CanWrite;
6042

6143
public override long Length
6244
{

SQLitePCL.pretty.Async/AsyncStatement.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,7 @@ public IReadOnlyList<IResultSetValue> Current
284284
}
285285
}
286286

287-
object IEnumerator.Current
288-
{
289-
get
290-
{
291-
return this.Current;
292-
}
293-
}
287+
object IEnumerator.Current => this.Current;
294288

295289
public bool MoveNext()
296290
{

SQLitePCL.pretty.Async/OperationsQueue.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,8 @@ private Operation(Func<CancellationToken, Task<T>> f, CancellationToken cancella
5555
this.cancellationToken = cancellationToken;
5656
}
5757

58-
public Task<T> Result
59-
{
60-
get
61-
{
62-
return result.Task;
63-
}
64-
}
58+
public Task<T> Result =>
59+
result.Task;
6560

6661
public override async Task EvaluateFunc()
6762
{

SQLitePCL.pretty.Orm/ColumnMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public override int GetHashCode()
101101
/// </summary>
102102
/// <returns>A <see cref="System.String"/> that represents the current <see cref="SQLitePCL.pretty.Orm.ColumnMapping"/>.</returns>
103103
public override string ToString() =>
104-
string.Format("[ColumnMapping: ClrType={0}, Property={1}, Metadata={2}]", ClrType, Property, Metadata);
104+
$"[ColumnMapping: ClrType={ClrType}, Property={Property}, Metadata={Metadata}]";
105105
}
106106
}
107107

SQLitePCL.pretty.Orm/IndexInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public override int GetHashCode()
8686
/// </summary>
8787
/// <returns>A <see cref="System.String"/> that represents the current <see cref="SQLitePCL.pretty.Orm.IndexInfo"/>.</returns>
8888
public override string ToString() =>
89-
string.Format("[IndexInfo: Unique={0}, Columns={1}", this.Unique, string.Join(", ", this.Columns));
89+
$"[IndexInfo: Unique={this.Unique}, Columns={string.Join(", ", this.Columns)}";
9090
}
9191
}
9292

SQLitePCL.pretty.Orm/ResultSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static object ToObject(this ISQLiteValue value, Type clrType)
9898
else if (clrType == typeof(Uri)) { return value.ToUri(); }
9999
else
100100
{
101-
throw new NotSupportedException ("Don't know how to read " + clrType);
101+
throw new NotSupportedException ($"Don't know how to read {clrType}");
102102
}
103103
}
104104
}

SQLitePCL.pretty.Orm/SQLBuilder.cs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,61 @@ namespace SQLitePCL.pretty.Orm
77
internal static class SQLBuilder
88
{
99
internal static string GetTableInfo (string tableName) =>
10-
"PRAGMA TABLE_INFO(\"" + tableName + "\")";
10+
$"PRAGMA TABLE_INFO(\"{tableName}\")";
1111

1212
internal static string SelectWhereColumnEquals(string tableName, string columnName) =>
13-
string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ?", tableName, columnName);
13+
$"SELECT * FROM \"{tableName}\" WHERE \"{columnName}\" = ?";
1414

1515
internal static string FindByRowID(string tableName) =>
16-
string.Format("SELECT * FROM \"{0}\" WHERE ROWID = ?", tableName);
16+
$"SELECT * FROM \"{tableName}\" WHERE ROWID = ?";
1717

1818
internal static string AlterTableAddColumn(string tableName, string columnName, ColumnMapping columnMapping) =>
19-
string.Format("ALTER TABLE \"{0}\" ADD COLUMN {1}", tableName, SqlDecl(columnName, columnMapping));
19+
$"ALTER TABLE \"{tableName}\" ADD COLUMN { SqlDecl(columnName, columnMapping)}";
2020

2121
internal static string DeleteUsingPrimaryKey(string tableName, string pkColumn) =>
22-
string.Format("DELETE FROM \"{0}\" WHERE \"{1}\" = ?", tableName, pkColumn);
22+
$"DELETE FROM \"{tableName}\" WHERE \"{pkColumn}\" = ?";
2323

24-
internal static string InsertOrReplace(string tableName, IEnumerable<string> columns) =>
25-
string.Format(
26-
"INSERT OR REPLACE INTO \"{0}\" ({1}) VALUES ({2})",
27-
tableName,
28-
string.Join(",", columns.Select(x => "\"" + x + "\"")),
29-
30-
// FIXME: Might need to quote this for some cases. Test!!!
31-
string.Join(",", columns.Select(x => ":" + x)));
32-
33-
internal static string CreateIndex(string indexName, string tableName, IEnumerable<string> columnNames, bool unique)
24+
internal static string InsertOrReplace(string tableName, IEnumerable<string> columns)
3425
{
35-
const string sqlFormat = "CREATE {2} INDEX IF NOT EXISTS \"{3}\" ON \"{0}\"(\"{1}\")";
36-
return String.Format(sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "UNIQUE" : "", indexName);
26+
var columnList = string.Join(",", columns.Select(x => $"\"{x}\""));
27+
var bindParamList = string.Join(",", columns.Select(x => $":{x}"));
28+
return $"INSERT OR REPLACE INTO \"{tableName}\" ({columnList}) VALUES ({bindParamList})";
3729
}
3830

31+
internal static string CreateIndex(string indexName, string tableName, IEnumerable<string> columnNames, bool unique) =>
32+
$"CREATE {(unique ? "UNIQUE" : "")} INDEX IF NOT EXISTS \"{indexName}\" ON \"{tableName}\"(\"{string.Join ("\", \"", columnNames)}\")";
33+
3934
internal static string NameIndex(string tableName, IEnumerable<string> columnNames) =>
40-
tableName + "_" + string.Join ("_", columnNames);
35+
$"{tableName}_{string.Join("_", columnNames)}";
4136

4237
internal static string NameIndex(string tableName, string columnName) =>
4338
NameIndex(tableName, new String[] { columnName});
4439

4540
internal static string ListIndexes(string tableName) =>
46-
string.Format("PRAGMA INDEX_LIST (\"{0}\")", tableName);
41+
$"PRAGMA INDEX_LIST (\"{tableName}\")";
4742

4843
internal static string IndexInfo(string indexName) =>
49-
string.Format("PRAGMA INDEX_INFO (\"{0}\")", indexName);
44+
$"PRAGMA INDEX_INFO (\"{indexName}\")";
5045

5146
internal static string CreateTableIfNotExists(string tableName, CreateFlags createFlags, IReadOnlyDictionary<string, ColumnMapping> columns)
5247
{
5348
bool fts3 = (createFlags & CreateFlags.FullTextSearch3) != 0;
5449
bool fts4 = (createFlags & CreateFlags.FullTextSearch4) != 0;
5550
bool fts = fts3 || fts4;
5651

57-
var @virtual = fts ? "VIRTUAL " : string.Empty;
58-
var @using = fts3 ? "USING FTS3 " : fts4 ? "USING FTS4 " : string.Empty;
52+
var @virtual = fts ? "VIRTUAL " : "";
53+
var @using = fts3 ? "USING FTS3 " : fts4 ? "USING FTS4 " : "";
5954

6055
// Build query.
61-
var query = "CREATE " + @virtual + "TABLE IF NOT EXISTS \"" + tableName + "\" " + @using + "(\n";
56+
var query = $"CREATE {@virtual}TABLE IF NOT EXISTS \"{tableName}\" {@using}(\n";
6257
var decls = columns.Select(c => SQLBuilder.SqlDecl(c.Key, c.Value));
6358
var decl = string.Join(",\n", decls.ToArray());
6459
query += decl;
6560
var fkconstraints =
6661
string.Join(
6762
",\n",
6863
columns.Where(x => x.Value.ForeignKeyConstraint != null).Select(x =>
69-
string.Format("FOREIGN KEY(\"{0}\") REFERENCES \"{1}\"(\"{2}\")",
70-
x.Key,
71-
x.Value.ForeignKeyConstraint.TableName,
72-
x.Value.ForeignKeyConstraint.ColumnName)));
64+
$"FOREIGN KEY(\"{x.Key}\") REFERENCES \"{x.Value.ForeignKeyConstraint.TableName}\"(\"{x.Value.ForeignKeyConstraint.ColumnName}\")"));
7365
query += (fkconstraints.Length != 0) ? "," + fkconstraints : "";
7466
query += ")";
7567

@@ -78,7 +70,7 @@ internal static string CreateTableIfNotExists(string tableName, CreateFlags crea
7870

7971
internal static string SqlDecl(string columnName, ColumnMapping columnMapping)
8072
{
81-
string decl = "\"" + columnName + "\" " + columnMapping.Metadata.DeclaredType + " ";
73+
string decl = $"\"{columnName}\" {columnMapping.Metadata.DeclaredType} ";
8274

8375
if (columnMapping.Metadata.IsPrimaryKeyPart && columnMapping.Metadata.IsAutoIncrement)
8476
{
@@ -90,22 +82,22 @@ internal static string SqlDecl(string columnName, ColumnMapping columnMapping)
9082
}
9183
else if (columnMapping.Metadata.HasNotNullConstraint)
9284
{
93-
decl += "NOT NULL DEFAULT \"" + columnMapping.DefaultValue.ToString() + "\" ";
85+
decl += $"NOT NULL DEFAULT \"{columnMapping.DefaultValue.ToString()}\" ";
9486
}
9587

9688
if (!string.IsNullOrEmpty (columnMapping.Metadata.CollationSequence))
9789
{
98-
decl += "COLLATE " + columnMapping.Metadata.CollationSequence + " ";
90+
decl += $"COLLATE {columnMapping.Metadata.CollationSequence} ";
9991
}
10092

10193
return decl;
10294
}
10395

10496
internal static string DropTableIfExists(string tableName) =>
105-
string.Format("DROP TABLE IF EXISTS \"{0}\"", tableName);
97+
$"DROP TABLE IF EXISTS \"{tableName}\"";
10698

10799
internal static string DeleteAll(string tableName) =>
108-
string.Format("DELETE FROM \"{0}\"", tableName);
100+
$"DELETE FROM \"{tableName}\"";
109101
}
110102
}
111103

SQLitePCL.pretty.Orm/SqlCompiler.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ private static string CompileExpr(this Expression This)
2121
{
2222
if (bin.NodeType == ExpressionType.Equal)
2323
{
24-
return "(" + leftExpr + "IS NULL)";
24+
return $"({leftExpr} IS NULL)";
2525
}
2626
else if (rightExpr == "NULL" && bin.NodeType == ExpressionType.NotEqual)
2727
{
28-
return "(" + leftExpr + "IS NOT NULL)";
28+
return $"({leftExpr} IS NOT NULL)";
2929
}
3030
}
3131

32-
return "(" + leftExpr + " " + GetSqlName(bin) + " " + rightExpr + ")";
32+
return $"({leftExpr} {GetSqlName(bin)} {rightExpr})";
3333
}
3434
else if (This is ParameterExpression)
3535
{
3636
var param = (ParameterExpression)This;
37-
return ":" + param.Name;
37+
return $":{param.Name}";
3838
}
3939
else if (This is MemberExpression)
4040
{
@@ -45,7 +45,7 @@ private static string CompileExpr(this Expression This)
4545
// This is a column in the table, output the column name
4646
var tableName = TableMapping.Get(member.Expression.Type).TableName;
4747
var columnName = ((PropertyInfo) member.Member).GetColumnName();
48-
return "\"" + tableName + "\".\"" + columnName + "\"";
48+
return $"\"{tableName}\".\"{columnName}\"";
4949
}
5050
else
5151
{
@@ -55,7 +55,7 @@ private static string CompileExpr(this Expression This)
5555
else if (This.NodeType == ExpressionType.Not)
5656
{
5757
var operandExpr = ((UnaryExpression)This).Operand;
58-
return "NOT(" + operandExpr.CompileExpr() + ")";
58+
return $"NOT({operandExpr.CompileExpr()})";
5959
}
6060
else if (This is ConstantExpression)
6161
{
@@ -75,42 +75,42 @@ private static string CompileExpr(this Expression This)
7575

7676
if (call.Method.Name == "Like" && args.Length == 2)
7777
{
78-
return "(" + args[0] + " LIKE " + args[1] + ")";
78+
return $"({args[0]} LIKE {args[1]})";
7979
}
8080
else if (call.Method.Name == "Contains" && args.Length == 2)
8181
{
82-
return "(" + args[1] + " IN " + args[0] + ")";
82+
return $"({args[1]} IN {args[0]})";
8383
}
8484
else if (call.Method.Name == "Contains" && args.Length == 1)
8585
{
8686
if (call.Object != null && call.Object.Type == typeof(string))
8787
{
88-
return "(" + obj + " LIKE ('%' || " + args[0] + " || '%'))";
88+
return $"({obj} LIKE ('%' || {args[0]} || '%'))";
8989
}
9090
else
9191
{
92-
return "(" + args[0] + " IN " + obj + ")";
92+
return $"({args[0]} IN {obj})";
9393
}
9494
}
9595
else if (call.Method.Name == "StartsWith" && args.Length == 1)
9696
{
97-
return "(" + obj + " LIKE (" + args[0] + " || '%'))";
97+
return $"({obj} LIKE ({args[0]} || '%'))";
9898
}
9999
else if (call.Method.Name == "EndsWith" && args.Length == 1)
100100
{
101-
return "(" + obj + " LIKE ('%' || " + args[0] + "))";
101+
return $"({obj} LIKE ('%' || {args[0]}))";
102102
}
103103
else if (call.Method.Name == "Equals" && args.Length == 1)
104104
{
105-
return "(" + obj + " = (" + args[0] + "))";
105+
return $"({obj} = ({args[0]}))";
106106
}
107107
else if (call.Method.Name == "Is" && args.Length == 2)
108108
{
109-
return "(" + args[0] + " IS " + args[1] + ")";
109+
return $"({args[0]} IS {args[1]})";
110110
}
111111
else if (call.Method.Name == "IsNot" && args.Length == 2)
112112
{
113-
return "(" + args[0] + " IS NOT " + args[1] + ")";
113+
return $"({args[0]} IS NOT {args[1]})";
114114
}
115115
}
116116
else if (This.NodeType == ExpressionType.Convert)
@@ -144,7 +144,7 @@ private static string CompileExpr(this Expression This)
144144
return CompileExpr(expr.Body);
145145
}
146146

147-
throw new NotSupportedException("Cannot compile: " + This.NodeType.ToString());
147+
throw new NotSupportedException($"Cannot compile: {This.NodeType.ToString()}");
148148
}
149149

150150
private static object EvaluateExpression(this Expression expr)
@@ -172,7 +172,7 @@ private static object EvaluateExpression(this Expression expr)
172172
}
173173
}
174174

175-
throw new NotSupportedException("Cannot compile: " + expr.NodeType.ToString());
175+
throw new NotSupportedException($"Cannot compile: {expr.NodeType.ToString()}");
176176
}
177177

178178
private static string ToSqlString(this ISQLiteValue value)
@@ -183,7 +183,7 @@ private static string ToSqlString(this ISQLiteValue value)
183183
return "NULL";
184184
case SQLiteType.Text:
185185
case SQLiteType.Blob:
186-
return "\"" + value.ToString() + "\"";
186+
return $"\"{value.ToString()}\"";
187187
default:
188188
return value.ToString();
189189
}
@@ -216,7 +216,7 @@ private static ISQLiteValue ConvertToSQLiteValue(this object This)
216216
else if (This is Uri) { return ((Uri) This).ToSQLiteValue(); }
217217
else
218218
{
219-
throw new ArgumentException("Invalid type conversion" + t);
219+
throw new ArgumentException($"Invalid type conversion {t}");
220220
}
221221
}
222222

@@ -237,7 +237,7 @@ private static string GetSqlName(Expression prop)
237237
case ExpressionType.Equal: return "=";
238238
case ExpressionType.NotEqual: return "!=";
239239
default:
240-
throw new NotSupportedException ("Cannot get SQL for: " + n);
240+
throw new NotSupportedException ($"Cannot get SQL for: {n}");
241241
}
242242
}
243243
}

SQLitePCL.pretty.Orm/SqlQuery.Join.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal JoinClause(FromClause from, IReadOnlyList<string> join)
3535
/// </summary>
3636
/// <returns>A <see cref="System.String"/> that represents the current <see cref="SQLitePCL.pretty.Orm.Sql.JoinClause"/>.</returns>
3737
public override string ToString() =>
38-
from + (join.Count == 0 ? "" : "\r\n" + string.Join("\r\n", join));
38+
from + (join.Count == 0 ? "" : $"\r\n{string.Join("\r\n", join)}");
3939
}
4040

4141
internal sealed class JoinClause<T> : JoinClause

SQLitePCL.pretty.Orm/SqlQuery.Limit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal LimitClause(OrderByClause orderBy, string limit)
2929
/// </summary>
3030
/// <returns>A <see cref="System.String"/> that represents the current <see cref="SQLitePCL.pretty.Orm.Sql.LimitClause"/>.</returns>
3131
public override string ToString() =>
32-
orderBy + "\r\n" + limit;
32+
$"{orderBy}\r\n{limit}";
3333
}
3434

3535
/// <summary>

0 commit comments

Comments
 (0)