Skip to content

Commit

Permalink
Code cleanup (#2938)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Nov 13, 2023
1 parent a173de7 commit ba2bae4
Show file tree
Hide file tree
Showing 460 changed files with 9,341 additions and 7,447 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,9 @@ dotnet_naming_symbols.everything_else.applicable_accessibilities = *
dotnet_naming_rule.everything_else_naming.symbols = everything_else
dotnet_naming_rule.everything_else_naming.style = camel_case_style
dotnet_naming_rule.everything_else_naming.severity = suggestion

# Microsoft .NET properties
csharp_style_expression_bodied_methods = true:suggestion

# ReSharper properties
resharper_local_function_body = expression_body
4 changes: 0 additions & 4 deletions EFCore.PG.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/XmlFormatter/WrapInsideText/@EntryValue">True</s:Boolean>

<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/QualifiedUsingAtNestedScope/@EntryValue">True</s:Boolean>


<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">Licensed to the .NET Foundation under one or more agreements.&#xD;
The .NET Foundation licenses this file to you under the MIT license.&#xD;
</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Generate/=Constructor/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Generate/=Constructor/Options/=XmlDocumentation/@EntryIndexedValue">True</s:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollec
.AddSingleton<IRelationalTypeMappingSourcePlugin, NpgsqlNetTopologySuiteTypeMappingSourcePlugin>()
.AddSingleton<IProviderCodeGeneratorPlugin, NpgsqlNetTopologySuiteCodeGeneratorPlugin>()
.TryAddSingleton<INpgsqlNetTopologySuiteOptions, NpgsqlNetTopologySuiteOptions>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Microsoft.EntityFrameworkCore;

/// <summary>
/// NetTopologySuite specific extension methods for <see cref="NpgsqlDbContextOptionsBuilder"/>.
/// NetTopologySuite specific extension methods for <see cref="NpgsqlDbContextOptionsBuilder" />.
/// </summary>
public static class NpgsqlNetTopologySuiteDbContextOptionsBuilderExtensions
{
/// <summary>
/// Use NetTopologySuite to access SQL Server spatial data.
/// Use NetTopologySuite to access SQL Server spatial data.
/// </summary>
/// <returns>
/// The options builder so that further configuration can be chained.
/// The options builder so that further configuration can be chained.
/// </returns>
public static NpgsqlDbContextOptionsBuilder UseNetTopologySuite(
this NpgsqlDbContextOptionsBuilder optionsBuilder,
Expand All @@ -26,7 +26,8 @@ public static NpgsqlDbContextOptionsBuilder UseNetTopologySuite(

// TODO: Global-only setup at the ADO.NET level for now, optionally allow per-connection?
#pragma warning disable CS0618 // NpgsqlConnection.GlobalTypeMapper is obsolete
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite(coordinateSequenceFactory, precisionModel, handleOrdinates, geographyAsDefault);
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite(
coordinateSequenceFactory, precisionModel, handleOrdinates, geographyAsDefault);
#pragma warning restore CS0618

var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
// ReSharper disable once CheckNamespace

namespace Microsoft.EntityFrameworkCore;

/// <summary>
/// Provides Npgsql-specific spatial extension methods on <see cref="DbFunctions"/>.
/// Provides Npgsql-specific spatial extension methods on <see cref="DbFunctions" />.
/// </summary>
public static class NpgsqlNetTopologySuiteDbFunctionsExtensions
{
/// <summary>
/// Returns a new geometry with its coordinates transformed to a different spatial reference system.
/// Translates to <c>ST_Transform(geometry, srid)</c>.
/// Returns a new geometry with its coordinates transformed to a different spatial reference system.
/// Translates to <c>ST_Transform(geometry, srid)</c>.
/// </summary>
/// <remarks>
/// See https://postgis.net/docs/ST_Transform.html.
/// See https://postgis.net/docs/ST_Transform.html.
/// </remarks>
public static TGeometry Transform<TGeometry>(this DbFunctions _, TGeometry geometry, int srid)
where TGeometry : Geometry
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Transform)));

/// <summary>
/// Forces the geometries into a "2-dimensional mode" so that all output representations will only have the X and Y coordinates.
/// Translates to <c>ST_Force2D(geometry)</c>
/// Forces the geometries into a "2-dimensional mode" so that all output representations will only have the X and Y coordinates.
/// Translates to <c>ST_Force2D(geometry)</c>
/// </summary>
/// <remarks>
/// See https://postgis.net/docs/ST_Force2D.html.
/// See https://postgis.net/docs/ST_Force2D.html.
/// </remarks>
public static TGeometry Force2D<TGeometry>(this DbFunctions _, TGeometry geometry)
where TGeometry : Geometry
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Force2D)));

