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

Commit e82bc6d

Browse files
committed
Use C# using var to reduce nesting
1 parent 34fa22a commit e82bc6d

19 files changed

+1856
-2185
lines changed

tests/ServiceStack.OrmLite.Tests/AdoNetDataAccessTests.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,30 @@ public class MigrateSqlServerTypes
2727
[Test]
2828
public void Can_read_from_existing_database()
2929
{
30-
using (var db = OpenDbConnection())
30+
using var db = OpenDbConnection();
31+
var map = new Dictionary<int, TimeSpan>();
32+
33+
using (var dbCmd = db.CreateCommand())
3134
{
32-
var map = new Dictionary<int, TimeSpan>();
35+
dbCmd.CommandText = "SELECT * FROM MigrateSqlServerTypes";
3336

34-
using (var dbCmd = db.CreateCommand())
37+
using (var reader = dbCmd.ExecuteReader())
3538
{
36-
dbCmd.CommandText = "SELECT * FROM MigrateSqlServerTypes";
37-
38-
using (var reader = dbCmd.ExecuteReader())
39+
while (reader.Read())
3940
{
40-
while (reader.Read())
41-
{
42-
var id = reader.GetInt32(0);
43-
var sqlTime = (TimeSpan)reader.GetValue(1);
44-
map[id] = sqlTime;
45-
}
41+
var id = reader.GetInt32(0);
42+
var sqlTime = (TimeSpan)reader.GetValue(1);
43+
map[id] = sqlTime;
4644
}
4745
}
46+
}
4847

49-
foreach (var entry in map)
50-
{
51-
db.Update(new MigrateSqlServerTypes { Id = entry.Key, OrmLiteTimeSpan = entry.Value });
52-
}
53-
54-
db.Select<MigrateSqlServerTypes>().PrintDump();
48+
foreach (var entry in map)
49+
{
50+
db.Update(new MigrateSqlServerTypes { Id = entry.Key, OrmLiteTimeSpan = entry.Value });
5551
}
52+
53+
db.Select<MigrateSqlServerTypes>().PrintDump();
5654
}
5755
}
5856
}

tests/ServiceStack.OrmLite.Tests/ApiSqlServerTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public ApiSqlServerTests(DialectContext context) : base(context) {}
1313
[Test]
1414
public void API_SqlServer_Examples()
1515
{
16-
var db = OpenDbConnection();
16+
using var db = OpenDbConnection();
1717
db.DropAndCreateTable<Person>();
1818
db.DropAndCreateTable<PersonWithAutoId>();
1919

@@ -360,7 +360,6 @@ public void API_SqlServer_Examples()
360360

361361
db.SaveAll(new[]{ new Person { Id = 14, FirstName = "Amy", LastName = "Winehouse", Age = 27 },
362362
new Person { Id = 15, FirstName = "Amy", LastName = "Winehouse", Age = 27 } });
363-
db.Dispose();
364363
}
365364
}
366365
}

tests/ServiceStack.OrmLite.Tests/ApiSqliteTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public ApiSqliteTests(DialectContext context) : base(context) {}
1313
[Test]
1414
public void API_Sqlite_Examples()
1515
{
16-
var db = OpenDbConnection();
16+
using var db = OpenDbConnection();
1717
db.DropAndCreateTable<Person>();
1818
db.DropAndCreateTable<PersonWithAutoId>();
1919

@@ -342,7 +342,6 @@ public void API_Sqlite_Examples()
342342

343343
db.SaveAll(new[]{ new Person { Id = 14, FirstName = "Amy", LastName = "Winehouse", Age = 27 },
344344
new Person { Id = 15, FirstName = "Amy", LastName = "Winehouse", Age = 27 } });
345-
db.Dispose();
346345
}
347346

348347
}

0 commit comments

Comments
 (0)