public virtual void AppendSubBuilder(ControlBuilder subBuilder) { subBuilder.OnAppendToParentBuilder(this); subBuilder.parentBuilder = this; if (childrenAsProperties) { AppendToProperty(subBuilder); return; } if (typeof(CodeRenderBuilder).IsAssignableFrom(subBuilder.GetType())) { AppendCode(subBuilder); return; } AddChild(subBuilder); }
/// <include file='doc\ControlBuilder.uex' path='docs/doc[@for="ControlBuilder.AppendSubBuilder"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public virtual void AppendSubBuilder(ControlBuilder subBuilder) { // Tell the sub builder that it's about to be appended to its parent subBuilder.OnAppendToParentBuilder(this); if (FChildrenAsProperties) { // Don't allow code blocks when properties are expected (ASURT 97838) if (subBuilder is CodeBlockBuilder) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Code_not_supported_on_not_controls)); } // If there is a default property, delegate to its builder if (_defaultPropBuilder != null) { _defaultPropBuilder.AppendSubBuilder(subBuilder); return; } // The tagname is the property name string propName = subBuilder.TagName; if (subBuilder is TemplateBuilder) // The subBuilder is for building a template { TemplateBuilder tplBuilder = (TemplateBuilder)subBuilder; if (_templateSetter == null) { _templateSetter = new PropertySetter(_ctrlType, InDesigner || NonCompiledPage); } // Add TemplateBuilder to the template setter. _templateSetter.AddTemplateProperty(propName, tplBuilder); return; } if (subBuilder is CollectionBuilder) // The subBuilder is for building a collection // If there are no items in the collection, we're done { if (subBuilder.SubBuilders == null || subBuilder.SubBuilders.Count == 0) { return; } IEnumerator subBuilders = subBuilder.SubBuilders.GetEnumerator(); while (subBuilders.MoveNext()) { ControlBuilder builder = (ControlBuilder)subBuilders.Current; subBuilder.ComplexAttribSetter.AddCollectionItem(builder); } subBuilder.SubBuilders.Clear(); ComplexAttribSetter.AddComplexProperty(propName, subBuilder); return; } ComplexAttribSetter.AddComplexProperty(propName, subBuilder); return; } CodeBlockBuilder codeBlockBuilder = subBuilder as CodeBlockBuilder; if (codeBlockBuilder != null) { // Don't allow code blocks inside non-control tags (ASURT 76719) if (ControlType != null && !typeof(Control).IsAssignableFrom(ControlType)) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Code_not_supported_on_not_controls)); } // Is it a databinding expression? <%# ... %> if (codeBlockBuilder.BlockType == CodeBlockType.DataBinding) { if (InDesigner) { // In the designer, don't use the fancy multipart DataBoundLiteralControl, // which breaks a number of things (ASURT 82925,86738). Instead, use the // simpler DesignerDataBoundLiteralControl, and do standard databinding // on its Text property. IDictionary attribs = new SortedList(); attribs.Add("Text", "<%#" + codeBlockBuilder.Content + "%>"); subBuilder = CreateBuilderFromType( Parser, this, typeof(DesignerDataBoundLiteralControl), null, null, attribs, codeBlockBuilder.Line, codeBlockBuilder.SourceFileName); } else { // Get the last builder, and check if it's a DataBoundLiteralControlBuilder object lastBuilder = GetLastBuilder(); DataBoundLiteralControlBuilder dataBoundBuilder = lastBuilder as DataBoundLiteralControlBuilder; // If not, then we need to create one. Otherwise, just append to the // existing one bool fNewDataBoundLiteralControl = false; if (dataBoundBuilder == null) { dataBoundBuilder = new DataBoundLiteralControlBuilder(); dataBoundBuilder.Init(_parser, this, typeof(DataBoundLiteralControl), null, null, null); fNewDataBoundLiteralControl = true; // If the previous builder was a string, add it as the first // entry in the composite control. string s = lastBuilder as string; if (s != null) { _subBuilders.RemoveAt(_subBuilders.Count - 1); dataBoundBuilder.AddLiteralString(s); } } dataBoundBuilder.AddDataBindingExpression(codeBlockBuilder); if (!fNewDataBoundLiteralControl) { return; } subBuilder = dataBoundBuilder; } } else { // Set a flag if there is at least one block of ASP code _fHasAspCode = true; } } if (FIsNonParserAccessor) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Children_not_supported_on_not_controls)); } AddSubBuilder(subBuilder); }
public virtual void AppendSubBuilder (ControlBuilder subBuilder) { subBuilder.OnAppendToParentBuilder (this); subBuilder.parentBuilder = this; if (childrenAsProperties) { AppendToProperty (subBuilder); return; } if (typeof (CodeRenderBuilder).IsAssignableFrom (subBuilder.GetType ())) { AppendCode (subBuilder); return; } AddChild (subBuilder); }
/// <devdoc> /// /// </devdoc> public virtual void AppendSubBuilder(ControlBuilder subBuilder) { // Tell the sub builder that it's about to be appended to its parent subBuilder.OnAppendToParentBuilder(this); if (FChildrenAsProperties) { // Don't allow code blocks when properties are expected (ASURT 97838) if (subBuilder is CodeBlockBuilder) { throw new HttpException(SR.GetString(SR.Code_not_supported_on_not_controls)); } // If there is a default property, delegate to its builder if (DefaultPropertyBuilder != null) { DefaultPropertyBuilder.AppendSubBuilder(subBuilder); return; } // The tagname is the property name string propName = subBuilder.TagName; if (subBuilder is TemplateBuilder) { TemplateBuilder tplBuilder = (TemplateBuilder)subBuilder; AddTemplateProperty(tplBuilder.Filter, propName, tplBuilder); } else if (subBuilder is CollectionBuilder) { // If there are items in the collection, add them if ((subBuilder.SubBuilders != null) && (subBuilder.SubBuilders.Count > 0)) { IEnumerator subBuilders = subBuilder.SubBuilders.GetEnumerator(); while (subBuilders.MoveNext()) { ControlBuilder builder = (ControlBuilder)subBuilders.Current; subBuilder.AddCollectionItem(builder); } subBuilder.SubBuilders.Clear(); AddComplexProperty(subBuilder.Filter, propName, subBuilder); } } else if (subBuilder is StringPropertyBuilder) { // Trim this so whitespace doesn't matter inside a tag? string text = ((StringPropertyBuilder)subBuilder).Text.Trim(); if (!String.IsNullOrEmpty(text)) { // Make sure we haven't set this property in the attributes already (special case for TextBox and similar things) AddComplexProperty(subBuilder.Filter, propName, subBuilder); } } else { AddComplexProperty(subBuilder.Filter, propName, subBuilder); } return; } CodeBlockBuilder codeBlockBuilder = subBuilder as CodeBlockBuilder; if (codeBlockBuilder != null) { // Don't allow code blocks inside non-control tags (ASURT 76719) if (ControlType != null && !flags[controlTypeIsControl]) { throw new HttpException(SR.GetString(SR.Code_not_supported_on_not_controls)); } // Is it a databinding expression? <%# ... %> if (codeBlockBuilder.BlockType == CodeBlockType.DataBinding) { // Bind statements are not allowed as DataBoundLiterals inside any template. // Outside a template, they should be treated as calls to page code. Match match; if ((match = bindExpressionRegex.Match(codeBlockBuilder.Content, 0)).Success || (match = bindItemExpressionRegex.Match(codeBlockBuilder.Content, 0)).Success) { ControlBuilder currentBuilder = this; while (currentBuilder != null && !(currentBuilder is TemplateBuilder)) { currentBuilder = currentBuilder.ParentBuilder; } if (currentBuilder != null && currentBuilder.ParentBuilder != null && currentBuilder is TemplateBuilder) { throw new HttpException(SR.GetString(SR.DataBoundLiterals_cant_bind)); } } if (InDesigner) { // In the designer, don't use the fancy multipart DataBoundLiteralControl, // which breaks a number of things (ASURT 82925,86738). Instead, use the // simpler DesignerDataBoundLiteralControl, and do standard databinding // on its Text property. IDictionary attribs = new ParsedAttributeCollection(); attribs.Add("Text", "<%#" + codeBlockBuilder.Content + "%>"); subBuilder = CreateBuilderFromType(Parser, this, typeof(DesignerDataBoundLiteralControl), null, null, attribs, codeBlockBuilder.Line, codeBlockBuilder.PageVirtualPath); } else { // Get the last builder, and check if it's a DataBoundLiteralControlBuilder object lastBuilder = GetLastBuilder(); DataBoundLiteralControlBuilder dataBoundBuilder = lastBuilder as DataBoundLiteralControlBuilder; // If not, then we need to create one. Otherwise, just append to the // existing one bool fNewDataBoundLiteralControl = false; if (dataBoundBuilder == null) { dataBoundBuilder = new DataBoundLiteralControlBuilder(); dataBoundBuilder.Init(Parser, this, typeof(DataBoundLiteralControl), null, null, null); dataBoundBuilder.Line = codeBlockBuilder.Line; dataBoundBuilder.VirtualPath = codeBlockBuilder.VirtualPath; fNewDataBoundLiteralControl = true; // If the previous builder was a string, add it as the first // entry in the composite control. // But if instrumentation is enabled, the strings need to be // treated separately, so don't combine them if (!PageInstrumentationService.IsEnabled) { string s = lastBuilder as string; if (s != null) { SubBuilders.RemoveAt(SubBuilders.Count - 1); dataBoundBuilder.AddLiteralString(s); } } } dataBoundBuilder.AddDataBindingExpression(codeBlockBuilder); if (!fNewDataBoundLiteralControl) return; subBuilder = dataBoundBuilder; } } else { // Set a flag if there is at least one block of ASP code ParseTimeData.HasAspCode = true; } } if (FIsNonParserAccessor) { throw new HttpException(SR.GetString(SR.Children_not_supported_on_not_controls)); } AddSubBuilder(subBuilder); }
public virtual void AppendSubBuilder(ControlBuilder subBuilder) { subBuilder.OnAppendToParentBuilder(this); if (this.FChildrenAsProperties) { if (subBuilder is CodeBlockBuilder) { throw new HttpException(System.Web.SR.GetString("Code_not_supported_on_not_controls")); } if (this.DefaultPropertyBuilder != null) { this.DefaultPropertyBuilder.AppendSubBuilder(subBuilder); } else { string tagName = subBuilder.TagName; if (subBuilder is TemplateBuilder) { TemplateBuilder builder = (TemplateBuilder) subBuilder; this.AddTemplateProperty(builder.Filter, tagName, builder); } else if (subBuilder is CollectionBuilder) { if ((subBuilder.SubBuilders != null) && (subBuilder.SubBuilders.Count > 0)) { IEnumerator enumerator = subBuilder.SubBuilders.GetEnumerator(); while (enumerator.MoveNext()) { ControlBuilder current = (ControlBuilder) enumerator.Current; subBuilder.AddCollectionItem(current); } subBuilder.SubBuilders.Clear(); this.AddComplexProperty(subBuilder.Filter, tagName, subBuilder); } } else if (subBuilder is StringPropertyBuilder) { if (!string.IsNullOrEmpty(((StringPropertyBuilder) subBuilder).Text.Trim())) { this.AddComplexProperty(subBuilder.Filter, tagName, subBuilder); } } else { this.AddComplexProperty(subBuilder.Filter, tagName, subBuilder); } } } else { CodeBlockBuilder codeBlockBuilder = subBuilder as CodeBlockBuilder; if (codeBlockBuilder != null) { if ((this.ControlType != null) && !this.flags[0x2000]) { throw new HttpException(System.Web.SR.GetString("Code_not_supported_on_not_controls")); } if (codeBlockBuilder.BlockType == CodeBlockType.DataBinding) { if (bindExpressionRegex.Match(codeBlockBuilder.Content, 0).Success) { ControlBuilder parentBuilder = this; while ((parentBuilder != null) && !(parentBuilder is TemplateBuilder)) { parentBuilder = parentBuilder.ParentBuilder; } if (((parentBuilder != null) && (parentBuilder.ParentBuilder != null)) && (parentBuilder is TemplateBuilder)) { throw new HttpException(System.Web.SR.GetString("DataBoundLiterals_cant_bind")); } } if (this.InDesigner) { IDictionary attribs = new ParsedAttributeCollection(); attribs.Add("Text", "<%#" + codeBlockBuilder.Content + "%>"); subBuilder = CreateBuilderFromType(this.Parser, this, typeof(DesignerDataBoundLiteralControl), null, null, attribs, codeBlockBuilder.Line, codeBlockBuilder.PageVirtualPath); } else { object lastBuilder = this.GetLastBuilder(); DataBoundLiteralControlBuilder builder5 = lastBuilder as DataBoundLiteralControlBuilder; bool flag = false; if (builder5 == null) { builder5 = new DataBoundLiteralControlBuilder(); builder5.Init(this.Parser, this, typeof(DataBoundLiteralControl), null, null, null); builder5.Line = codeBlockBuilder.Line; builder5.VirtualPath = codeBlockBuilder.VirtualPath; flag = true; string s = lastBuilder as string; if (s != null) { this.SubBuilders.RemoveAt(this.SubBuilders.Count - 1); builder5.AddLiteralString(s); } } builder5.AddDataBindingExpression(codeBlockBuilder); if (!flag) { return; } subBuilder = builder5; } } else { this.ParseTimeData.HasAspCode = true; } } if (this.FIsNonParserAccessor) { throw new HttpException(System.Web.SR.GetString("Children_not_supported_on_not_controls")); } this.AddSubBuilder(subBuilder); } }