Ejemplo n.º 1
0
 public DataContextStack(Type type, DataContextStack parent = null)
 {
     Parent = parent;
     DataContextType = type;
     RootControlType = parent?.RootControlType;
     //if (parent == null) Parameters = new List<Type>();
     //else Parameters = parent.Parameters;
 }
 public override Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty dproperty = null)
 {
     var property = DotvvmProperty.ResolveProperty(control.Metadata.Type, PropertyName);
     ResolvedPropertySetter propertyValue;
     if (control.Properties.TryGetValue(property, out propertyValue))
     {
         var binding = propertyValue as ResolvedPropertyBinding;
         if (binding == null) return dataContext;
         return binding.Binding.GetExpression().Type;
     }
     else return dataContext;
 }
Ejemplo n.º 3
0
 public object ExecuteBinding(string expression, object[] contexts, DotvvmControl control)
 {
     var context = new DataContextStack(contexts.FirstOrDefault()?.GetType() ?? typeof(object));
     context.RootControlType = control?.GetType() ?? typeof(DotvvmControl);
     for (int i = 1; i < contexts.Length; i++)
     {
         context = new DataContextStack(contexts[i].GetType(), context);
     }
     var parser = new BindingParser();
     var expressionTree = parser.Parse(expression, context);
     return BindingCompiler.CompileToDelegate(expressionTree, context)(contexts, control);
 }
Ejemplo n.º 4
0
 // public static Expression GetDataContextExpression(DataContextStack dataContextStack, ResolvedControl control, DotvvmProperty property = null)
 //{
 //    var attributes = control.Metadata.Type.GetCustomAttributes<DataContextChangeAttribute>();
 //    Expression dataContextExpression = Expression.Parameter(dataContextStack.DataContextType, Constants.ThisSpecialBindingProperty);
 //    var paramDataContextExpression = dataContextExpression;
 //    foreach (var attribute in attributes)
 //    {
 //        // TODO: assign to varialbes to reduce multiple calls ?
 //        dataContextExpression = attribute.GetChildDataContextType(dataContextExpression, dataContextStack, control, property);
 //    }
 //    return dataContextExpression == paramDataContextExpression ? null : dataContextExpression;
 //}
 public static Type GetDataContextExpression(DataContextStack dataContextStack, ResolvedControl control, DotvvmProperty property = null)
 {
     var attributes = property == null ? control.Metadata.Type.GetCustomAttributes<DataContextChangeAttribute>() : property.PropertyInfo?.GetCustomAttributes<DataContextChangeAttribute>();
     if (attributes == null) return null;
     var type = dataContextStack.DataContextType;
     var paramDataContextExpression = type;
     foreach (var attribute in attributes)
     {
         // TODO: assign to varialbes to reduce multiple calls ?
         type = attribute.GetChildDataContextType(type, dataContextStack, control, property);
     }
     return type == paramDataContextExpression ? null : type;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Emits value or binding and returns 
 /// </summary>
 protected ExpressionSyntax ProcessBindingOrValue(object obj, DataContextStack dataContext)
 {
     var binding = obj as ResolvedBinding;
     if (binding != null) return ProcessBinding(binding);
     else return emitter.EmitValue(obj);
 }
Ejemplo n.º 6
0
 protected void ProcessHtmlAttributes(string controlName, IDictionary<string, object> attributes, DataContextStack dataContext)
 {
     foreach (var attr in attributes)
     {
         var value = ProcessBindingOrValue(attr.Value, dataContext);
         emitter.EmitAddHtmlAttribute(controlName, attr.Key, value);
     }
 }
 //public override Expression GetChildDataContextType(Expression dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null)
 //{
 //    return ExpressionUtils.Indexer(dataContext, controlContextStack.GetNextParameter(typeof(int)));
 //}
 public override Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null)
 {
     return ReflectionUtils.GetEnumerableType(dataContext);
 }
Ejemplo n.º 8
0
 public abstract Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null);
Ejemplo n.º 9
0
 public static string GetArgsScript(MethodCallExpression expression, DataContextStack dataContext)
 {
     var target = expression.Object == null ? "null" : JavascriptTranslator.CompileToJavascript(expression.Object, dataContext);
     var arguments = new[] { target }.Concat(expression.Arguments.Select(a => JavascriptTranslator.CompileToJavascript(a, dataContext)));
     return "[" + String.Join(", ", arguments.Select(a => JsonConvert.SerializeObject(a))) + "]";
 }
Ejemplo n.º 10
0
 public Expression Parse(string value, DataContextStack context)
 {
     return Parse(value, context.DataContextType, context.Parents().ToArray(), context.RootControlType);
 }
 public override Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null)
 {
     return type;
 }