Skip to content

Commit

Permalink
Some missed NotNulls.
Browse files Browse the repository at this point in the history
  • Loading branch information
lajones committed Jun 4, 2020
1 parent 546547d commit f9b6d7c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
28 changes: 14 additions & 14 deletions src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ namespace Microsoft.EntityFrameworkCore
public static class RelationalIndexExtensions
{
/// <summary>
/// Returns the name of the index on the database.
/// Returns the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <returns> The name of the index on the database. </returns>
/// <returns> The name of the index in the database. </returns>
public static string GetDatabaseName([NotNull] this IIndex index)
=> (string)index[RelationalAnnotationNames.Name]
?? index.Name
?? index.GetDefaultDatabaseName();

/// <summary>
/// Returns the name of the index on the database.
/// Returns the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <returns> The name of the index on the database. </returns>
/// <returns> The name of the index in the database. </returns>
[Obsolete("Use GetDatabaseName() instead")]
public static string GetName([NotNull] this IIndex index)
=> GetDatabaseName(index);

/// <summary>
/// Returns the name of the index on the database.
/// Returns the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <param name="tableName"> The table name. </param>
/// <param name="schema"> The schema. </param>
/// <returns> The name of the index on the database. </returns>
/// <returns> The name of the index in the database. </returns>
public static string GetDatabaseName(
[NotNull] this IIndex index,
[NotNull] string tableName,
Expand Down Expand Up @@ -127,7 +127,7 @@ public static string GetDefaultDatabaseName(
}

/// <summary>
/// Sets the name of the index on the database.
/// Sets the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <param name="name"> The value to set. </param>
Expand All @@ -139,7 +139,7 @@ public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNul
}

/// <summary>
/// Sets the name of the index on the database.
/// Sets the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <param name="name"> The value to set. </param>
Expand All @@ -148,7 +148,7 @@ public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] strin
=> SetDatabaseName(index, name);

/// <summary>
/// Sets the name of the index on the database.
/// Sets the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <param name="name"> The value to set. </param>
Expand All @@ -165,7 +165,7 @@ public static string SetDatabaseName([NotNull] this IConventionIndex index, [Can
}

/// <summary>
/// Sets the name of the index on the database.
/// Sets the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <param name="name"> The value to set. </param>
Expand All @@ -176,18 +176,18 @@ public static string SetName([NotNull] this IConventionIndex index, [CanBeNull]
=> SetDatabaseName(index, name, fromDataAnnotation);

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the name of the index on the database.
/// Gets the <see cref="ConfigurationSource" /> for the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the name of the index on the database. </returns>
/// <returns> The <see cref="ConfigurationSource" /> for the name of the index in the database. </returns>
public static ConfigurationSource? GetDatabaseNameConfigurationSource([NotNull] this IConventionIndex index)
=> index.FindAnnotation(RelationalAnnotationNames.Name)?.GetConfigurationSource();

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the name of the index on the database.
/// Gets the <see cref="ConfigurationSource" /> for the name of the index in the database.
/// </summary>
/// <param name="index"> The index. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the name of the index on the database. </returns>
/// <returns> The <see cref="ConfigurationSource" /> for the name of the index in the database. </returns>
[Obsolete("Use GetDatabaseNameConfigurationSource() instead.")]
public static ConfigurationSource? GetNameConfigurationSource([NotNull] this IConventionIndex index)
=> GetDatabaseNameConfigurationSource(index);
Expand Down
7 changes: 5 additions & 2 deletions src/EFCore/Metadata/Builders/EntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,12 @@ public virtual IndexBuilder HasIndex([NotNull] params string[] propertyNames)
/// <returns> An object that can be used to configure the index. </returns>
public virtual IndexBuilder HasIndex(
[NotNull] string[] propertyNames,
[CanBeNull] string name)
[NotNull] string name)
=> new IndexBuilder(
Builder.HasIndex(Check.NotEmpty(propertyNames, nameof(propertyNames)), name, ConfigurationSource.Explicit).Metadata);
Builder.HasIndex(
Check.NotEmpty(propertyNames, nameof(propertyNames)),
Check.NotEmpty(name, nameof(name)),
ConfigurationSource.Explicit).Metadata);

