Skip to content

Commit

Permalink
Refactor ConventionScope
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Dec 12, 2019
1 parent bdff0a1 commit 059adbb
Show file tree
Hide file tree
Showing 8 changed files with 875 additions and 851 deletions.
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ protected virtual InternalRelationshipBuilder Builder
[EntityFrameworkInternal]
protected virtual T UpdateBuilder<T>([NotNull] Func<T> configure)
{
var foreignKey = _builder.Metadata;
IConventionForeignKey foreignKey = _builder.Metadata;
var result = DependentEntityType.Model.ConventionDispatcher.Run(configure, ref foreignKey);
if (foreignKey != null)
{
_builder = foreignKey.Builder;
_builder = ((ForeignKey)foreignKey).Builder;
}

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal
{
public partial class ConventionDispatcher
{
private abstract class ConventionNode
{
public abstract ConventionNode Accept(ConventionVisitor visitor);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal
{
public partial class ConventionDispatcher
{
private abstract class ConventionScope : ConventionNode
{
public virtual ConventionScope Parent => null;
public virtual IReadOnlyList<ConventionNode> Children => null;

public int GetLeafCount()
{
if (Children == null)
{
return 0;
}

var scopesToVisit = new Queue<ConventionScope>();
scopesToVisit.Enqueue(this);
var leafCount = 0;
while (scopesToVisit.Count > 0)
{
var scope = scopesToVisit.Dequeue();
if (scope.Children == null)
{
continue;
}

foreach (var conventionNode in scope.Children)
{
if (conventionNode is ConventionScope nextScope)
{
scopesToVisit.Enqueue(nextScope);
}
else
{
leafCount++;
}
}
}

return leafCount;
}

public abstract IConventionEntityTypeBuilder OnEntityTypeAdded([NotNull] IConventionEntityTypeBuilder entityTypeBuilder);
public abstract IConventionAnnotation OnEntityTypeAnnotationChanged([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name, [CanBeNull] IConventionAnnotation annotation, [CanBeNull] IConventionAnnotation oldAnnotation);
public abstract IConventionEntityType OnEntityTypeBaseTypeChanged([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] IConventionEntityType newBaseType, [CanBeNull] IConventionEntityType previousBaseType);
public abstract string OnEntityTypeIgnored([NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, [CanBeNull] Type type);
public abstract string OnEntityTypeMemberIgnored([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name);
public abstract IConventionKey OnEntityTypePrimaryKeyChanged([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] IConventionKey newPrimaryKey, [CanBeNull] IConventionKey previousPrimaryKey);
public abstract IConventionEntityType OnEntityTypeRemoved([NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionEntityType entityType);
public abstract IConventionRelationshipBuilder OnForeignKeyAdded([NotNull] IConventionRelationshipBuilder relationshipBuilder);
public abstract IConventionAnnotation OnForeignKeyAnnotationChanged(IConventionRelationshipBuilder relationshipBuilder, string name, IConventionAnnotation annotation, IConventionAnnotation oldAnnotation);
public abstract IConventionRelationshipBuilder OnForeignKeyOwnershipChanged([NotNull] IConventionRelationshipBuilder relationshipBuilder);
public abstract IConventionRelationshipBuilder OnForeignKeyPrincipalEndChanged([NotNull] IConventionRelationshipBuilder relationshipBuilder);
public abstract IConventionRelationshipBuilder OnForeignKeyPropertiesChanged([NotNull] IConventionRelationshipBuilder relationshipBuilder, [NotNull] IReadOnlyList<IConventionProperty> oldDependentProperties, [NotNull] IConventionKey oldPrincipalKey);
public abstract IConventionForeignKey OnForeignKeyRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionForeignKey foreignKey);
public abstract IConventionRelationshipBuilder OnForeignKeyRequirednessChanged([NotNull] IConventionRelationshipBuilder relationshipBuilder);
public abstract IConventionRelationshipBuilder OnForeignKeyUniquenessChanged([NotNull] IConventionRelationshipBuilder relationshipBuilder);
public abstract IConventionIndexBuilder OnIndexAdded([NotNull] IConventionIndexBuilder indexBuilder);
public abstract IConventionAnnotation OnIndexAnnotationChanged([NotNull] IConventionIndexBuilder indexBuilder, [NotNull] string name, [CanBeNull] IConventionAnnotation annotation, [CanBeNull] IConventionAnnotation oldAnnotation);
public abstract IConventionIndex OnIndexRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionIndex index);
public abstract IConventionIndexBuilder OnIndexUniquenessChanged([NotNull] IConventionIndexBuilder indexBuilder);
public abstract IConventionKeyBuilder OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder);
public abstract IConventionAnnotation OnKeyAnnotationChanged(IConventionKeyBuilder keyBuilder, string name, IConventionAnnotation annotation, IConventionAnnotation oldAnnotation);
public abstract IConventionKey OnKeyRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionKey key);
public abstract IConventionAnnotation OnModelAnnotationChanged([NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, [CanBeNull] IConventionAnnotation annotation, [CanBeNull] IConventionAnnotation oldAnnotation);
public abstract IConventionNavigation OnNavigationAdded([NotNull] IConventionRelationshipBuilder relationshipBuilder, [NotNull] IConventionNavigation navigation);
public abstract string OnNavigationRemoved([NotNull] IConventionEntityTypeBuilder sourceEntityTypeBuilder, [NotNull] IConventionEntityTypeBuilder targetEntityTypeBuilder, [NotNull] string navigationName, [CanBeNull] MemberInfo memberInfo);
public abstract IConventionPropertyBuilder OnPropertyAdded([NotNull] IConventionPropertyBuilder propertyBuilder);
public abstract IConventionAnnotation OnPropertyAnnotationChanged([NotNull] IConventionPropertyBuilder propertyBuilder, [NotNull] string name, [CanBeNull] IConventionAnnotation annotation, [CanBeNull] IConventionAnnotation oldAnnotation);
public abstract FieldInfo OnPropertyFieldChanged([NotNull] IConventionPropertyBuilder propertyBuilder, FieldInfo newFieldInfo, [CanBeNull] FieldInfo oldFieldInfo);
public abstract IConventionPropertyBuilder OnPropertyNullableChanged([NotNull] IConventionPropertyBuilder propertyBuilder);
}
}
}
Loading

0 comments on commit 059adbb

Please sign in to comment.