Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup for Relational #22183

Merged
merged 1 commit into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions src/EFCore.Relational/Design/AnnotationCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public virtual void RemoveAnnotationsHandledByConventions(IModel model, IDiction

/// <inheritdoc />
public virtual void RemoveAnnotationsHandledByConventions(
IEntityType entityType, IDictionary<string, IAnnotation> annotations)
IEntityType entityType,
IDictionary<string, IAnnotation> annotations)
{
annotations.Remove(RelationalAnnotationNames.IsTableExcludedFromMigrations);

Expand All @@ -88,7 +89,8 @@ public virtual void RemoveAnnotationsHandledByConventions(

/// <inheritdoc />
public virtual void RemoveAnnotationsHandledByConventions(
IProperty property, IDictionary<string, IAnnotation> annotations)
IProperty property,
IDictionary<string, IAnnotation> annotations)
{
var columnName = property.GetColumnName();
if (columnName == property.Name)
Expand All @@ -105,7 +107,8 @@ public virtual void RemoveAnnotationsHandledByConventions(IKey key, IDictionary<

/// <inheritdoc />
public virtual void RemoveAnnotationsHandledByConventions(
IForeignKey foreignKey, IDictionary<string, IAnnotation> annotations)
IForeignKey foreignKey,
IDictionary<string, IAnnotation> annotations)
=> RemoveConventionalAnnotationsHelper(foreignKey, annotations, IsHandledByConvention);

/// <inheritdoc />
Expand All @@ -114,7 +117,8 @@ public virtual void RemoveAnnotationsHandledByConventions(IIndex index, IDiction

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IModel model, IDictionary<string, IAnnotation> annotations)
IModel model,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -129,7 +133,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IEntityType entityType, IDictionary<string, IAnnotation> annotations)
IEntityType entityType,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -144,7 +149,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IProperty property, IDictionary<string, IAnnotation> annotations)
IProperty property,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -167,16 +173,16 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
{
methodCallCodeFragments.Add(
computedColumnSql?.Length == 0
? new MethodCallCodeFragment(
nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql))
: TryGetAndRemove(annotations, RelationalAnnotationNames.IsStored, out bool isStored)
? new MethodCallCodeFragment(
nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql),
computedColumnSql,
isStored)
: new MethodCallCodeFragment(
nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql),
computedColumnSql));
nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql))
: TryGetAndRemove(annotations, RelationalAnnotationNames.IsStored, out bool isStored)
? new MethodCallCodeFragment(
nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql),
computedColumnSql,
isStored)
: new MethodCallCodeFragment(
nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql),
computedColumnSql));
}

