Skip to content

Commit 7689c80

Browse files
committed
General cleanup/cosmetics
C# 6 and so on
1 parent 043f767 commit 7689c80

12 files changed

Lines changed: 1551 additions & 1910 deletions

src/EntityFramework5.Npgsql/EntityFramework5.Npgsql.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<RestorePackages>true</RestorePackages>
1616
<TargetFrameworkProfile />
1717
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
18-
<LangVersion>5</LangVersion>
1918
</PropertyGroup>
2019
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2120
<DebugSymbols>true</DebugSymbols>
@@ -80,4 +79,4 @@
8079
<None Include="packages.config" />
8180
</ItemGroup>
8281
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
83-
</Project>
82+
</Project>

src/EntityFramework6.Npgsql/NpgsqlMigrationSqlGenerator.cs

Lines changed: 214 additions & 299 deletions
Large diffs are not rendered by default.

src/EntityFramework6.Npgsql/NpgsqlProviderManifest.cs

Lines changed: 240 additions & 268 deletions
Large diffs are not rendered by default.

src/EntityFramework6.Npgsql/NpgsqlServices.cs

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#endregion
2323

2424
using System;
25-
using System.Collections.Generic;
2625
using System.Text;
26+
using JetBrains.Annotations;
2727
#if ENTITIES6
2828
using System.Data.Entity.Core.Common;
2929
using System.Data.Entity.Core.Common.CommandTrees;
@@ -39,6 +39,8 @@
3939
using DbConnection = System.Data.Common.DbConnection;
4040
using DbCommand = System.Data.Common.DbCommand;
4141

42+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
43+
4244
namespace Npgsql
4345
{
4446
#if ENTITIES6
@@ -47,38 +49,33 @@ public class NpgsqlServices : DbProviderServices
4749
internal class NpgsqlServices : DbProviderServices
4850
#endif
4951
{
50-
private static readonly NpgsqlServices _instance = new NpgsqlServices();
52+
public static NpgsqlServices Instance { get; } = new NpgsqlServices();
5153

5254
#if ENTITIES6
5355
public NpgsqlServices()
5456
{
5557
AddDependencyResolver(new SingletonDependencyResolver<Func<MigrationSqlGenerator>>(
56-
() => new NpgsqlMigrationSqlGenerator(), "Npgsql"));
58+
() => new NpgsqlMigrationSqlGenerator(), nameof(Npgsql)));
5759
}
5860
#endif
5961

60-
public static NpgsqlServices Instance
61-
{
62-
get { return _instance; }
63-
}
64-
65-
protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
66-
{
67-
return CreateCommandDefinition(CreateDbCommand(((NpgsqlProviderManifest)providerManifest).Version, commandTree));
68-
}
62+
protected override DbCommandDefinition CreateDbCommandDefinition([NotNull] DbProviderManifest providerManifest, [NotNull] DbCommandTree commandTree)
63+
=> CreateCommandDefinition(CreateDbCommand(((NpgsqlProviderManifest)providerManifest).Version, commandTree));
6964