/// <summary>
/// Tests whether the distance from the origin geometry to another is less than or equal to a specified value.
/// Translates to <c>ST_DWithin</c>.
/// Tests whether the distance from the origin geometry to another is less than or equal to a specified value.
/// Translates to <c>ST_DWithin</c>.
/// </summary>
/// <remarks>
/// See https://postgis.net/docs/ST_DWithin.html.
/// See https://postgis.net/docs/ST_DWithin.html.
/// </remarks>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="geometry">The origin geometry.</param>
Expand All @@ -45,11 +46,11 @@ public static bool IsWithinDistance(this DbFunctions _, Geometry geometry, Geome
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IsWithinDistance)));

/// <summary>
/// Returns the minimum distance between the origin geometry and another geometry g.
/// Translates to <c>ST_Distance</c>.
/// Returns the minimum distance between the origin geometry and another geometry g.
/// Translates to <c>ST_Distance</c>.
/// </summary>
/// <remarks>
/// See https://postgis.net/docs/ST_Distance.html.
/// See https://postgis.net/docs/ST_Distance.html.
/// </remarks>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="geometry">The origin geometry.</param>
Expand All @@ -60,11 +61,11 @@ public static double Distance(this DbFunctions _, Geometry geometry, Geometry an
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Distance)));

/// <summary>
/// Returns the 2D distance between two geometries. Used in the "ORDER BY" clause, provides index-assisted nearest-neighbor result
/// sets. Translates to <c>&lt;-&gt;</c>.
/// Returns the 2D distance between two geometries. Used in the "ORDER BY" clause, provides index-assisted nearest-neighbor result
/// sets. Translates to <c>&lt;-&gt;</c>.
/// </summary>
/// <remarks>
/// See https://postgis.net/docs/ST_Distance.html.
/// See https://postgis.net/docs/ST_Distance.html.
/// </remarks>
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
/// <param name="geometry">The origin geometry.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
/// Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite extension methods for <see cref="IServiceCollection" />.
/// Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite extension methods for <see cref="IServiceCollection" />.
/// </summary>
public static class NpgsqlNetTopologySuiteServiceCollectionExtensions
{
/// <summary>
/// Adds the services required for NetTopologySuite support in the Npgsql provider for Entity Framework.
/// Adds the services required for NetTopologySuite support in the Npgsql provider for Entity Framework.
/// </summary>
/// <param name="serviceCollection">The <see cref="IServiceCollection" /> to add services to.</param>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
Expand All @@ -31,7 +31,6 @@ public static IServiceCollection AddEntityFrameworkNpgsqlNetTopologySuite(
.TryAddProviderSpecificServices(
x => x.TryAddSingleton<INpgsqlNetTopologySuiteOptions, NpgsqlNetTopologySuiteOptions>());


return serviceCollection;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@


// ReSharper disable once CheckNamespace

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;

/// <summary>
/// Represents options for Npgsql NetTopologySuite that can only be set at the <see cref="System.IServiceProvider"/> singleton level.
/// Represents options for Npgsql NetTopologySuite that can only be set at the <see cref="System.IServiceProvider" /> singleton level.
/// </summary>
public interface INpgsqlNetTopologySuiteOptions : ISingletonOptions
{
/// <summary>
/// True if geography is to be used by default instead of geometry
/// True if geography is to be used by default instead of geometry
/// </summary>
bool IsGeographyDefault { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NpgsqlNetTopologySuiteOptionsExtension : IDbContextOptionsExtension
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public NpgsqlNetTopologySuiteOptionsExtension() {}
public NpgsqlNetTopologySuiteOptionsExtension() { }

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -37,15 +37,18 @@ public NpgsqlNetTopologySuiteOptionsExtension() {}
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected NpgsqlNetTopologySuiteOptionsExtension(NpgsqlNetTopologySuiteOptionsExtension copyFrom)
=> IsGeographyDefault = copyFrom.IsGeographyDefault;
{
IsGeographyDefault = copyFrom.IsGeographyDefault;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual NpgsqlNetTopologySuiteOptionsExtension Clone() => new(this);
protected virtual NpgsqlNetTopologySuiteOptionsExtension Clone()
=> new(this);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -96,9 +99,11 @@ public virtual void Validate(IDbContextOptions options)
using (var scope = internalServiceProvider.CreateScope())
{
if (scope.ServiceProvider.GetService<IEnumerable<IRelationalTypeMappingSourcePlugin>>()
?.Any(s => s is NpgsqlNetTopologySuiteTypeMappingSourcePlugin) != true)
?.Any(s => s is NpgsqlNetTopologySuiteTypeMappingSourcePlugin)
!= true)
{
throw new InvalidOperationException($"{nameof(NpgsqlNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite)} requires {nameof(NpgsqlNetTopologySuiteServiceCollectionExtensions.AddEntityFrameworkNpgsqlNetTopologySuite)} to be called on the internal service provider used.");
throw new InvalidOperationException(
$"{nameof(NpgsqlNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite)} requires {nameof(NpgsqlNetTopologySuiteServiceCollectionExtensions.AddEntityFrameworkNpgsqlNetTopologySuite)} to be called on the internal service provider used.");
}
}
}
Expand All @@ -116,9 +121,11 @@ public ExtensionInfo(IDbContextOptionsExtension extension)
private new NpgsqlNetTopologySuiteOptionsExtension Extension
=> (NpgsqlNetTopologySuiteOptionsExtension)base.Extension;

public override bool IsDatabaseProvider => false;
public override bool IsDatabaseProvider
=> false;

public override int GetServiceProviderHashCode() => Extension.IsGeographyDefault.GetHashCode();
public override int GetServiceProviderHashCode()
=> Extension.IsGeographyDefault.GetHashCode();

public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
=> true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ReSharper disable once CheckNamespace

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Internal;

/// <summary>
Expand All @@ -25,4 +23,3 @@ public virtual ConventionSet ModifyConventions(ConventionSet conventionSet)
return conventionSet;
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ReSharper disable once CheckNamespace

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Internal;

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions src/EFCore.PG.NTS/Internal/NpgsqlNetTopologySuiteOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public class NpgsqlNetTopologySuiteOptions : INpgsqlNetTopologySuiteOptions
/// <inheritdoc />
public virtual void Initialize(IDbContextOptions options)
{
var npgsqlNtsOptions = options.FindExtension<NpgsqlNetTopologySuiteOptionsExtension>() ?? new NpgsqlNetTopologySuiteOptionsExtension();
var npgsqlNtsOptions = options.FindExtension<NpgsqlNetTopologySuiteOptionsExtension>()
?? new NpgsqlNetTopologySuiteOptionsExtension();

IsGeographyDefault = npgsqlNtsOptions.IsGeographyDefault;
}

/// <inheritdoc />
public virtual void Validate(IDbContextOptions options) {}
}
public virtual void Validate(IDbContextOptions options) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public NpgsqlNetTopologySuiteAggregateMethodTranslator(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual SqlExpression? Translate(
MethodInfo method, EnumerableExpression source, IReadOnlyList<SqlExpression> arguments,
MethodInfo method,
EnumerableExpression source,
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
if (source.Selector is not SqlExpression sqlExpression)
Expand Down
Loading

0 comments on commit ba2bae4

Please sign in to comment.