GenerateSimpleFluentApiCall(
Expand All @@ -199,7 +205,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IKey key, IDictionary<string, IAnnotation> annotations)
IKey key,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -214,7 +221,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IForeignKey navigation, IDictionary<string, IAnnotation> annotations)
IForeignKey navigation,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -229,7 +237,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
INavigation navigation, IDictionary<string, IAnnotation> annotations)
INavigation navigation,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -240,7 +249,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
ISkipNavigation navigation, IDictionary<string, IAnnotation> annotations)
ISkipNavigation navigation,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -251,7 +261,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IIndex index, IDictionary<string, IAnnotation> annotations)
IIndex index,
IDictionary<string, IAnnotation> annotations)
{
var methodCallCodeFragments = new List<MethodCallCodeFragment>();

Expand All @@ -270,7 +281,8 @@ public virtual IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(

/// <inheritdoc />
public virtual IReadOnlyList<AttributeCodeFragment> GenerateDataAnnotationAttributes(
IEntityType entityType, IDictionary<string, IAnnotation> annotations)
IEntityType entityType,
IDictionary<string, IAnnotation> annotations)
{
var attributeCodeFragments = new List<AttributeCodeFragment>();

Expand All @@ -281,7 +293,8 @@ public virtual IReadOnlyList<AttributeCodeFragment> GenerateDataAnnotationAttrib

/// <inheritdoc />
public virtual IReadOnlyList<AttributeCodeFragment> GenerateDataAnnotationAttributes(
IProperty property, IDictionary<string, IAnnotation> annotations)
IProperty property,
IDictionary<string, IAnnotation> annotations)
{
var attributeCodeFragments = new List<AttributeCodeFragment>();

Expand Down Expand Up @@ -312,8 +325,8 @@ public virtual IReadOnlyList<AttributeCodeFragment> GenerateDataAnnotationAttrib
/// <param name="model"> The <see cref="IModel" />. </param>
/// <param name="annotation"> The <see cref="IAnnotation" />. </param>
/// <returns>
/// <see langword="true"/> if the annotation is handled by convention;
/// <see langword="false"/> if code must be generated.
/// <see langword="true" /> if the annotation is handled by convention;
/// <see langword="false" /> if code must be generated.
/// </returns>
protected virtual bool IsHandledByConvention([NotNull] IModel model, [NotNull] IAnnotation annotation)
{
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Relational/Design/AttributeCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public AttributeCodeFragment([NotNull] Type type, [NotNull] params object[] argu
/// Gets the method call's arguments.
/// </summary>
/// <value> The method call's arguments. </value>
public virtual IReadOnlyList<object> Arguments => _arguments;
public virtual IReadOnlyList<object> Arguments
=> _arguments;
}
}
34 changes: 23 additions & 11 deletions src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ void RemoveAnnotationsHandledByConventions([NotNull] IKey key, [NotNull] IDictio
/// </summary>
/// <param name="foreignKey"> The foreign key to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to remove the conventional ones. </param>
void RemoveAnnotationsHandledByConventions([NotNull] IForeignKey foreignKey, [NotNull] IDictionary<string, IAnnotation> annotations) { }
void RemoveAnnotationsHandledByConventions([NotNull] IForeignKey foreignKey, [NotNull] IDictionary<string, IAnnotation> annotations)
{
}

/// <summary>
/// Removes annotation whose configuration is already applied by convention, and do not need to be
Expand All @@ -78,7 +80,8 @@ void RemoveAnnotationsHandledByConventions([NotNull] IIndex index, [NotNull] IDi
/// <param name="model"> The model to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] IModel model, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IModel model,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -88,7 +91,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="entityType"> The entity type to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] IEntityType entityType, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IEntityType entityType,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -98,7 +102,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="property"> The property to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] IProperty property, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IProperty property,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -108,7 +113,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="key"> The key to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] IKey key, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IKey key,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -118,7 +124,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="foreignKey"> The foreign key to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] IForeignKey foreignKey, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IForeignKey foreignKey,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -128,7 +135,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="navigation"> The navigation to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] INavigation navigation, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] INavigation navigation,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -138,7 +146,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="navigation"> The skip navigation to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] ISkipNavigation navigation, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] ISkipNavigation navigation,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -148,7 +157,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="index"> The index to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
[NotNull] IIndex index, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IIndex index,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<MethodCallCodeFragment>();

/// <summary>
Expand All @@ -158,7 +168,8 @@ IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
/// <param name="entityType"> The entity type to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<AttributeCodeFragment> GenerateDataAnnotationAttributes(
[NotNull] IEntityType entityType, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IEntityType entityType,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<AttributeCodeFragment>();

/// <summary>
Expand All @@ -168,7 +179,8 @@ IReadOnlyList<AttributeCodeFragment> GenerateDataAnnotationAttributes(
/// <param name="property"> The property to which the annotations are applied. </param>
/// <param name="annotations"> The set of annotations from which to generate fluent API calls. </param>
IReadOnlyList<AttributeCodeFragment> GenerateDataAnnotationAttributes(
[NotNull] IProperty property, [NotNull] IDictionary<string, IAnnotation> annotations)
[NotNull] IProperty property,
[NotNull] IDictionary<string, IAnnotation> annotations)
=> Array.Empty<AttributeCodeFragment>();
}
}
3 changes: 2 additions & 1 deletion src/EFCore.Relational/Design/MethodCallCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public MethodCallCodeFragment(
/// Gets the method call's arguments.
/// </summary>
/// <value> The method call's arguments. </value>
public virtual IReadOnlyList<object> Arguments => _arguments;
public virtual IReadOnlyList<object> Arguments
=> _arguments;

/// <summary>
/// Gets the next method call to chain after this.
Expand Down
Loading