Skip to content

Commit 0b66b5f

Browse files
author
Marc Sallin
committed
Fix for code analysis warnings.
1 parent 9266156 commit 0b66b5f

File tree

10 files changed

+38
-16
lines changed

10 files changed

+38
-16
lines changed

SQLite.CodeFirst/Attributes/CollateAttribute.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ namespace SQLite.CodeFirst
99
[AttributeUsage(AttributeTargets.Property)]
1010
public sealed class CollateAttribute : Attribute
1111
{
12-
public CollateAttribute(CollationFunction collation = CollationFunction.None)
12+
public CollateAttribute()
13+
{
14+
Collation = CollationFunction.None;
15+
}
16+
17+
public CollateAttribute(CollationFunction collation)
1318
{
1419
Collation = collation;
1520
}
1621

17-
public CollationFunction Collation { get; set; }
22+
public CollationFunction Collation { get; private set; }
1823
}
1924
}

SQLite.CodeFirst/Attributes/UniqueAttribute.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ namespace SQLite.CodeFirst
88
[AttributeUsage(AttributeTargets.Property)]
99
public sealed class UniqueAttribute : Attribute
1010
{
11-
public UniqueAttribute(OnConflictAction onConflict = OnConflictAction.None)
11+
public UniqueAttribute()
12+
{
13+
OnConflict = OnConflictAction.None;
14+
}
15+
16+
public UniqueAttribute(OnConflictAction onConflict)
1217
{
1318
OnConflict = onConflict;
1419
}
1520

16-
public OnConflictAction OnConflict { get; set; }
21+
public OnConflictAction OnConflict { get; private set; }
1722
}
1823
}

SQLite.CodeFirst/DbInitializers/SqliteDropCreateDatabaseWhenModelChanges.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using SQLite.CodeFirst.Utility;
9+
using System.Diagnostics.CodeAnalysis;
910

1011
namespace SQLite.CodeFirst
1112
{
@@ -88,6 +89,7 @@ public override void InitializeDatabase(TContext context)
8889
}
8990
}
9091

92+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.GC.Collect", Justification = "Required.")]
9193
private static void DeleteDatabase(TContext context, string databseFilePath)
9294
{
9395
context.Database.Connection.Close();
@@ -120,6 +122,7 @@ private void SaveHistory(TContext context)
120122
context.SaveChanges();
121123
}
122124

