Skip to content

Commit

Permalink
Evolve null-checking approach in EFCore (#26557)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Nov 9, 2021
1 parent 491e1b5 commit 53fbd04
Show file tree
Hide file tree
Showing 132 changed files with 142 additions and 1,313 deletions.
4 changes: 0 additions & 4 deletions src/EFCore/ChangeTracking/ChangeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public ChangeTracker(
IModel model,
IEntityEntryGraphIterator graphIterator)
{
Check.NotNull(context, nameof(context));
Check.NotNull(stateManager, nameof(stateManager));
Check.NotNull(changeDetector, nameof(changeDetector));

Context = context;

_defaultQueryTrackingBehavior
Expand Down
2 changes: 0 additions & 2 deletions src/EFCore/ChangeTracking/EntityEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class EntityEntry : IInfrastructure<InternalEntityEntry>
[EntityFrameworkInternal]
public EntityEntry(InternalEntityEntry internalEntry)
{
Check.NotNull(internalEntry, nameof(internalEntry));

InternalEntry = internalEntry;
}

Expand Down
2 changes: 0 additions & 2 deletions src/EFCore/ChangeTracking/EntityEntryGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public EntityEntryGraphNode(
InternalEntityEntry? sourceEntry,
INavigationBase? inboundNavigation)
{
Check.NotNull(entry, nameof(entry));

_entry = entry;
_sourceEntry = sourceEntry;
InboundNavigation = inboundNavigation;
Expand Down
4 changes: 0 additions & 4 deletions src/EFCore/ChangeTracking/MemberEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.ChangeTracking
{
Expand Down Expand Up @@ -38,9 +37,6 @@ public abstract class MemberEntry : IInfrastructure<InternalEntityEntry>
[EntityFrameworkInternal]
protected MemberEntry(InternalEntityEntry internalEntry, IPropertyBase metadata)
{
Check.NotNull(internalEntry, nameof(internalEntry));
Check.NotNull(metadata, nameof(metadata));

InternalEntry = internalEntry;
Metadata = metadata;
}
Expand Down
5 changes: 0 additions & 5 deletions src/EFCore/DbContextOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore
{
Expand Down Expand Up @@ -46,8 +45,6 @@ protected DbContextOptions()
protected DbContextOptions(
IReadOnlyDictionary<Type, IDbContextOptionsExtension> extensions)
{
Check.NotNull(extensions, nameof(extensions));

_extensionsMap = ImmutableSortedDictionary.Create<Type, (IDbContextOptionsExtension, int)>(TypeFullNameComparer.Instance)
.AddRange(extensions.Select((p, i) => new KeyValuePair<Type, (IDbContextOptionsExtension, int)>(p.Key, (p.Value, i))));
}
Expand All @@ -62,8 +59,6 @@ protected DbContextOptions(
protected DbContextOptions(
ImmutableSortedDictionary<Type, (IDbContextOptionsExtension Extension, int Ordinal)> extensions)
{
Check.NotNull(extensions, nameof(extensions));

_extensionsMap = extensions;
}

Expand Down
6 changes: 1 addition & 5 deletions src/EFCore/DbContextOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,7 @@ public virtual DbContextOptionsBuilder ConfigureLoggingCacheTime(TimeSpan timeSp
/// <typeparam name="TExtension">The type of extension to be added.</typeparam>
/// <param name="extension">The extension to be added.</param>
void IDbContextOptionsBuilderInfrastructure.AddOrUpdateExtension<TExtension>(TExtension extension)
{
Check.NotNull(extension, nameof(extension));

_options = _options.WithExtension(extension);
}
=> _options = _options.WithExtension(extension);

private DbContextOptionsBuilder WithOption(Func<CoreOptionsExtension, CoreOptionsExtension> withFunc)
{
Expand Down
3 changes: 0 additions & 3 deletions src/EFCore/DbContextOptions`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore
{
Expand Down Expand Up @@ -51,8 +50,6 @@ private DbContextOptions(
/// <inheritdoc />
public override DbContextOptions WithExtension<TExtension>(TExtension extension)
{
Check.NotNull(extension, nameof(extension));

var type = extension.GetType();
var ordinal = ExtensionsMap.Count;
if (ExtensionsMap.TryGetValue(type, out var existingValue))
Expand Down
5 changes: 0 additions & 5 deletions src/EFCore/DbUpdateException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Runtime.Serialization;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Update;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore
{
Expand Down Expand Up @@ -73,8 +72,6 @@ public DbUpdateException(
IReadOnlyList<IUpdateEntry> entries)
: base(message, innerException)
{
Check.NotEmpty(entries, nameof(entries));

_entries = entries
.Where(e => e.EntityState != EntityState.Unchanged)
.Select(e => e.ToEntityEntry()).ToList();
Expand Down Expand Up @@ -104,8 +101,6 @@ public DbUpdateException(
IReadOnlyList<EntityEntry> entries)
: base(message, innerException)
{
Check.NotEmpty(entries, nameof(entries));

_entries = entries;
}

Expand Down
4 changes: 0 additions & 4 deletions src/EFCore/Design/AttributeCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design
{
Expand All @@ -25,9 +24,6 @@ public class AttributeCodeFragment
/// <param name="arguments">The attribute's arguments.</param>
public AttributeCodeFragment(Type type, params object[] arguments)
{
Check.NotNull(type, nameof(type));
Check.NotNull(arguments, nameof(arguments));

Type = type;
_arguments = new List<object>(arguments);
}
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore/Design/DesignTimeProviderServicesAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public sealed class DesignTimeProviderServicesAttribute : Attribute
/// The name of the type that can be used to add the database providers design time services to a <see cref="ServiceCollection" />.
/// This type should implement <see cref="IDesignTimeServices" />.
/// </param>
public DesignTimeProviderServicesAttribute(
string typeName)
public DesignTimeProviderServicesAttribute(string typeName)
{
Check.NotEmpty(typeName, nameof(typeName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design.Internal
{
Expand All @@ -21,8 +20,6 @@ public class CSharpRuntimeAnnotationCodeGenerator : ICSharpRuntimeAnnotationCode
/// <param name="dependencies">Parameter object containing dependencies for this service.</param>
public CSharpRuntimeAnnotationCodeGenerator(CSharpRuntimeAnnotationCodeGeneratorDependencies dependencies)
{
Check.NotNull(dependencies, nameof(dependencies));

Dependencies = dependencies;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design.Internal
{
Expand Down Expand Up @@ -42,8 +41,6 @@ public sealed record CSharpRuntimeAnnotationCodeGeneratorDependencies
[EntityFrameworkInternal]
public CSharpRuntimeAnnotationCodeGeneratorDependencies(ICSharpHelper cSharpHelper)
{
Check.NotNull(cSharpHelper, nameof(cSharpHelper));

CSharpHelper = cSharpHelper;
}

Expand Down
11 changes: 0 additions & 11 deletions src/EFCore/Design/MethodCallCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design
{
Expand All @@ -32,9 +31,6 @@ public class MethodCallCodeFragment
/// <param name="arguments">The method call's arguments. Can be <see cref="NestedClosureCodeFragment" />.</param>
public MethodCallCodeFragment(MethodInfo methodInfo, params object?[] arguments)
{
Check.NotNull(methodInfo, nameof(methodInfo));
Check.NotNull(arguments, nameof(arguments));

var parameterLength = methodInfo.GetParameters().Length;
if (methodInfo.IsStatic)
{
Expand All @@ -60,9 +56,6 @@ public MethodCallCodeFragment(MethodInfo methodInfo, params object?[] arguments)
[Obsolete("Use the overload accepting a MethodInfo")]
public MethodCallCodeFragment(string method, params object?[] arguments)
{
Check.NotEmpty(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));

_method = method;
_arguments = new List<object?>(arguments);
}
Expand All @@ -87,8 +80,6 @@ private MethodCallCodeFragment(
object?[] arguments)
: this(methodInfo, arguments)
{
Check.NotNull(chainedCall, nameof(chainedCall));

ChainedCall = chainedCall;
}

Expand All @@ -105,8 +96,6 @@ public MethodCallCodeFragment(
MethodCallCodeFragment chainedCall)
: this(method, arguments)
{
Check.NotNull(chainedCall, nameof(chainedCall));

ChainedCall = chainedCall;
}

Expand Down
7 changes: 0 additions & 7 deletions src/EFCore/Design/NestedClosureCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Design
{
Expand All @@ -22,9 +21,6 @@ public class NestedClosureCodeFragment
/// <param name="methodCall">The method call used as the body of the nested closure.</param>
public NestedClosureCodeFragment(string parameter, MethodCallCodeFragment methodCall)
{
Check.NotEmpty(parameter, nameof(parameter));
Check.NotNull(methodCall, nameof(methodCall));

Parameter = parameter;
MethodCalls = new List<MethodCallCodeFragment> { methodCall };
}
Expand All @@ -36,9 +32,6 @@ public NestedClosureCodeFragment(string parameter, MethodCallCodeFragment method
/// <param name="methodCalls">The list of method calls used as the body of the nested closure.</param>
public NestedClosureCodeFragment(string parameter, IReadOnlyList<MethodCallCodeFragment> methodCalls)
{
Check.NotEmpty(parameter, nameof(parameter));
Check.NotEmpty(methodCalls, nameof(methodCalls));

Parameter = parameter;
MethodCalls = methodCalls;
}
Expand Down
3 changes: 0 additions & 3 deletions src/EFCore/Diagnostics/CascadeDeleteEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
Expand Down Expand Up @@ -33,8 +32,6 @@ public CascadeDeleteEventData(
EntityState state)
: base(eventDefinition, messageGenerator, entityEntry)
{
Check.NotNull(parentEntry, nameof(parentEntry));

ParentEntityEntry = parentEntry;
State = state;
}
Expand Down
3 changes: 0 additions & 3 deletions src/EFCore/Diagnostics/CascadeDeleteOrphanEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
Expand Down Expand Up @@ -34,8 +33,6 @@ public CascadeDeleteOrphanEventData(
EntityState state)
: base(eventDefinition, messageGenerator, entityEntry)
{
Check.NotNull(parentEntityTypes, nameof(parentEntityTypes));

ParentEntityType = parentEntityTypes;
State = state;
}
Expand Down
5 changes: 0 additions & 5 deletions src/EFCore/Diagnostics/CollectionChangedEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
Expand Down Expand Up @@ -37,10 +36,6 @@ public CollectionChangedEventData(
IEnumerable<object> removed)
: base(eventDefinition, messageGenerator, navigation)
{
Check.NotNull(entityEntry, nameof(entityEntry));
Check.NotNull(added, nameof(added));
Check.NotNull(removed, nameof(removed));

EntityEntry = entityEntry;
Added = added;
Removed = removed;
Expand Down
3 changes: 0 additions & 3 deletions src/EFCore/Diagnostics/EntityEntryEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
Expand All @@ -29,8 +28,6 @@ public EntityEntryEventData(
EntityEntry entityEntry)
: base(eventDefinition, messageGenerator)
{
Check.NotNull(entityEntry, nameof(entityEntry));

EntityEntry = entityEntry;
}

Expand Down
3 changes: 0 additions & 3 deletions src/EFCore/Diagnostics/EventDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.Logging;

namespace Microsoft.EntityFrameworkCore.Diagnostics
Expand Down Expand Up @@ -37,8 +36,6 @@ public EventDefinition(
Func<LogLevel, Action<ILogger, Exception?>> logActionFunc)
: base(loggingOptions, eventId, level, eventIdCode)
{
Check.NotNull(logActionFunc, nameof(logActionFunc));

_logAction = logActionFunc(Level);
}

Expand Down
4 changes: 0 additions & 4 deletions src/EFCore/Diagnostics/EventDefinitionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.Logging;

namespace Microsoft.EntityFrameworkCore.Diagnostics
Expand Down Expand Up @@ -32,9 +31,6 @@ protected EventDefinitionBase(
LogLevel level,
string eventIdCode)
{
Check.NotNull(loggingOptions, nameof(loggingOptions));
Check.NotEmpty(eventIdCode, nameof(eventIdCode));

EventId = eventId;
EventIdCode = eventIdCode;

Expand Down
3 changes: 0 additions & 3 deletions src/EFCore/Diagnostics/EventDefinition`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.Logging;

namespace Microsoft.EntityFrameworkCore.Diagnostics
Expand Down Expand Up @@ -37,8 +36,6 @@ public EventDefinition(
Func<LogLevel, Action<ILogger, TParam, Exception?>> logActionFunc)
: base(loggingOptions, eventId, level, eventIdCode)
{
Check.NotNull(logActionFunc, nameof(logActionFunc));

_logAction = logActionFunc(Level);
}

Expand Down
Loading

0 comments on commit 53fbd04

Please sign in to comment.