7065
internal DbCommand CreateDbCommand(Version serverVersion, DbCommandTree commandTree)
7166
{
7267
if (commandTree == null)
73-
throw new ArgumentNullException("commandTree");
68+
throw new ArgumentNullException(nameof(commandTree));
7469

75-
NpgsqlCommand command = new NpgsqlCommand();
70+
var command = new NpgsqlCommand();
7671

77-
foreach (KeyValuePair<string, TypeUsage> parameter in commandTree.Parameters)
72+
foreach (var parameter in commandTree.Parameters)
7873
{
79-
NpgsqlParameter dbParameter = new NpgsqlParameter();
80-
dbParameter.ParameterName = parameter.Key;
81-
dbParameter.NpgsqlDbType = NpgsqlProviderManifest.GetNpgsqlDbType(((PrimitiveType)parameter.Value.EdmType).PrimitiveTypeKind);
74+
var dbParameter = new NpgsqlParameter
75+
{
76+
ParameterName = parameter.Key,
77+
NpgsqlDbType = NpgsqlProviderManifest.GetNpgsqlDbType(((PrimitiveType)parameter.Value.EdmType).PrimitiveTypeKind)
78+
};
8279
command.Parameters.Add(dbParameter);
8380
}
8481

@@ -89,76 +86,66 @@ internal DbCommand CreateDbCommand(Version serverVersion, DbCommandTree commandT
8986

9087
internal void TranslateCommandTree(Version serverVersion, DbCommandTree commandTree, DbCommand command, bool createParametersForNonSelect = true)
9188
{
92-
SqlBaseGenerator sqlGenerator = null;
89+
SqlBaseGenerator sqlGenerator;
9390

9491
DbQueryCommandTree select;
9592
DbInsertCommandTree insert;
9693
DbUpdateCommandTree update;
9794
DbDeleteCommandTree delete;
9895
if ((select = commandTree as DbQueryCommandTree) != null)
99-
{
10096
sqlGenerator = new SqlSelectGenerator(select);
101-
}
10297
else if ((insert = commandTree as DbInsertCommandTree) != null)
103-
{
10498
sqlGenerator = new SqlInsertGenerator(insert);
105-
}
10699
else if ((update = commandTree as DbUpdateCommandTree) != null)
107-
{
108100
sqlGenerator = new SqlUpdateGenerator(update);
109-
}
110101
else if ((delete = commandTree as DbDeleteCommandTree) != null)
111-
{
112102
sqlGenerator = new SqlDeleteGenerator(delete);
113-
}
114103
else
115104
{
116105
// TODO: get a message (unsupported DbCommandTree type)
117106
throw new ArgumentException();
118107
}
119-
sqlGenerator._createParametersForConstants = select != null ? false : createParametersForNonSelect;
120-
sqlGenerator._command = (NpgsqlCommand)command;
108+
sqlGenerator.CreateParametersForConstants = select == null && createParametersForNonSelect;
109+
sqlGenerator.Command = (NpgsqlCommand)command;
121110
sqlGenerator.Version = serverVersion;
122111

123112
sqlGenerator.BuildCommand(command);
124113
}
125114

126-
protected override string GetDbProviderManifestToken(DbConnection connection)
115+
protected override string GetDbProviderManifestToken([NotNull] DbConnection connection)
127116
{
128117
if (connection == null)
129-
throw new ArgumentNullException("connection");
130-
string serverVersion = "";
131-
UsingPostgresDBConnection((NpgsqlConnection)connection, conn =>
132-
{
118+
throw new ArgumentNullException(nameof(connection));
119+
120+
var serverVersion = "";
121+
UsingPostgresDbConnection((NpgsqlConnection)connection, conn => {
133122
serverVersion = conn.ServerVersion;
134123
});
135124
return serverVersion;
136125
}
137126

138-
protected override DbProviderManifest GetDbProviderManifest(string versionHint)
127+
protected override DbProviderManifest GetDbProviderManifest([NotNull] string versionHint)
139128
{
140129
if (versionHint == null)
141-
throw new ArgumentNullException("versionHint");
130+
throw new ArgumentNullException(nameof(versionHint));
142131
return new NpgsqlProviderManifest(versionHint);
143132
}
144133

145134
#if ENTITIES6
146-
protected override bool DbDatabaseExists(DbConnection connection, int? commandTimeout, StoreItemCollection storeItemCollection)
135+
protected override bool DbDatabaseExists([NotNull] DbConnection connection, int? commandTimeout, [NotNull] StoreItemCollection storeItemCollection)
147136
{
148-
bool exists = false;
149-
UsingPostgresDBConnection((NpgsqlConnection)connection, conn =>
137+
var exists = false;
138+
UsingPostgresDbConnection((NpgsqlConnection)connection, conn =>
150139
{
151-
using (NpgsqlCommand command = new NpgsqlCommand("select count(*) from pg_catalog.pg_database where datname = '" + connection.Database + "';", conn))
152-
{
140+
using (var command = new NpgsqlCommand("select count(*) from pg_catalog.pg_database where datname = '" + connection.Database + "';", conn))
153141
exists = Convert.ToInt32(command.ExecuteScalar()) > 0;
154-
}
155142
});
156143
return exists;
157144
}
158145

159-
protected override void DbCreateDatabase(DbConnection connection, int? commandTimeout, StoreItemCollection storeItemCollection)
146+
protected override void DbCreateDatabase([NotNull] DbConnection connection, int? commandTimeout, [NotNull] StoreItemCollection storeItemCollection)
160147
{
161-
UsingPostgresDBConnection((NpgsqlConnection)connection, conn =>
148+
UsingPostgresDbConnection((NpgsqlConnection)connection, conn =>
162149
{
163150
var sb = new StringBuilder();
164151
sb.Append("CREATE DATABASE \"");
@@ -171,28 +158,24 @@ protected override void DbCreateDatabase(DbConnection connection, int? commandTi
171158
sb.Append("\"");
172159
}
173160

174-
using (NpgsqlCommand command = new NpgsqlCommand(sb.ToString(), conn))
175-
{
161+
using (var command = new NpgsqlCommand(sb.ToString(), conn))
176162
command.ExecuteNonQuery();
177-
}
178163
});
179164
}
180165

181-
protected override void DbDeleteDatabase(DbConnection connection, int? commandTimeout, StoreItemCollection storeItemCollection)
166+
protected override void DbDeleteDatabase([NotNull] DbConnection connection, int? commandTimeout, [NotNull] StoreItemCollection storeItemCollection)
182167
{
183-
UsingPostgresDBConnection((NpgsqlConnection)connection, conn =>
168+
UsingPostgresDbConnection((NpgsqlConnection)connection, conn =>
184169
{
185170
//Close all connections in pool or exception "database used by another user appears"
186171
NpgsqlConnection.ClearAllPools();
187-
using (NpgsqlCommand command = new NpgsqlCommand("DROP DATABASE \"" + connection.Database + "\";", conn))
188-
{
172+
using (var command = new NpgsqlCommand("DROP DATABASE \"" + connection.Database + "\";", conn))
189173
command.ExecuteNonQuery();
190-
}
191174
});
192175
}
193176
#endif
194177

195-
private static void UsingPostgresDBConnection(NpgsqlConnection connection, Action<NpgsqlConnection> action)
178+
static void UsingPostgresDbConnection(NpgsqlConnection connection, Action<NpgsqlConnection> action)
196179
{
197180
var connectionBuilder = new NpgsqlConnectionStringBuilder(connection.ConnectionString)
198181
{

src/EntityFramework6.Npgsql/SqlGenerators/PendingProjectsNode.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2222
#endregion
2323

24-
using System;
2524
using System.Collections.Generic;
26-
using System.Linq;
27-
using System.Text;
2825

2926
namespace Npgsql.SqlGenerators
3027
{
@@ -51,23 +48,18 @@ internal class PendingProjectsNode
5148
{
5249
public readonly List<NameAndInputExpression> Selects = new List<NameAndInputExpression>();
5350
public PendingProjectsNode JoinParent { get; set; }
54-
public string TopName
55-
{
56-
get
57-
{
58-
return Selects[0].AsName;
59-
}
60-
}
51+
public string TopName => Selects[0].AsName;
6152

6253
public PendingProjectsNode(string asName, InputExpression exp)
6354
{
6455
Selects.Add(new NameAndInputExpression(asName, exp));
6556
}
57+
6658
public void Add(string asName, InputExpression exp)
6759
{
6860
Selects.Add(new NameAndInputExpression(asName, exp));
6961
}
7062

71-
public NameAndInputExpression Last { get { return Selects[Selects.Count - 1]; } }
63+
public NameAndInputExpression Last => Selects[Selects.Count - 1];
7264
}
7365
}

0 commit comments

Comments
 (0)