Skip to content

Commit

Permalink
Improved error handling of missing _index
Browse files Browse the repository at this point in the history
since some BP control may do it wrong, so we at least have a clue what's
going on when the bug triggered
  • Loading branch information
exyi committed Aug 17, 2019
1 parent 0a54ed0 commit 6d9543b
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ public CurrentCollectionIndexExtensionParameter() : base("_index", new ResolvedT

}

internal static int GetIndex(DotvvmBindableObject c) =>
(c.GetAllAncestors(true, false)
.OfType<DataItemContainer>()
.FirstOrDefault() ?? throw new DotvvmControlException(c, "Could not find ancestor DataItemContainer that stores the current collection index."))
.DataItemIndex ?? throw new DotvvmControlException(c, "Nearest DataItemContainer does have the collection index specified.");

public override Expression GetServerEquivalent(Expression controlParameter)
{
return ExpressionUtils.Replace((DotvvmBindableObject c) => c.GetAllAncestors(true, false).OfType<DataItemContainer>().First().DataItemIndex.Value, controlParameter);
return ExpressionUtils.Replace((DotvvmBindableObject c) => GetIndex(c), controlParameter);
}

public override JsExpression GetJsTranslation(JsExpression dataContext)
Expand Down Expand Up @@ -115,7 +121,7 @@ public BindingCollectionInfoExtensionParameter(string identifier) : base(identif
}

public override Expression GetServerEquivalent(Expression controlParameter) =>
ExpressionUtils.Replace((DotvvmBindableObject c) => new BindingCollectionInfo(c.GetAllAncestors(true, false).OfType<DataItemContainer>().First().DataItemIndex.Value), controlParameter);
ExpressionUtils.Replace((DotvvmBindableObject c) => new BindingCollectionInfo(CurrentCollectionIndexExtensionParameter.GetIndex(c)), controlParameter);

public override JsExpression GetJsTranslation(JsExpression dataContext)
{
Expand Down

0 comments on commit 6d9543b

Please sign in to comment.