Skip to content

Commit

Permalink
Introduce DataContextStart.CreateCollectionElement
Browse files Browse the repository at this point in the history
Creates a nested data context with _index and _collection extension parameters
  • Loading branch information
exyi committed Oct 22, 2023
1 parent face71b commit 8f9343a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,9 @@ public ThisBindingProperty GetThisBinding(IBinding binding, DataContextStack sta

public CollectionElementDataContextBindingProperty GetCollectionElementDataContext(DataContextStack dataContext, ResultTypeBindingProperty resultType)
{
return new CollectionElementDataContextBindingProperty(DataContextStack.Create(
return new CollectionElementDataContextBindingProperty(DataContextStack.CreateCollectionElement(
ReflectionUtils.GetEnumerableType(resultType.Type).NotNull(),
parent: dataContext,
extensionParameters: new CollectionElementDataContextChangeAttribute(0).GetExtensionParameters(new ResolvedTypeDescriptor(dataContext.DataContextType)).ToArray()
dataContext
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Compilation.ControlTree.Resolved;
using DotVVM.Framework.Utils;
using FastExpressionCompiler;
Expand Down Expand Up @@ -172,5 +173,23 @@ public static DataContextStack Create(Type type,
var dcs = new DataContextStack(type, parent, imports, extensionParameters, bindingPropertyResolvers);
return dcs;// internCache.GetValue(dcs, _ => dcs);
}


/// <summary> Creates a new data context level with _index and _collection extension parameters. </summary>
public static DataContextStack CreateCollectionElement(Type elementType,
DataContextStack? parent = null,
IReadOnlyList<NamespaceImport>? imports = null,
IReadOnlyList<BindingExtensionParameter>? extensionParameters = null,
IReadOnlyList<Delegate>? bindingPropertyResolvers = null)
{
var indexParameters = new CollectionElementDataContextChangeAttribute(0).GetExtensionParameters(new ResolvedTypeDescriptor(elementType.MakeArrayType()));
extensionParameters = extensionParameters is null ? indexParameters.ToArray() : extensionParameters.Concat(indexParameters).ToArray();
return DataContextStack.Create(
elementType, parent,
imports: imports,
extensionParameters: extensionParameters,
bindingPropertyResolvers: bindingPropertyResolvers
);
}
}
}

0 comments on commit 8f9343a

Please sign in to comment.