Skip to content

Commit

Permalink
Evolve null-checking approach in extensions (#26527)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Nov 4, 2021
1 parent 99f1674 commit 74f4e5e
Show file tree
Hide file tree
Showing 28 changed files with 3 additions and 126 deletions.
4 changes: 0 additions & 4 deletions src/EFCore.Proxies/ProxiesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public static DbContextOptionsBuilder UseChangeTrackingProxies(
bool useChangeTrackingProxies = true,
bool checkEquality = true)
{
Check.NotNull(optionsBuilder, nameof(optionsBuilder));

var extension = optionsBuilder.Options.FindExtension<ProxiesOptionsExtension>()
?? new ProxiesOptionsExtension();

Expand Down Expand Up @@ -117,8 +115,6 @@ public static DbContextOptionsBuilder UseLazyLoadingProxies(
this DbContextOptionsBuilder optionsBuilder,
bool useLazyLoadingProxies = true)
{
Check.NotNull(optionsBuilder, nameof(optionsBuilder));

var extension = optionsBuilder.Options.FindExtension<ProxiesOptionsExtension>()
?? new ProxiesOptionsExtension();

Expand Down
3 changes: 0 additions & 3 deletions src/EFCore.Proxies/ProxiesServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Proxies.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand All @@ -32,8 +31,6 @@ public static class ProxiesServiceCollectionExtensions
public static IServiceCollection AddEntityFrameworkProxies(
this IServiceCollection serviceCollection)
{
Check.NotNull(serviceCollection, nameof(serviceCollection));

new EntityFrameworkServicesBuilder(serviceCollection)
.TryAdd<IConventionSetPlugin, ProxiesConventionSetPlugin>()
.TryAddProviderSpecificServices(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore
{
Expand All @@ -25,8 +24,6 @@ public static class SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions
public static SqlServerDbContextOptionsBuilder UseNetTopologySuite(
this SqlServerDbContextOptionsBuilder optionsBuilder)
{
Check.NotNull(optionsBuilder, nameof(optionsBuilder));

var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;

var extension = coreOptionsBuilder.Options.FindExtension<SqlServerNetTopologySuiteOptionsExtension>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NetTopologySuite;

Expand All @@ -30,8 +29,6 @@ public static class SqlServerNetTopologySuiteServiceCollectionExtensions
public static IServiceCollection AddEntityFrameworkSqlServerNetTopologySuite(
this IServiceCollection serviceCollection)
{
Check.NotNull(serviceCollection, nameof(serviceCollection));

serviceCollection.TryAddSingleton(NtsGeometryServices.Instance);

new EntityFrameworkRelationalServicesBuilder(serviceCollection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal
Expand Down Expand Up @@ -45,10 +44,6 @@ public SqlServerGeometryCollectionMemberTranslator(ISqlExpressionFactory sqlExpr
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (Equals(member, _count))
{
return _sqlExpressionFactory.Function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal
Expand Down Expand Up @@ -51,10 +50,6 @@ public SqlServerGeometryCollectionMethodTranslator(
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));

if (Equals(method, _item)
&& instance != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ public SqlServerGeometryMemberTranslator(
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (typeof(Geometry).IsAssignableFrom(member.DeclaringType))
{
Check.DebugAssert(instance!.TypeMapping != null, "Instance must have typeMapping assigned.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public SqlServerGeometryMethodTranslator(
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));

if (typeof(Geometry).IsAssignableFrom(method.DeclaringType)
&& instance != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public SqlServerLineStringMemberTranslator(
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (_memberToFunctionName.TryGetValue(member, out var functionName))
{
Check.DebugAssert(instance!.TypeMapping != null, "Instance must have typeMapping assigned.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public SqlServerLineStringMethodTranslator(
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));

if (Equals(method, _getPointN)
&& instance != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal
Expand Down Expand Up @@ -45,10 +44,6 @@ public SqlServerMultiLineStringMemberTranslator(ISqlExpressionFactory sqlExpress
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (Equals(member, _isClosed))
{
return _sqlExpressionFactory.Function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public SqlServerPointMemberTranslator(ISqlExpressionFactory sqlExpressionFactory
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (typeof(Point).IsAssignableFrom(member.DeclaringType))
{
Check.DebugAssert(instance!.TypeMapping != null, "Instance must have typeMapping assigned.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public SqlServerPolygonMemberTranslator(
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (typeof(Polygon).IsAssignableFrom(member.DeclaringType))
{
Check.DebugAssert(instance!.TypeMapping != null, "Instance must have typeMapping assigned.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public SqlServerPolygonMethodTranslator(
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));

if (Equals(method, _getInteriorRingN))
{
Check.DebugAssert(instance!.TypeMapping != null, "Instance must have typeMapping assigned.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite;
using NetTopologySuite.Geometries;

Expand All @@ -30,8 +29,6 @@ public class SqlServerNetTopologySuiteTypeMappingSourcePlugin : IRelationalTypeM
/// </summary>
public SqlServerNetTopologySuiteTypeMappingSourcePlugin(NtsGeometryServices geometryServices)
{
Check.NotNull(geometryServices, nameof(geometryServices));

_geometryServices = geometryServices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
Expand All @@ -29,8 +28,6 @@ public static class SqliteNetTopologySuiteDbContextOptionsBuilderExtensions
public static SqliteDbContextOptionsBuilder UseNetTopologySuite(
this SqliteDbContextOptionsBuilder optionsBuilder)
{
Check.NotNull(optionsBuilder, nameof(optionsBuilder));

var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;
var infrastructure = (IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder;
#pragma warning disable EF1001 // Internal EF Core API usage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.EntityFrameworkCore.Sqlite.Query.Internal;
using Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NetTopologySuite;

Expand All @@ -30,8 +29,6 @@ public static class SqliteNetTopologySuiteServiceCollectionExtensions
public static IServiceCollection AddEntityFrameworkSqliteNetTopologySuite(
this IServiceCollection serviceCollection)
{
Check.NotNull(serviceCollection, nameof(serviceCollection));

serviceCollection.TryAddSingleton(NtsGeometryServices.Instance);

new EntityFrameworkRelationalServicesBuilder(serviceCollection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,13 @@ public SqliteGeometryCollectionMemberTranslator(ISqlExpressionFactory sqlExpress
MemberInfo member,
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

return Equals(member, _count)
=> Equals(member, _count)
? _sqlExpressionFactory.Function(
"NumGeometries",
new[] { instance! },
nullable: true,
argumentsPropagateNullability: new[] { true },
returnType)
: null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
Expand Down Expand Up @@ -46,10 +45,6 @@ public SqliteGeometryCollectionMethodTranslator(ISqlExpressionFactory sqlExpress
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));

if (Equals(method, _item))
{
return _sqlExpressionFactory.Function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
Expand Down Expand Up @@ -65,10 +64,6 @@ public SqliteGeometryMemberTranslator(ISqlExpressionFactory sqlExpressionFactory
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (instance != null)
{
if (_memberToFunctionName.TryGetValue(member, out var functionName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
Expand Down Expand Up @@ -81,10 +80,6 @@ public SqliteGeometryMethodTranslator(ISqlExpressionFactory sqlExpressionFactory
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));

if (instance != null)
{
if (_methodToFunctionName.TryGetValue(method, out var functionName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
Expand Down Expand Up @@ -55,10 +54,6 @@ public SqliteLineStringMemberTranslator(ISqlExpressionFactory sqlExpressionFacto
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (_memberToFunctionName.TryGetValue(member, out var functionName)
&& instance != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
Expand Down Expand Up @@ -48,10 +47,6 @@ public SqliteLineStringMethodTranslator(ISqlExpressionFactory sqlExpressionFacto
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));

if (Equals(method, _getPointN))
{
return _sqlExpressionFactory.Function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
using NetTopologySuite.Geometries;

namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
Expand Down Expand Up @@ -45,10 +44,6 @@ public SqliteMultiLineStringMemberTranslator(ISqlExpressionFactory sqlExpression
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(member, nameof(member));
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));

if (Equals(member, _isClosed)
&& instance != null)
{
Expand Down
Loading

0 comments on commit 74f4e5e

Please sign in to comment.