Skip to content

Commit

Permalink
Fixes false positive in the ValidateParentsLifecycleEvents check
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Dec 27, 2017
1 parent 3f6534c commit 469b001
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/DotVVM.Framework/Controls/DotvvmBindableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,18 @@ public IEnumerable<KeyValuePair<DotvvmProperty, IBinding>> GetAllBindings()
/// <summary>
/// Gets all ancestors of this control starting with the parent.
/// </summary>
public IEnumerable<DotvvmBindableObject> GetAllAncestors(bool incudingThis = false)
/// <param name="onlyWhenInChildren">only enumerate until the parent has this control in <see cref="DotvvmControl.Children" />. Note that it may have a non-trivial performance penalty</param>
public IEnumerable<DotvvmBindableObject> GetAllAncestors(bool incudingThis = false, bool onlyWhenInChildren = false)
{
var ancestor = incudingThis ? this : Parent;
while (ancestor != null)
{
yield return ancestor;
if (onlyWhenInChildren)
{
if (!(ancestor.Parent is DotvvmControl parentControl && parentControl.Children.Contains(ancestor)))
yield break;
}
ancestor = ancestor.Parent;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DotVVM.Framework/Controls/DotvvmControlCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void SetParent(DotvvmControl item)
internal void ValidateParentsLifecycleEvents()
{
// check if all ancestors have the flags
if (!this.parent.GetAllAncestors().OfType<DotvvmControl>().All(c => (c.LifecycleRequirements & this.parent.LifecycleRequirements) == this.parent.LifecycleRequirements))
if (!this.parent.GetAllAncestors(onlyWhenInChildren: true).OfType<DotvvmControl>().All(c => (c.LifecycleRequirements & this.parent.LifecycleRequirements) == this.parent.LifecycleRequirements))
throw new Exception("Internal bug in Lifecycle events.");
}

Expand Down

0 comments on commit 469b001

Please sign in to comment.