AppendSubBuilder() public method

public AppendSubBuilder ( ControlBuilder subBuilder ) : void
subBuilder ControlBuilder
return void
Example #1
0
        void AppendToProperty(ControlBuilder subBuilder)
        {
            if (typeof(CodeRenderBuilder) == subBuilder.GetType())
            {
                throw new HttpException("Code render not supported here.");
            }

            if (defaultPropertyBuilder != null)
            {
                defaultPropertyBuilder.AppendSubBuilder(subBuilder);
                return;
            }

            AddChild(subBuilder);
        }
Example #2
0
		public void Deny_Unrestricted ()
		{
			ControlBuilder cb = new ControlBuilder ();
			Assert.IsNull (cb.ControlType, "ControlType");
			Assert.IsFalse (cb.HasAspCode, "HasAspCode");
			cb.ID = "mono";
			Assert.AreEqual ("mono", cb.ID, "ID");
			Assert.AreEqual (typeof (Control), cb.NamingContainerType, "NamingContainerType");
			Assert.IsNull (cb.TagName, "TagName");
			Assert.IsTrue (cb.AllowWhitespaceLiterals (), "AllowWhitespaceLiterals");
			cb.AppendLiteralString ("mono");
			cb.AppendSubBuilder (cb);
			cb.CloseControl ();
			Assert.IsNull (cb.GetChildControlType (null, null), "GetChildControlType");
			Assert.IsTrue (cb.HasBody (), "HasBody");
			Assert.IsFalse (cb.HtmlDecodeLiterals (), "HtmlDecodeLiterals");
			cb.Init (null, cb, typeof (TemplateBuilder), "span", "mono", null);
			Assert.IsFalse (cb.NeedsTagInnerText (), "NeedsTagInnerText");
			//cb.OnAppendToParentBuilder (null);
			cb.SetTagInnerText ("mono");

			cb = ControlBuilder.CreateBuilderFromType (null, cb, typeof (TemplateBuilder), "span", "mono", null, 0, String.Empty);
			Assert.IsNotNull (cb, "CreateBuilderFromType");
		}
        /// <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);
        }
Example #4
0
    /*
     * Add a child builder to a builder
     */
    private void AppendSubBuilder(ControlBuilder builder, ControlBuilder subBuilder) {
        // Check if it's an object tag
        if (subBuilder is ObjectTagBuilder) {
            ProcessObjectTag((ObjectTagBuilder) subBuilder);
            return;
        }

        builder.AppendSubBuilder(subBuilder);
    }
 private void AddTagInnerTextElements(ControlBuilder builder)
 {
     if (_tagInnerTextElements != null)
     {
         foreach(Object o in _tagInnerTextElements)
         {
             if (o is String)
             {
                 builder.AppendLiteralString((String)o);
             }
             else
             {
                 builder.AppendSubBuilder((ControlBuilder)o);
             }
         }
         _tagInnerTextElements = null;
     }
 }