/// <summary> /// Processes the node. /// </summary> public override void VisitControl(ResolvedControl node) { var parentName = controlName; controlName = CreateControl(node); base.VisitControl(node); emitter.EmitAddCollectionItem(parentName, controlName); controlName = parentName; }
public override void VisitControl(ResolvedControl control) { Matcher.PushControl(control); foreach (var style in Matcher.GetMatchingStyles()) { style.ApplyStyle(control); } base.VisitControl(control); Matcher.PopControl(); }
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; }
// 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; }
protected virtual void ApplyStyle(ResolvedControl control) { if(SetHtmlAttributes != null) { foreach (var attr in SetHtmlAttributes) { if(control.HtmlAttributes == null || !control.HtmlAttributes.ContainsKey(attr.Key) || attr.Value.append) { control.SetHtmlAttribute(attr.Key, attr.Value.value); } } } if(SetProperties != null) { foreach (var prop in SetProperties) { if(!control.Properties.ContainsKey(prop.Key)) { control.Properties.Add(prop.Key, prop.Value); } } } }
public virtual void VisitControl(ResolvedControl control) { DefaultVisit(control); }
public ResolvedPropertyControl(DotvvmProperty property, ResolvedControl control) : base(property) { Control = control; }
/// <summary> /// Processes the HTML element that represents a new object. /// </summary> protected string CreateControl(ResolvedControl control) { string name; if (control.Metadata.ControlBuilderType == null) { // compiled control name = emitter.EmitCreateObject(control.Metadata.Type, control.ContructorParameters); } else { // markup control name = emitter.EmitInvokeControlBuilder(control.Metadata.Type, control.Metadata.VirtualPath); } emitter.EmitSetAttachedProperty(name, typeof(Internal).FullName, Internal.UniqueIDProperty.Name, name); if(control.HtmlAttributes != null && control.Metadata.HasHtmlAttributesCollection) { ProcessHtmlAttributes(name, control.HtmlAttributes, control.DataContextTypeStack); } return name; }
//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); }
public void PushControl(ResolvedControl control) { Context = new StyleMatchContext() { Control = control, Parent = Context }; }
public abstract Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null);
public void ApplyStyle(ResolvedControl control) { @this.ApplyStyle(control); }
public override Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, ResolvedControl control, DotvvmProperty property = null) { return type; }