125+
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
123126
private bool IsSameModel(TContext context)
124127
{
125128

SQLite.CodeFirst/DbInitializers/SqliteInitializerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace SQLite.CodeFirst
2222
public abstract class SqliteInitializerBase<TContext> : IDatabaseInitializer<TContext>
2323
where TContext : DbContext
2424
{
25-
protected readonly DbModelBuilder ModelBuilder;
25+
protected DbModelBuilder ModelBuilder { get; }
2626

2727
protected SqliteInitializerBase(DbModelBuilder modelBuilder)
2828
{

SQLite.CodeFirst/Internal/Builder/ColumnStatementCollectionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static void AdjustDatatypeForAutogenerationIfNecessary(EdmProperty prope
5757
if (property.StoreGeneratedPattern == StoreGeneratedPattern.Identity)
5858
{
5959
// Must be INTEGER else SQLite will not generate the Ids
60-
columnStatement.TypeName = columnStatement.TypeName.ToLower(CultureInfo.InvariantCulture) == "int" ? "INTEGER" : columnStatement.TypeName;
60+
columnStatement.TypeName = columnStatement.TypeName.ToUpperInvariant() == "INT" ? "INTEGER" : columnStatement.TypeName;
6161
}
6262
}
6363

SQLite.CodeFirst/Internal/Convention/SqliteForeignKeyIndexConvention.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Data.Entity.Infrastructure;
77
using System.Data.Entity.Infrastructure.Annotations;
88
using System.Data.Entity.ModelConfiguration.Conventions;
9+
using System.Globalization;
910
using System.Linq;
1011
using SQLite.CodeFirst.Builder.NameCreators;
1112

@@ -76,7 +77,7 @@ private static IndexAnnotation CreateIndexAnnotation(string tableName, string pr
7677
// To be honest, it should never happen. But because its possible by using the API, it should be covered.
7778
if (count > 0)
7879
{
79-
indexName = String.Format("{0}_{1}", indexName, count);
80+
indexName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", indexName, count);
8081
}
8182

8283
var indexAttribute = new IndexAttribute(indexName);

SQLite.CodeFirst/Internal/Utility/ConnectionStringParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Globalization;
45

56
namespace SQLite.CodeFirst.Utility
@@ -12,6 +13,7 @@ internal static class ConnectionStringParser
1213
private const int KeyPosition = 0;
1314
private const int ValuePosition = 1;
1415

16+
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "ToUppercase makes no sense.")]
1517
public static IDictionary<string, string> ParseConnectionString(string connectionString)
1618
{
1719
connectionString = connectionString.Trim();

SQLite.CodeFirst/Internal/Utility/HashCreator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ internal static class HashCreator
99
public static string CreateHash(string data)
1010
{
1111
byte[] dataBytes = Encoding.ASCII.GetBytes(data);
12-
SHA512 sha512 = new SHA512Managed();
13-
byte[] hashBytes = sha512.ComputeHash(dataBytes);
14-
string hash = Convert.ToBase64String(hashBytes);
15-
return hash;
12+
using (SHA512 sha512 = new SHA512Managed())
13+
{
14+
byte[] hashBytes = sha512.ComputeHash(dataBytes);
15+
string hash = Convert.ToBase64String(hashBytes);
16+
return hash;
17+
}
1618
}
1719
}
1820
}

SQLite.CodeFirst/SqliteDatabaseCreator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Data.Entity;
1+
using System;
2+
using System.Data.Entity;
23
using System.Data.Entity.Infrastructure;
34

45
namespace SQLite.CodeFirst
@@ -14,6 +15,9 @@ public class SqliteDatabaseCreator : IDatabaseCreator
1415
/// </summary>
1516
public void Create(Database db, DbModel model)
1617
{
18+
if (db == null) throw new ArgumentNullException("db");
19+
if (model == null) throw new ArgumentNullException("model");
20+
1721
var sqliteSqlGenerator = new SqliteSqlGenerator();
1822
string sql = sqliteSqlGenerator.Generate(model.StoreModel);
1923
db.ExecuteSqlCommand(TransactionalBehavior.EnsureTransaction, sql);

Shared/SQLite.CodeFirst.ruleset

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<Rule Id="CA1017" Action="Warning" />
2222
<Rule Id="CA1018" Action="Warning" />
2323
<Rule Id="CA1019" Action="Warning" />
24-
<Rule Id="CA1020" Action="Warning" />
24+
<Rule Id="CA1020" Action="None" />
2525
<Rule Id="CA1021" Action="Warning" />
2626
<Rule Id="CA1023" Action="Warning" />
2727
<Rule Id="CA1024" Action="Warning" />
@@ -101,7 +101,7 @@
101101
<Rule Id="CA1701" Action="Warning" />
102102
<Rule Id="CA1702" Action="Warning" />
103103
<Rule Id="CA1703" Action="Warning" />
104-
<Rule Id="CA1704" Action="Warning" />
104+
<Rule Id="CA1704" Action="None" />
105105
<Rule Id="CA1707" Action="Warning" />
106106
<Rule Id="CA1708" Action="Warning" />
107107
<Rule Id="CA1709" Action="Warning" />
@@ -152,7 +152,7 @@
152152
<Rule Id="CA2101" Action="Warning" />
153153
<Rule Id="CA2102" Action="Warning" />
154154
<Rule Id="CA2103" Action="Warning" />
155-
<Rule Id="CA2104" Action="Warning" />
155+
<Rule Id="CA2104" Action="None" />
156156
<Rule Id="CA2105" Action="Warning" />
157157
<Rule Id="CA2106" Action="Warning" />
158158
<Rule Id="CA2107" Action="Warning" />
@@ -195,7 +195,7 @@
195195
<Rule Id="CA2200" Action="Warning" />
196196
<Rule Id="CA2201" Action="Warning" />
197197
<Rule Id="CA2202" Action="Warning" />
198-
<Rule Id="CA2204" Action="Warning" />
198+
<Rule Id="CA2204" Action="None" />
199199
<Rule Id="CA2205" Action="Warning" />
200200
<Rule Id="CA2207" Action="Warning" />
201201
<Rule Id="CA2208" Action="Warning" />

0 commit comments

Comments
 (0)