Skip to content

Commit

Permalink
Scaffolding: Address API Review feedback
Browse files Browse the repository at this point in the history
Part of dotnet#27588
  • Loading branch information
bricelam committed Aug 19, 2022
1 parent 4cfbb5f commit 9259481
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/EFCore.Design/Design/FluentApiCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ IEnumerable<string> IMethodCallCodeFragment.TypeArguments
/// Gets or sets a value indicating whether this method call has an equivalent data annotation.
/// </summary>
/// <value>A value indicating whether this method call has an equivalent data annotation.</value>
public virtual bool HasDataAnnotation { get; set; }
public virtual bool IsHandledByDataAnnotations { get; set; }

/// <summary>
/// Gets the next method call to chain after this.
Expand Down Expand Up @@ -149,7 +149,7 @@ public virtual IEnumerable<string> GetRequiredUsings()
DeclaringType = currentLink.DeclaringType,
TypeArguments = currentLink.TypeArguments,
Arguments = currentLink.Arguments,
HasDataAnnotation = currentLink.HasDataAnnotation
IsHandledByDataAnnotations = currentLink.IsHandledByDataAnnotations
};
newRoot = newRoot?.Chain(unchained) ?? unchained;
}
Expand Down
32 changes: 16 additions & 16 deletions src/EFCore.Design/Extensions/ScaffoldingModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static string GetDbSetName(this IReadOnlyEntityType entityType)
/// </summary>
/// <param name="key">The key to check.</param>
/// <returns><see langword="true" /> if the key would be configured by conventions.</returns>
public static bool IsHandledByConventions(this IKey key)
public static bool IsHandledByConvention(this IKey key)
=> key is IConventionKey conventionKey
&& conventionKey.Properties.SequenceEqual(
KeyDiscoveryConvention.DiscoverKeyProperties(
Expand All @@ -86,7 +86,7 @@ public static bool IsHandledByConventions(this IKey key)
/// <param name="index">The index.</param>
/// <param name="annotationCodeGenerator">The provider's annotation code generator.</param>
/// <returns><see langword="true" /> if this index can be reperesented by a data annotation.</returns>
public static bool HasDataAnnotation(this IIndex index, IAnnotationCodeGenerator annotationCodeGenerator)
public static bool IsHandledByDataAnnotations(this IIndex index, IAnnotationCodeGenerator annotationCodeGenerator)
{
var indexAnnotations = annotationCodeGenerator.FilterIgnoredAnnotations(index.GetAnnotations())
.ToDictionary(a => a.Name, a => a);
Expand Down Expand Up @@ -138,7 +138,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
foreach (var index in entityType.GetIndexes()
.Where(
i => ((IConventionIndex)i).GetConfigurationSource() != ConfigurationSource.Convention
&& i.HasDataAnnotation(annotationCodeGenerator)))
&& i.IsHandledByDataAnnotations(annotationCodeGenerator)))
{
var indexArgs = new List<object?>();
var indexNamedArgs = new Dictionary<string, object?>();
Expand Down Expand Up @@ -385,7 +385,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(

if (entityType.FindPrimaryKey() is null)
{
var hasNoKey = new FluentApiCodeFragment(nameof(EntityTypeBuilder.HasNoKey)) { HasDataAnnotation = true };
var hasNoKey = new FluentApiCodeFragment(nameof(EntityTypeBuilder.HasNoKey)) { IsHandledByDataAnnotations = true };

root = root?.Chain(hasNoKey) ?? hasNoKey;
}
Expand Down Expand Up @@ -444,7 +444,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(

var toTable = new FluentApiCodeFragment(nameof(RelationalEntityTypeBuilderExtensions.ToTable))
{
Arguments = toTableArguments, HasDataAnnotation = toTableHandledByDataAnnotations
Arguments = toTableArguments, IsHandledByDataAnnotations = toTableHandledByDataAnnotations
};

root = root?.Chain(toTable) ?? toTable;
Expand Down Expand Up @@ -474,7 +474,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
}

annotationsRoot = GenerateAnnotations(
entityType, annotationsHandledByDataAnnotations, annotationCodeGenerator, hasDataAnnotation: true);
entityType, annotationsHandledByDataAnnotations, annotationCodeGenerator, isHandledByDataAnnotations: true);
if (annotationsRoot is not null)
{
root = root?.Chain(annotationsRoot) ?? annotationsRoot;
Expand Down Expand Up @@ -581,7 +581,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
&& property.ClrType.IsNullableType()
&& !property.IsPrimaryKey())
{
var isRequired = new FluentApiCodeFragment(nameof(PropertyBuilder.IsRequired)) { HasDataAnnotation = true };
var isRequired = new FluentApiCodeFragment(nameof(PropertyBuilder.IsRequired)) { IsHandledByDataAnnotations = true };

root = root?.Chain(isRequired) ?? isRequired;
}
Expand All @@ -591,7 +591,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
{
var hasMaxLength = new FluentApiCodeFragment(nameof(PropertyBuilder.HasMaxLength))
{
Arguments = { maxLength.Value }, HasDataAnnotation = true
Arguments = { maxLength.Value }, IsHandledByDataAnnotations = true
};

root = root?.Chain(hasMaxLength) ?? hasMaxLength;
Expand All @@ -603,7 +603,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
{
var hasPrecision = new FluentApiCodeFragment(nameof(PropertyBuilder.HasPrecision))
{
Arguments = { precision.Value, scale.Value }, HasDataAnnotation = true
Arguments = { precision.Value, scale.Value }, IsHandledByDataAnnotations = true
};

root = root?.Chain(hasPrecision) ?? hasPrecision;
Expand All @@ -612,15 +612,15 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
{
var hasPrecision = new FluentApiCodeFragment(nameof(PropertyBuilder.HasPrecision))
{
Arguments = { precision.Value }, HasDataAnnotation = true
Arguments = { precision.Value }, IsHandledByDataAnnotations = true
};

root = root?.Chain(hasPrecision) ?? hasPrecision;
}

if (property.IsUnicode() != null)
{
var isUnicode = new FluentApiCodeFragment(nameof(PropertyBuilder.IsUnicode)) { HasDataAnnotation = true };
var isUnicode = new FluentApiCodeFragment(nameof(PropertyBuilder.IsUnicode)) { IsHandledByDataAnnotations = true };

if (property.IsUnicode() == false)
{
Expand Down Expand Up @@ -665,7 +665,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
}

annotationsRoot = GenerateAnnotations(
property, annotationsHandledByDataAnnotations, annotationCodeGenerator, hasDataAnnotation: true);
property, annotationsHandledByDataAnnotations, annotationCodeGenerator, isHandledByDataAnnotations: true);
if (annotationsRoot is not null)
{
root = root?.Chain(annotationsRoot) ?? annotationsRoot;
Expand Down Expand Up @@ -715,7 +715,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
root = root?.Chain(hasPrincipalKey) ?? hasPrincipalKey;
}

var hasForeignKey = new FluentApiCodeFragment(nameof(ReferenceReferenceBuilder.HasForeignKey)) { HasDataAnnotation = true };
var hasForeignKey = new FluentApiCodeFragment(nameof(ReferenceReferenceBuilder.HasForeignKey)) { IsHandledByDataAnnotations = true };

if (foreignKey.IsUnique)
{
Expand Down Expand Up @@ -808,14 +808,14 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
IAnnotatable annotatable,
Dictionary<string, IAnnotation> annotations,
IAnnotationCodeGenerator annotationCodeGenerator,
bool hasDataAnnotation = false)
bool isHandledByDataAnnotations = false)
{
FluentApiCodeFragment? root = null;

foreach (var methodCall in annotationCodeGenerator.GenerateFluentApiCalls(annotatable, annotations))
{
var fluentApiCall = FluentApiCodeFragment.From(methodCall);
fluentApiCall.HasDataAnnotation = hasDataAnnotation;
fluentApiCall.IsHandledByDataAnnotations = isHandledByDataAnnotations;

root = root?.Chain(fluentApiCall) ?? fluentApiCall;
}
Expand All @@ -824,7 +824,7 @@ public static IEnumerable<AttributeCodeFragment> GetDataAnnotations(
{
var hasAnnotation = new FluentApiCodeFragment(nameof(ModelBuilder.HasAnnotation))
{
Arguments = { annotation.Name, annotation.Value }, HasDataAnnotation = hasDataAnnotation
Arguments = { annotation.Name, annotation.Value }, IsHandledByDataAnnotations = isHandledByDataAnnotations
};

root = root?.Chain(hasAnnotation) ?? hasAnnotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public virtual string TransformText()
{
var keyFluentApiCalls = key.GetFluentApiCalls(annotationCodeGenerator);
if (keyFluentApiCalls != null
|| (!key.IsHandledByConventions() && !Options.UseDataAnnotations))
|| (!key.IsHandledByConvention() && !Options.UseDataAnnotations))
{
if (keyFluentApiCalls != null)
{
Expand All @@ -167,7 +167,7 @@ public virtual string TransformText()
}

var entityTypeFluentApiCalls = entityType.GetFluentApiCalls(annotationCodeGenerator)
?.FilterChain(c => !(Options.UseDataAnnotations && c.HasDataAnnotation));
?.FilterChain(c => !(Options.UseDataAnnotations && c.IsHandledByDataAnnotations));
if (entityTypeFluentApiCalls != null)
{
usings.AddRange(entityTypeFluentApiCalls.GetRequiredUsings());
Expand All @@ -185,7 +185,7 @@ public virtual string TransformText()
}

foreach (var index in entityType.GetIndexes()
.Where(i => !(Options.UseDataAnnotations && i.HasDataAnnotation(annotationCodeGenerator))))
.Where(i => !(Options.UseDataAnnotations && i.IsHandledByDataAnnotations(annotationCodeGenerator))))
{
if (anyEntityTypeConfiguration)
{
Expand Down Expand Up @@ -213,7 +213,7 @@ public virtual string TransformText()
foreach (var property in entityType.GetProperties())
{
var propertyFluentApiCalls = property.GetFluentApiCalls(annotationCodeGenerator)
?.FilterChain(c => !(Options.UseDataAnnotations && c.HasDataAnnotation)
?.FilterChain(c => !(Options.UseDataAnnotations && c.IsHandledByDataAnnotations)
&& !(c.Method == "IsRequired" && Options.UseNullableReferenceTypes && !property.ClrType.IsValueType));
if (propertyFluentApiCalls == null)
{
Expand All @@ -240,7 +240,7 @@ public virtual string TransformText()
foreach (var foreignKey in entityType.GetForeignKeys())
{
var foreignKeyFluentApiCalls = foreignKey.GetFluentApiCalls(annotationCodeGenerator)
?.FilterChain(c => !(Options.UseDataAnnotations && c.HasDataAnnotation));
?.FilterChain(c => !(Options.UseDataAnnotations && c.IsHandledByDataAnnotations));
if (foreignKeyFluentApiCalls == null)
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public partial class <#= Options.ContextName #> : DbContext
{
var keyFluentApiCalls = key.GetFluentApiCalls(annotationCodeGenerator);
if (keyFluentApiCalls != null
|| (!key.IsHandledByConventions() && !Options.UseDataAnnotations))
|| (!key.IsHandledByConvention() && !Options.UseDataAnnotations))
{
if (keyFluentApiCalls != null)
{
Expand All @@ -136,7 +136,7 @@ public partial class <#= Options.ContextName #> : DbContext
}

var entityTypeFluentApiCalls = entityType.GetFluentApiCalls(annotationCodeGenerator)
?.FilterChain(c => !(Options.UseDataAnnotations && c.HasDataAnnotation));
?.FilterChain(c => !(Options.UseDataAnnotations && c.IsHandledByDataAnnotations));
if (entityTypeFluentApiCalls != null)
{
usings.AddRange(entityTypeFluentApiCalls.GetRequiredUsings());
Expand All @@ -152,7 +152,7 @@ public partial class <#= Options.ContextName #> : DbContext
}

foreach (var index in entityType.GetIndexes()
.Where(i => !(Options.UseDataAnnotations && i.HasDataAnnotation(annotationCodeGenerator))))
.Where(i => !(Options.UseDataAnnotations && i.IsHandledByDataAnnotations(annotationCodeGenerator))))
{
if (anyEntityTypeConfiguration)
{
Expand All @@ -174,7 +174,7 @@ public partial class <#= Options.ContextName #> : DbContext
foreach (var property in entityType.GetProperties())
{
var propertyFluentApiCalls = property.GetFluentApiCalls(annotationCodeGenerator)
?.FilterChain(c => !(Options.UseDataAnnotations && c.HasDataAnnotation)
?.FilterChain(c => !(Options.UseDataAnnotations && c.IsHandledByDataAnnotations)
&& !(c.Method == "IsRequired" && Options.UseNullableReferenceTypes && !property.ClrType.IsValueType));
if (propertyFluentApiCalls == null)
{
Expand All @@ -197,7 +197,7 @@ public partial class <#= Options.ContextName #> : DbContext
foreach (var foreignKey in entityType.GetForeignKeys())
{
var foreignKeyFluentApiCalls = foreignKey.GetFluentApiCalls(annotationCodeGenerator)
?.FilterChain(c => !(Options.UseDataAnnotations && c.HasDataAnnotation));
?.FilterChain(c => !(Options.UseDataAnnotations && c.IsHandledByDataAnnotations));
if (foreignKeyFluentApiCalls == null)
{
continue;
Expand Down

0 comments on commit 9259481

Please sign in to comment.