Пример #1
0
 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())));
     }
 }
Пример #2
0
 /// <summary>
 /// Get's Javascript code that can be executed inside knockout data-bind attribute.
 /// </summary>
 public static string FormatKnockoutScript(ParametrizedCode expression, ParametrizedCode contextVariable, ParametrizedCode dataVariable = null)
 {
     if (dataVariable == null)
     {
         dataVariable = new ParametrizedCode.Builder {
             contextVariable, ".$data"
         }
     }