/// <summary>
/// <para>
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public virtual IndexBuilder<TEntity> HasIndex([NotNull] Expression<Func<TEntity,
/// <returns> An object that can be used to configure the index. </returns>
public virtual IndexBuilder<TEntity> HasIndex(
[NotNull] Expression<Func<TEntity, object>> indexExpression,
[CanBeNull] string name)
[NotNull] string name)
=> new IndexBuilder<TEntity>(
Builder.HasIndex(
Check.NotNull(indexExpression, nameof(indexExpression)).GetMemberAccessList(),
Expand Down Expand Up @@ -286,7 +286,7 @@ public virtual IndexBuilder<TEntity> HasIndex(
/// <returns> An object that can be used to configure the index. </returns>
public new virtual IndexBuilder<TEntity> HasIndex(
[NotNull] string[] propertyNames,
[CanBeNull] string name)
[NotNull] string name)
=> new IndexBuilder<TEntity>(
Builder.HasIndex(
Check.NotEmpty(propertyNames, nameof(propertyNames)),
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/IConventionEntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ IConventionIndex AddIndex(
/// <returns> The newly created index. </returns>
IConventionIndex AddIndex(
[NotNull] IReadOnlyList<IConventionProperty> properties,
[CanBeNull] string name,
[NotNull] string name,
bool fromDataAnnotation = false);

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore/Metadata/Internal/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,7 @@ public virtual Index AddIndex(
/// </summary>
public virtual Index AddIndex(
[NotNull] Property property,
[CanBeNull] string name,
[NotNull] string name,
ConfigurationSource configurationSource)
=> AddIndex(
new[] { property }, name, configurationSource);
Expand Down Expand Up @@ -1931,7 +1931,7 @@ public virtual Index AddIndex(
return (Index)Model.ConventionDispatcher.OnIndexAdded(index.Builder)?.Metadata;
}

private void CheckIndexProperties([NotNull] IReadOnlyList<Property> properties)
private void CheckIndexProperties(IReadOnlyList<Property> properties)
{
for (var i = 0; i < properties.Count; i++)
{
Expand All @@ -1952,7 +1952,7 @@ private void CheckIndexProperties([NotNull] IReadOnlyList<Property> properties)
}
}

private void UpdatePropertyIndexes([NotNull] IReadOnlyList<Property> properties, [NotNull] Index index)
private void UpdatePropertyIndexes(IReadOnlyList<Property> properties, Index index)
{
foreach (var property in properties)
{
Expand Down Expand Up @@ -2039,7 +2039,7 @@ public virtual Index FindDeclaredIndex([NotNull] IReadOnlyList<IProperty> proper
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual Index FindDeclaredIndex([NotNull] string name)
=> _namedIndexes.TryGetValue(name, out var index)
=> _namedIndexes.TryGetValue(Check.NotEmpty(name, nameof(name)), out var index)
? index
: null;

Expand Down Expand Up @@ -2077,7 +2077,7 @@ public virtual IEnumerable<Index> FindIndexesInHierarchy([NotNull] IReadOnlyList
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IEnumerable<Index> FindIndexesInHierarchy([NotNull] string name)
=> ToEnumerable(FindIndex(name)).Concat(FindDerivedIndexes(name));
=> ToEnumerable(FindIndex(Check.NotEmpty(name, nameof(name)))).Concat(FindDerivedIndexes(name));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
28 changes: 15 additions & 13 deletions src/EFCore/Metadata/Internal/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ public Index(
[NotNull] IReadOnlyList<Property> properties,
[NotNull] EntityType declaringEntityType,
ConfigurationSource configurationSource)
: this(properties, null, declaringEntityType, configurationSource)
{
Check.NotEmpty(properties, nameof(properties));
Check.HasNoNulls(properties, nameof(properties));
Check.NotNull(declaringEntityType, nameof(declaringEntityType));

Properties = properties;
DeclaringEntityType = declaringEntityType;
_configurationSource = configurationSource;

Builder = new InternalIndexBuilder(this, declaringEntityType.Model.Builder);
}

/// <summary>
Expand All @@ -51,21 +59,15 @@ public Index(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public Index(
[NotNull] IReadOnlyList<Property> properties,
[CanBeNull] string name,
[NotNull] EntityType declaringEntityType,
ConfigurationSource configurationSource)
[NotNull] IReadOnlyList<Property> properties,
[NotNull] string name,
[NotNull] EntityType declaringEntityType,
ConfigurationSource configurationSource)
: this(properties, declaringEntityType, configurationSource)
{
Check.NotEmpty(properties, nameof(properties));
Check.HasNoNulls(properties, nameof(properties));
Check.NotNull(declaringEntityType, nameof(declaringEntityType));
Check.NotEmpty(name, nameof(name));

Properties = properties;
Name = name;
DeclaringEntityType = declaringEntityType;
_configurationSource = configurationSource;

Builder = new InternalIndexBuilder(this, declaringEntityType.Model.Builder);
}

/// <summary>
Expand Down

0 comments on commit f9b6d7c

Please sign in to comment.