コード例 #1
0
ファイル: DataContextStack.cs プロジェクト: holajan/dotvvm
 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;
 }
コード例 #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);
 }
コード例 #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;
 }
コード例 #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);
 }
コード例 #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);
     }
 }
コード例 #7
0
 //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);
 }
コード例 #8
0
 public abstract Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null);
コード例 #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))) + "]";
 }
コード例 #10
0
ファイル: BindingParser.cs プロジェクト: holajan/dotvvm
 public Expression Parse(string value, DataContextStack context)
 {
     return Parse(value, context.DataContextType, context.Parents().ToArray(), context.RootControlType);
 }
コード例 #11
0
 public override Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null)
 {
     return type;
 }