Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ ImmutableList<IAbstractPropertyDeclarationDirective> propertyDirectives
baseType.FullName + "||" + string.Join("|", imports) + "||" + string.Join("|", properties)
)
);
var hash = Convert.ToBase64String(hashBytes, 0, 16);

var hash = Convert.ToBase64String(hashBytes, 0, 16)
.Replace('+', '_')
.Replace('/', '_')
.TrimEnd('=');
var typeName = "DotvvmMarkupControl-" + hash;

return GetOrCreateDynamicType(baseType, typeName, propertyDirectives);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace DotVVM.Framework.Compilation.Directives
public class ResolvedPropertyDeclarationDirectiveCompiler : PropertyDeclarationDirectiveCompiler
{
private static readonly Lazy<ModuleBuilder> DynamicMarkupControlAssembly = new(CreateDynamicMarkupControlAssembly);
private static readonly object locker = new();

public ResolvedPropertyDeclarationDirectiveCompiler(
ImmutableDictionary<string, ImmutableList<DothtmlDirectiveNode>> directiveNodesByName,
Expand Down Expand Up @@ -45,18 +46,29 @@ protected override IPropertyDescriptor TryCreateDotvvmPropertyFromDirective(IAbs
string typeName,
ImmutableList<IAbstractPropertyDeclarationDirective> propertyDirectives)
{
if (DynamicMarkupControlAssembly.Value.GetType(typeName) is { } type)
// this must be done in the lock, otherwise the DynamicMarkupControlAssembly can return TypeBuilder instead of fully-built System.Type
lock (locker)
{
return new ResolvedTypeDescriptor(type);
}
if (DynamicMarkupControlAssembly.Value.GetType(typeName) is { } type)
{
return new ResolvedTypeDescriptor(type);
}

var declaringTypeBuilder =
DynamicMarkupControlAssembly.Value.DefineType(typeName, TypeAttributes.Public, ResolvedTypeDescriptor.ToSystemType(baseType));
var createdTypeInfo = declaringTypeBuilder.CreateTypeInfo()?.AsType();
try
{
var declaringTypeBuilder =
DynamicMarkupControlAssembly.Value.DefineType(typeName, TypeAttributes.Public, ResolvedTypeDescriptor.ToSystemType(baseType));
var createdTypeInfo = declaringTypeBuilder.CreateTypeInfo()?.AsType();

return createdTypeInfo is not null
? new ResolvedTypeDescriptor(createdTypeInfo)
: null;
return createdTypeInfo is not null
? new ResolvedTypeDescriptor(createdTypeInfo)
: null;
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to create dynamic type '{typeName}'", ex);
}
}
}

private static ModuleBuilder CreateDynamicMarkupControlAssembly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- Resource c7-item of type TemplateResource. -->
<template id=c7-item><!-- ko with: $item -->
<!-- ko with: $rawData --><div>
<input type=button onclick='dotvvm.postBack(this,["HItems/[$indexPath]","$parent"],"RR93KduwUKJIXxFp","c7"+&#39;_&#39;+(ko.contextFor(this).$parentContext.$indexPath.map(ko.unwrap).join("_")+"L")+&#39;_&#39;+"c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' data-bind="value: Label" /></div><!-- /ko -->
<input type=button onclick='dotvvm.postBack(this,["HItems/[$indexPath]","$parent"],"bu4IebQeKpjPj6ST","c7"+&#39;_&#39;+(ko.contextFor(this).$parentContext.$indexPath.map(ko.unwrap).join("_")+"L")+&#39;_&#39;+"c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' data-bind="value: Label" /></div><!-- /ko -->
<!-- /ko --><!-- ko template: { foreach: $item().Children, name: "c7-item", hierarchyRole: "Child" } --><!-- ko if: Children()?.length --><!-- /ko --><!-- /ko --></template>

</body>
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

<div><!-- ko dotvvm-SSR-foreach: { data: HItems } --><!-- ko dotvvm-SSR-item: 0 -->
<!-- ko with: $rawData --><div>
<input type=button value=A onclick='dotvvm.postBack(this,["HItems/[0]","$parent"],"RR93KduwUKJIXxFp","c7_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<input type=button value=A onclick='dotvvm.postBack(this,["HItems/[0]","$parent"],"bu4IebQeKpjPj6ST","c7_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- ko dotvvm-SSR-foreach: { data: ko.unwrap($foreachCollectionSymbol)[0]().Children } --><!-- ko dotvvm-SSR-item: 0 -->
<!-- ko with: $rawData --><div>
<input type=button value=A_1 onclick='dotvvm.postBack(this,["HItems/[0]/[0]","$parent"],"RR93KduwUKJIXxFp","c7_0_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<input type=button value=A_1 onclick='dotvvm.postBack(this,["HItems/[0]/[0]","$parent"],"bu4IebQeKpjPj6ST","c7_0_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- ko dotvvm-SSR-foreach: { data: ko.unwrap($foreachCollectionSymbol)[0]().Children } --><!-- ko dotvvm-SSR-item: 0 -->
<!-- ko with: $rawData --><div>
<input type=button value=A_1_1 onclick='dotvvm.postBack(this,["HItems/[0]/[0]/[0]","$parent"],"RR93KduwUKJIXxFp","c7_0_0_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<input type=button value=A_1_1 onclick='dotvvm.postBack(this,["HItems/[0]/[0]/[0]","$parent"],"bu4IebQeKpjPj6ST","c7_0_0_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- ko dotvvm-SSR-item: 1 -->
<!-- ko with: $rawData --><div>
<input type=button value=A_1_2 onclick='dotvvm.postBack(this,["HItems/[0]/[0]/[1]","$parent"],"RR93KduwUKJIXxFp","c7_0_0_1L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<input type=button value=A_1_2 onclick='dotvvm.postBack(this,["HItems/[0]/[0]/[1]","$parent"],"bu4IebQeKpjPj6ST","c7_0_0_1L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- /ko --><!-- /ko --><!-- ko dotvvm-SSR-item: 1 -->
<!-- ko with: $rawData --><div>
<input type=button value=B onclick='dotvvm.postBack(this,["HItems/[1]","$parent"],"RR93KduwUKJIXxFp","c7_1L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<input type=button value=B onclick='dotvvm.postBack(this,["HItems/[1]","$parent"],"bu4IebQeKpjPj6ST","c7_1L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- /ko --></div>


Expand Down
Loading