Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various code style/cleanup #3261

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Npgsql.EntityFrameworkCore.PostgreSQL.Internal;

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public NpgsqlNetTopologySuiteAggregateMethodCallTranslatorPlugin(
throw new ArgumentException($"Must be an {nameof(NpgsqlSqlExpressionFactory)}", nameof(sqlExpressionFactory));
}

Translators = new IAggregateMethodCallTranslator[]
{
Translators =
[
new NpgsqlNetTopologySuiteAggregateMethodTranslator(npgsqlSqlExpressionFactory, typeMappingSource)
};
];
}

/// <summary>
Expand Down Expand Up @@ -103,19 +103,18 @@ public NpgsqlNetTopologySuiteAggregateMethodTranslator(
// https://postgis.net/docs/ST_ConvexHull.html
return _sqlExpressionFactory.Function(
"ST_ConvexHull",
new[]
{
[
_sqlExpressionFactory.AggregateFunction(
"ST_Collect",
new[] { sqlExpression },
[sqlExpression],
source,
nullable: true,
argumentsPropagateNullability: new[] { false },
argumentsPropagateNullability: [false],
typeof(Geometry),
GetMapping())
},
],
nullable: true,
argumentsPropagateNullability: new[] { true },
argumentsPropagateNullability: [true],
typeof(Geometry),
GetMapping());
}
Expand All @@ -127,10 +126,10 @@ public NpgsqlNetTopologySuiteAggregateMethodTranslator(
return _sqlExpressionFactory.Convert(
_sqlExpressionFactory.AggregateFunction(
"ST_Extent",
new[] { sqlExpression },
[sqlExpression],
source,
nullable: true,
argumentsPropagateNullability: new[] { false },
argumentsPropagateNullability: [false],
typeof(Geometry),
GetMapping()),
typeof(Geometry), GetMapping());
Expand All @@ -140,10 +139,10 @@ public NpgsqlNetTopologySuiteAggregateMethodTranslator(
{
return _sqlExpressionFactory.AggregateFunction(
method == UnionMethod ? "ST_Union" : "ST_Collect",
new[] { sqlExpression },
[sqlExpression],
source,
nullable: true,
argumentsPropagateNullability: new[] { false },
argumentsPropagateNullability: [false],
typeof(Geometry),
GetMapping());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public NpgsqlNetTopologySuiteMemberTranslatorPlugin(
IRelationalTypeMappingSource typeMappingSource,
ISqlExpressionFactory sqlExpressionFactory)
{
Translators = new IMemberTranslator[] { new NpgsqlGeometryMemberTranslator(sqlExpressionFactory, typeMappingSource), };
Translators = [new NpgsqlGeometryMemberTranslator(sqlExpressionFactory, typeMappingSource)];
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public NpgsqlNetTopologySuiteMethodCallTranslatorPlugin(
throw new ArgumentException($"Must be an {nameof(NpgsqlSqlExpressionFactory)}", nameof(sqlExpressionFactory));
}

Translators = new IMethodCallTranslator[] { new NpgsqlGeometryMethodTranslator(npgsqlSqlExpressionFactory, typeMappingSource), };
Translators = [new NpgsqlGeometryMethodTranslator(npgsqlSqlExpressionFactory, typeMappingSource)];
}

/// <summary>
Expand Down Expand Up @@ -90,15 +90,15 @@ public NpgsqlGeometryMethodTranslator(
{
nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.Transform) => _sqlExpressionFactory.Function(
"ST_Transform",
new[] { arguments[1], arguments[2] },
[arguments[1], arguments[2]],
nullable: true,
argumentsPropagateNullability: TrueArrays[2],
method.ReturnType,
arguments[1].TypeMapping),

nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.Force2D) => _sqlExpressionFactory.Function(
"ST_Force2D",
new[] { arguments[1] },
[arguments[1]],
nullable: true,
TrueArrays[1],
method.ReturnType,
Expand All @@ -110,9 +110,9 @@ public NpgsqlGeometryMethodTranslator(
arguments[2]),

nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.Distance) =>
TranslateGeometryMethod(arguments[1], method, new[] { arguments[2], arguments[3] }),
TranslateGeometryMethod(arguments[1], method, [arguments[2], arguments[3]]),
nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.IsWithinDistance) =>
TranslateGeometryMethod(arguments[1], method, new[] { arguments[2], arguments[3], arguments[4] }),
TranslateGeometryMethod(arguments[1], method, [arguments[2], arguments[3], arguments[4]]),

_ => null
};
Expand Down Expand Up @@ -147,7 +147,7 @@ public NpgsqlGeometryMethodTranslator(
{
return _sqlExpressionFactory.Function(
"ST_GeometryN",
new[] { instance, OneBased(arguments[0]) },
[instance, OneBased(arguments[0])],
nullable: true,
argumentsPropagateNullability: TrueArrays[2],
method.ReturnType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public NpgsqlNodaTimeAggregateMethodCallTranslatorPlugin(
throw new ArgumentException($"Must be an {nameof(NpgsqlSqlExpressionFactory)}", nameof(sqlExpressionFactory));
}

Translators = new IAggregateMethodCallTranslator[]
{
Translators =
[
new NpgsqlNodaTimeAggregateMethodTranslator(npgsqlSqlExpressionFactory, typeMappingSource)
};
];
}

/// <summary>
Expand Down Expand Up @@ -87,19 +87,19 @@ public NpgsqlNodaTimeAggregateMethodTranslator(
return method.Name switch
{
nameof(NpgsqlNodaTimeDbFunctionsExtensions.Sum) => _sqlExpressionFactory.AggregateFunction(
"sum", new[] { sqlExpression }, source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
"sum", [sqlExpression], source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
returnType: sqlExpression.Type, sqlExpression.TypeMapping),

nameof(NpgsqlNodaTimeDbFunctionsExtensions.Average) => _sqlExpressionFactory.AggregateFunction(
"avg", new[] { sqlExpression }, source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
"avg", [sqlExpression], source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
returnType: sqlExpression.Type, sqlExpression.TypeMapping),

nameof(NpgsqlNodaTimeDbFunctionsExtensions.RangeAgg) => _sqlExpressionFactory.AggregateFunction(
"range_agg", new[] { sqlExpression }, source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
"range_agg", [sqlExpression], source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
returnType: method.ReturnType, _typeMappingSource.FindMapping(method.ReturnType)),

nameof(NpgsqlNodaTimeDbFunctionsExtensions.RangeIntersectAgg) => _sqlExpressionFactory.AggregateFunction(
"range_intersect_agg", new[] { sqlExpression }, source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
"range_intersect_agg", [sqlExpression], source, nullable: true, argumentsPropagateNullability: FalseArrays[1],
returnType: sqlExpression.Type, sqlExpression.TypeMapping),

_ => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public NpgsqlNodaTimeMemberTranslatorPlugin(
IRelationalTypeMappingSource typeMappingSource,
ISqlExpressionFactory sqlExpressionFactory)
{
Translators = new IMemberTranslator[]
{
new NpgsqlNodaTimeMemberTranslator(typeMappingSource, (NpgsqlSqlExpressionFactory)sqlExpressionFactory),
};
Translators =
[
new NpgsqlNodaTimeMemberTranslator(typeMappingSource, (NpgsqlSqlExpressionFactory)sqlExpressionFactory)
];
}

/// <summary>
Expand Down Expand Up @@ -196,7 +196,7 @@ SqlExpression TranslateDurationTotalMember(SqlExpression instance, double diviso
return _sqlExpressionFactory.Not(
_sqlExpressionFactory.Function(
"lower_inf",
new[] { instance },
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(bool)));
Expand All @@ -207,7 +207,7 @@ SqlExpression TranslateDurationTotalMember(SqlExpression instance, double diviso
return _sqlExpressionFactory.Not(
_sqlExpressionFactory.Function(
"upper_inf",
new[] { instance },
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(bool)));
Expand All @@ -223,7 +223,7 @@ SqlExpression TranslateDurationTotalMember(SqlExpression instance, double diviso
SqlExpression Lower()
=> _sqlExpressionFactory.Function(
"lower",
new[] { instance },
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(Interval),
Expand All @@ -232,7 +232,7 @@ SqlExpression Lower()
SqlExpression Upper()
=> _sqlExpressionFactory.Function(
"upper",
new[] { instance },
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(Interval),
Expand Down Expand Up @@ -270,7 +270,7 @@ SqlExpression Upper()
SqlExpression Lower()
=> _sqlExpressionFactory.Function(
"lower",
new[] { instance },
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(LocalDate),
Expand All @@ -279,7 +279,7 @@ SqlExpression Lower()
SqlExpression Upper()
=> _sqlExpressionFactory.Function(
"upper",
new[] { instance },
[instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(LocalDate),
Expand All @@ -304,7 +304,7 @@ SqlExpression Upper()
"DayOfWeek" when GetDatePartExpression(instance, "dow", true) is var getValueExpression
=> _sqlExpressionFactory.Case(
getValueExpression,
new[] { new CaseWhenClause(_sqlExpressionFactory.Constant(0), _sqlExpressionFactory.Constant(7)) },
[new CaseWhenClause(_sqlExpressionFactory.Constant(0), _sqlExpressionFactory.Constant(7))],
getValueExpression),

// PG allows converting a timestamp directly to date, truncating the time; but given a timestamptz, it performs a time zone
Expand Down Expand Up @@ -350,7 +350,7 @@ private SqlExpression GetDatePartExpressionDouble(
{
var result = _sqlExpressionFactory.Function(
"date_part",
new[] { _sqlExpressionFactory.Constant(partName), instance },
[_sqlExpressionFactory.Constant(partName), instance],
nullable: true,
argumentsPropagateNullability: TrueArrays[2],
typeof(double));
Expand All @@ -359,7 +359,7 @@ private SqlExpression GetDatePartExpressionDouble(
{
result = _sqlExpressionFactory.Function(
"floor",
new[] { result },
[result],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(double));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public NpgsqlNodaTimeMethodCallTranslatorPlugin(
IRelationalTypeMappingSource typeMappingSource,
ISqlExpressionFactory sqlExpressionFactory)
{
Translators = new IMethodCallTranslator[]
{
new NpgsqlNodaTimeMethodCallTranslator(typeMappingSource, (NpgsqlSqlExpressionFactory)sqlExpressionFactory),
};
Translators =
[
new NpgsqlNodaTimeMethodCallTranslator(typeMappingSource, (NpgsqlSqlExpressionFactory)sqlExpressionFactory)
];
}

/// <summary>
Expand Down Expand Up @@ -336,8 +336,8 @@ public NpgsqlNodaTimeMethodCallTranslator(
static PgFunctionExpression IntervalPart(string datePart, SqlExpression parameter)
=> PgFunctionExpression.CreateWithNamedArguments(
"make_interval",
new[] { parameter },
new[] { datePart },
[parameter],
[datePart],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
builtIn: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// ReSharper disable once CheckNamespace


using System.Text;
using NodaTime.Text;
// ReSharper disable once CheckNamespace
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;

// ReSharper disable once CheckNamespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateEmbeddedNonNullSqlLiteral(object value)
=> $@"""{GenerateLiteralCore(value)}""";
=> $"""
"{GenerateLiteralCore(value)}"
""";

private string GenerateLiteralCore(object value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateEmbeddedNonNullSqlLiteral(object value)
=> $@"""{GenerateLiteralCore(value)}""";
=> $"""
"{GenerateLiteralCore(value)}"
""";

private string GenerateLiteralCore(object value)
=> PeriodPattern.NormalizingIso.Format((Period)value);
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore.PG.NodaTime/Storage/Internal/TimeTzMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateEmbeddedNonNullSqlLiteral(object value)
=> $@"""{Pattern.Format((OffsetTime)value)}""";
=> $"""
"{Pattern.Format((OffsetTime)value)}"
""";

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateEmbeddedNonNullSqlLiteral(object value)
=> $@"""{Format((LocalDateTime)value)}""";
=> $"""
"{Format((LocalDateTime)value)}"
""";

private static string Format(LocalDateTime localDateTime)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Globalization;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Storage.Json;
using NodaTime.Text;
Expand Down Expand Up @@ -88,7 +87,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateEmbeddedNonNullSqlLiteral(object value)
=> $@"""{Format((Instant)value)}""";
=> $"""
"{Format((Instant)value)}"
""";

private static string Format(Instant instant)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateEmbeddedNonNullSqlLiteral(object value)
=> $@"""{Format((OffsetDateTime)value)}""";
=> $"""
"{Format((OffsetDateTime)value)}"
""";

private static string Format(OffsetDateTime offsetDateTime)
=> OffsetDateTimePattern.ExtendedIso.Format(offsetDateTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateEmbeddedNonNullSqlLiteral(object value)
=> $@"""{Pattern.Format((ZonedDateTime)value)}""";
=> $"""
"{Pattern.Format((ZonedDateTime)value)}"
""";

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 0 additions & 2 deletions src/EFCore.PG/Extensions/ExpressionVisitorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// ReSharper disable once CheckNamespace
namespace System.Linq.Expressions;

#nullable enable

[DebuggerStepThrough]
internal static class ExpressionVisitorExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Npgsql.EntityFrameworkCore.PostgreSQL.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal;

Expand Down
Loading
Loading