public string CompileBinding(string expression, Type[] contexts, Type expectedType) { var context = new DataContextStack(contexts.FirstOrDefault() ?? typeof(object), rootControlType: typeof(DotvvmControl)); for (int i = 1; i < contexts.Length; i++) { context = new DataContextStack(contexts[i], context); } var parser = new BindingExpressionBuilder(); var expressionTree = TypeConversion.ImplicitConversion(parser.Parse(expression, context, BindingParserOptions.Create <ValueBindingExpression>()), expectedType, true, true); return(JavascriptTranslator.CompileToJavascript(expressionTree, context)); }
public object ExecuteBinding(string expression, object[] contexts, DotvvmControl control, NamespaceImport[] imports = null, Type expectedType = null) { var context = new DataContextStack(contexts.FirstOrDefault()?.GetType() ?? typeof(object), rootControlType: control?.GetType() ?? typeof(DotvvmControl)); for (int i = 1; i < contexts.Length; i++) { context = new DataContextStack(contexts[i].GetType(), context); } var parser = new BindingExpressionBuilder(); var expressionTree = parser.Parse(expression, context, BindingParserOptions.Create <ValueBindingExpression>(importNs: new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding") }.Concat(imports ?? Enumerable.Empty <NamespaceImport>()).ToArray())); Array.Reverse(contexts); return(new BindingCompilationAttribute().CompileToDelegate(expressionTree, context, expectedType ?? typeof(object)).Compile()(contexts, control)); }
public string CompileBinding(string expression, Type[] contexts, Type expectedType) { var context = DataContextStack.Create(contexts.FirstOrDefault() ?? typeof(object), extensionParameters: new BindingExtensionParameter[] { new BindingPageInfoExtensionParameter(), }.Concat(configuration.Markup.DefaultExtensionParameters).ToArray()); for (int i = 1; i < contexts.Length; i++) { context = DataContextStack.Create(contexts[i], context); } var parser = new BindingExpressionBuilder(); var expressionTree = TypeConversion.ImplicitConversion(parser.Parse(expression, context, BindingParserOptions.Create <ValueBindingExpression>()), expectedType, true, true); var jsExpression = new JsParenthesizedExpression(configuration.ServiceProvider.GetRequiredService <JavascriptTranslator>().CompileToJavascript(expressionTree, context)); jsExpression.AcceptVisitor(new KnockoutObservableHandlingVisitor(true)); JsTemporaryVariableResolver.ResolveVariables(jsExpression); return(JavascriptTranslator.FormatKnockoutScript(jsExpression.Expression)); }