private object JoinValuesOrBindings(IList <object> fragments) { if (fragments.All(f => f is string)) { return(string.Join("_", fragments)); } else { BindingCompilationService service = null; var result = new ParametrizedCode.Builder(); var first = true; foreach (var f in fragments) { if (!first | (first = false)) { result.Add("+'_'+"); } if (f is IValueBinding binding) { service = service ?? binding.GetProperty <BindingCompilationService>(ErrorHandlingMode.ReturnNull); result.Add(binding.GetParametrizedKnockoutExpression(this, unwraped: true), 14); } else { result.Add(JavascriptCompilationHelper.CompileConstant(f)); } } if (service == null) { throw new NotSupportedException(); } return(ValueBindingExpression.CreateBinding <string>(service.WithoutInitialization(), h => null, result.Build(new OperatorPrecedence()))); } }
public ParametrizedCode GetJavascriptValue(DotvvmProperty property, bool inherit = true) => GetValueBinding(property, inherit)?.KnockoutExpression ?? new ParametrizedCode(JavascriptCompilationHelper.CompileConstant(GetValue(property)), OperatorPrecedence.Max);