Skip to content

Commit 5784b52

Browse files
authored
Cleanup (#2794)
1 parent 459b27e commit 5784b52

58 files changed

Lines changed: 193 additions & 232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/EFCore.PG.NodaTime/Storage/Internal/IntervalRangeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override Expression GenerateCodeLiteral(object value)
118118
{
119119
var interval = (Interval)value;
120120

121-
return interval.HasStart && interval.HasEnd
121+
return interval is { HasStart: true, HasEnd: true }
122122
? Expression.New(
123123
_constructor,
124124
TimestampTzInstantMapping.GenerateCodeLiteral(interval.Start),

src/EFCore.PG.NodaTime/Storage/Internal/TimestampLocalDateTimeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private string GenerateLiteralCore(object value)
124124

125125
internal static Expression GenerateCodeLiteral(LocalDateTime dateTime)
126126
{
127-
if (dateTime.Second == 0 && dateTime.NanosecondOfSecond == 0)
127+
if (dateTime is { Second: 0, NanosecondOfSecond: 0 })
128128
{
129129
return ConstantNew(ConstructorWithMinutes, dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute);
130130
}

src/EFCore.PG/Internal/IReadOnlyListExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public static IReadOnlyList<T> Slice<T>(this IReadOnlyList<T> list, int start)
99

1010
private sealed class IReadOnlyListSlice<T> : IReadOnlyList<T>
1111
{
12-
private IReadOnlyList<T> _underlying;
13-
private int _start;
12+
private readonly IReadOnlyList<T> _underlying;
13+
private readonly int _start;
1414

1515
internal IReadOnlyListSlice(IReadOnlyList<T> underlying, int start)
1616
{

src/EFCore.PG/Internal/NpgsqlSingletonOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ public virtual void Initialize(IDbContextOptions options)
9494
public virtual void Validate(IDbContextOptions options)
9595
{
9696
var npgsqlOptions = options.FindExtension<NpgsqlOptionsExtension>() ?? new();
97-
var coreOptions = options.FindExtension<CoreOptionsExtension>() ?? new();
9897

9998
if (PostgresVersion != npgsqlOptions.PostgresVersion)
10099
{

src/EFCore.PG/Metadata/Conventions/NpgsqlPostgresModelFinalizingConvention.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ protected virtual void DiscoverPostgresExtensions(
7171
/// </summary>
7272
protected virtual void ProcessRowVersionProperty(IConventionProperty property, RelationalTypeMapping typeMapping)
7373
{
74-
if (property.ValueGenerated == ValueGenerated.OnAddOrUpdate
75-
&& property.IsConcurrencyToken
74+
if (property is { ValueGenerated: ValueGenerated.OnAddOrUpdate, IsConcurrencyToken: true }
7675
&& typeMapping.StoreType == "xid")
7776
{
7877
property.Builder.HasColumnName("xmin");

src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ public override IEnumerable<IAnnotation> For(IColumn column, bool designTime)
8686
var valueGenerationStrategy = valueGeneratedProperty.GetValueGenerationStrategy();
8787
yield return new Annotation(NpgsqlAnnotationNames.ValueGenerationStrategy, valueGenerationStrategy);
8888

89-
if (valueGenerationStrategy == NpgsqlValueGenerationStrategy.IdentityByDefaultColumn ||
90-
valueGenerationStrategy == NpgsqlValueGenerationStrategy.IdentityAlwaysColumn)
89+
if (valueGenerationStrategy is NpgsqlValueGenerationStrategy.IdentityByDefaultColumn or NpgsqlValueGenerationStrategy.IdentityAlwaysColumn)
9190
{
9291
if (valueGeneratedProperty[NpgsqlAnnotationNames.IdentityOptions] is string identityOptions)
9392
{

src/EFCore.PG/Metadata/PostgresExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private static (string? Schema, string? Name, string? Version) Deserialize(IAnno
192192
}
193193

194194
// TODO: Can't actually use schema and name...they might not be set when this is first called.
195-
var schemaNameValue = value.Split(',').Select(x => x.Trim()).Select(x => x == "" || x == "''" ? null : x).ToArray();
195+
var schemaNameValue = value.Split(',').Select(x => x.Trim()).Select(x => x is "" or "''" ? null : x).ToArray();
196196
var schemaAndName = annotation.Name.Substring(NpgsqlAnnotationNames.PostgresExtensionPrefix.Length).Split('.');
197197
switch (schemaAndName.Length)
198198
{

src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected override void Generate(
169169

170170
builder.Append("CREATE ");
171171

172-
if (operation[NpgsqlAnnotationNames.UnloggedTable] is bool unlogged && unlogged)
172+
if (operation[NpgsqlAnnotationNames.UnloggedTable] is true)
173173
{
174174
builder.Append("UNLOGGED ");
175175
}
@@ -312,8 +312,8 @@ protected override void Generate(AlterTableOperation operation, IModel? model, M
312312
}
313313

314314
// Unlogged table (null is equivalent to false)
315-
var oldUnlogged = operation.OldTable[NpgsqlAnnotationNames.UnloggedTable] is bool ou && ou;
316-
var newUnlogged = operation[NpgsqlAnnotationNames.UnloggedTable] is bool nu && nu;
315+
var oldUnlogged = operation.OldTable[NpgsqlAnnotationNames.UnloggedTable] is true;
316+
var newUnlogged = operation[NpgsqlAnnotationNames.UnloggedTable] is true;
317317

318318
if (oldUnlogged != newUnlogged)
319319
{
@@ -511,14 +511,14 @@ protected override void Generate(AlterColumnOperation operation, IModel? model,
511511
builder.AppendLine(";");
512512
}
513513

514-
if (operation.IsNullable && !operation.OldColumn.IsNullable)
514+
if (operation is { IsNullable: true, OldColumn.IsNullable: false })
515515
{
516516
builder
517517
.Append(alterBase)
518518
.Append("DROP NOT NULL")
519519
.AppendLine(";");
520520
}
521-
else if (!operation.IsNullable && operation.OldColumn.IsNullable)
521+
else if (operation is { IsNullable: false, OldColumn.IsNullable: true })
522522
{
523523
// The column is being made non-nullable. Generate an update statement before doing that, to convert any existing null values to
524524
// the default value (otherwise PostgreSQL fails).
@@ -2046,7 +2046,7 @@ private string IndexColumnList(IndexColumn[] columns, string? method)
20462046

20472047
// Of the built-in access methods, only btree (the default) supports
20482048
// sorting, thus we only want to emit sort options for btree indexes.
2049-
if (method is null || method == "btree")
2049+
if (method is null or "btree")
20502050
{
20512051
if (column.IsDescending)
20522052
{

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlArrayMethodTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class NpgsqlArrayMethodTranslator : IMethodCallTranslator
1717
// ReSharper disable InconsistentNaming
1818
private static readonly MethodInfo Array_IndexOf1 =
1919
typeof(Array).GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
20-
.Single(m => m.Name == nameof(Array.IndexOf) && m.IsGenericMethod && m.GetParameters().Length == 2);
20+
.Single(m => m is { Name: nameof(Array.IndexOf), IsGenericMethod: true } && m.GetParameters().Length == 2);
2121

2222
private static readonly MethodInfo Array_IndexOf2 =
2323
typeof(Array).GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public NpgsqlJsonDbFunctionsTranslator(
7979
}
8080

8181
// The following are jsonb-only, not support on json
82-
if (args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping jsonMapping && !jsonMapping.IsJsonb))
82+
if (args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping { IsJsonb: false }))
8383
{
8484
throw new InvalidOperationException("JSON methods on EF.Functions only support the jsonb type, not json.");
8585
}
@@ -109,8 +109,7 @@ SqlExpression Jsonb(SqlExpression e)
109109

110110
static SqlExpression RemoveConvert(SqlExpression e)
111111
{
112-
while (e is SqlUnaryExpression unary &&
113-
(unary.OperatorType == ExpressionType.Convert || unary.OperatorType == ExpressionType.ConvertChecked))
112+
while (e is SqlUnaryExpression { OperatorType: ExpressionType.Convert or ExpressionType.ConvertChecked } unary)
114113
{
115114
e = unary.Operand;
116115
}

0 commit comments

Comments
 (0)