AllowWhitespaceLiterals() public method

public AllowWhitespaceLiterals ( ) : bool
return bool
Example #1
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");
		}
        private void BuildBuildMethodInternal(ControlBuilder builder, Type ctrlType, bool fInTemplate,
            bool topLevelControlInTemplate, PropertyEntry pse, CodeStatementCollection statements,
            bool fStandardControl, bool fControlFieldDeclared, string deviceFilter, bool fControlSkin) {

            // Same linePragma in the entire build method
            CodeLinePragma linePragma = CreateCodeLinePragma(builder);

            CodeObjectCreateExpression newExpr;
            CodeExpressionStatement methCallStatement;
            CodeMethodInvokeExpression methCallExpression;

            CodeExpression ctrlRefExpr;

            if (fControlSkin) {
                CodeCastExpression cast = new CodeCastExpression(builder.ControlType.FullName,
                                           new CodeArgumentReferenceExpression("ctrl"));
                statements.Add(new CodeVariableDeclarationStatement(builder.ControlType.FullName, "__ctrl", cast));
                ctrlRefExpr = new CodeVariableReferenceExpression("__ctrl");
            }
            // Not a control. ie. it's for a template or a r/o complex prop,
            else if (!fControlFieldDeclared) {
                ctrlRefExpr = new CodeArgumentReferenceExpression("__ctrl");
            }
            else {
                CodeTypeReference ctrlTypeRef = CodeDomUtility.BuildGlobalCodeTypeReference(ctrlType);
                    
                newExpr = new CodeObjectCreateExpression(ctrlTypeRef);

                // If it has a ConstructorNeedsTagAttribute, it needs a tag name
                ConstructorNeedsTagAttribute cnta = (ConstructorNeedsTagAttribute)
                    TypeDescriptor.GetAttributes(ctrlType)[typeof(ConstructorNeedsTagAttribute)];

                if (cnta != null && cnta.NeedsTag) {
                    newExpr.Parameters.Add(new CodePrimitiveExpression(builder.TagName));
                }

                // If it's for a DataBoundLiteralControl, pass it the number of
                // entries in the constructor
                DataBoundLiteralControlBuilder dataBoundBuilder = builder as DataBoundLiteralControlBuilder;
                if (dataBoundBuilder != null) {
                    newExpr.Parameters.Add(new CodePrimitiveExpression(
                        dataBoundBuilder.GetStaticLiteralsCount()));
                    newExpr.Parameters.Add(new CodePrimitiveExpression(
                        dataBoundBuilder.GetDataBoundLiteralCount()));
                }

                // e.g. {{controlTypeName}} __ctrl;
                statements.Add(new CodeVariableDeclarationStatement(ctrlTypeRef, "__ctrl"));
                ctrlRefExpr = new CodeVariableReferenceExpression("__ctrl");

                // e.g. __ctrl = new {{controlTypeName}}();
                CodeAssignStatement setCtl = new CodeAssignStatement(ctrlRefExpr, newExpr);
                setCtl.LinePragma = linePragma;
                statements.Add(setCtl);

                if (!builder.IsGeneratedID) {
                    // Assign the local control reference to the global control variable
                    CodeFieldReferenceExpression ctrlNameExpr = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), builder.ID);

                    // e.g. {{controlName}} = __ctrl;
                    CodeAssignStatement underscoreCtlSet = new CodeAssignStatement(ctrlNameExpr, ctrlRefExpr);
                    statements.Add(underscoreCtlSet);
                }

                // Don't do this if the control is itself a TemplateControl, in which case it
                // will point its TemplateControl property to itself (instead of its parent
                // TemplateControl).  VSWhidbey 214356.
                if (topLevelControlInTemplate && !typeof(TemplateControl).IsAssignableFrom(ctrlType)) {
                    statements.Add(BuildTemplatePropertyStatement(ctrlRefExpr));
                }

                if (fStandardControl) {
                    // e.g. __ctrl.SkinID = {{skinID}};
                    if (builder.SkinID != null) {
                        CodeAssignStatement set = new CodeAssignStatement();
                        set.Left = new CodePropertyReferenceExpression(ctrlRefExpr, skinIDPropertyName);
                        set.Right = new CodePrimitiveExpression(builder.SkinID);
                        statements.Add(set);
                    }

                    // e.g. __ctrl.ApplyStyleSheetSkin(this);
                    if (ThemeableAttribute.IsTypeThemeable(ctrlType)) {
                        // e.g. __ctrl.ApplyStyleSheetSkin(this.Page);
                        CodeMethodInvokeExpression applyStyleSheetExpr = new CodeMethodInvokeExpression(ctrlRefExpr, applyStyleSheetMethodName);
                        applyStyleSheetExpr.Parameters.Add(BuildPagePropertyReferenceExpression());

                        statements.Add(applyStyleSheetExpr);
                    }
                }
            }

            // Process the templates
            if (builder.TemplatePropertyEntries.Count > 0) {

                // Used to deal with the device filter conditionals
                CodeStatementCollection currentStmts;
                CodeStatementCollection nextStmts = statements;
                PropertyEntry previous = null;

                foreach (TemplatePropertyEntry pseSub in builder.TemplatePropertyEntries) {
                    currentStmts = nextStmts;

                    HandleDeviceFilterConditional(ref previous, pseSub, statements, ref currentStmts, out nextStmts);

                    string controlName = pseSub.Builder.ID;
                    CodeDelegateCreateExpression newDelegate = new CodeDelegateCreateExpression();
                    newDelegate.DelegateType = new CodeTypeReference(typeof(BuildTemplateMethod));
                    newDelegate.TargetObject = new CodeThisReferenceExpression();
                    newDelegate.MethodName = buildMethodPrefix + controlName;

                    CodeAssignStatement set = new CodeAssignStatement();
                    if (pseSub.PropertyInfo != null) {
                        set.Left = new CodePropertyReferenceExpression(ctrlRefExpr, pseSub.Name);
                    }
                    else {
                        set.Left = new CodeFieldReferenceExpression(ctrlRefExpr, pseSub.Name);
                    }

                    if (pseSub.BindableTemplate) {
                        // e.g. __ctrl.{{templateName}} = new CompiledBindableTemplateBuilder(
                        // e.g.     new BuildTemplateMethod(this.__BuildControl {{controlName}}),
                        // e.g.     new ExtractTemplateValuesMethod(this.__ExtractValues {{controlName}}));
                        CodeExpression newExtractValuesDelegate;
                        if (pseSub.Builder.HasTwoWayBoundProperties) {
                            newExtractValuesDelegate = new CodeDelegateCreateExpression();
                            ((CodeDelegateCreateExpression)newExtractValuesDelegate).DelegateType = new CodeTypeReference(typeof(ExtractTemplateValuesMethod));
                            ((CodeDelegateCreateExpression)newExtractValuesDelegate).TargetObject = new CodeThisReferenceExpression();
                            ((CodeDelegateCreateExpression)newExtractValuesDelegate).MethodName = extractTemplateValuesMethodPrefix + controlName;
                        }
                        else {
                            newExtractValuesDelegate = new CodePrimitiveExpression(null);
                        }

                        newExpr = new CodeObjectCreateExpression(typeof(CompiledBindableTemplateBuilder));
                        newExpr.Parameters.Add(newDelegate);
                        newExpr.Parameters.Add(newExtractValuesDelegate);

                    }
                    else {
                        // e.g. __ctrl.{{templateName}} = new CompiledTemplateBuilder(
                        // e.g.     new BuildTemplateMethod(this.__BuildControl {{controlName}}));
                        newExpr = new CodeObjectCreateExpression(typeof(CompiledTemplateBuilder));
                        newExpr.Parameters.Add(newDelegate);

                    }
                    set.Right = newExpr;
                    set.LinePragma = CreateCodeLinePragma(pseSub.Builder);
                    currentStmts.Add(set);
                }
            }

            // Is this BuilderData for a declarative control?  If so initialize it (75330)
            // Only do this is the control field has been declared (i.e. not with templates)
            if (typeof(UserControl).IsAssignableFrom(ctrlType) && fControlFieldDeclared && !fControlSkin) {
                // e.g. _ctrl.InitializeAsUserControl(Context, Page);
                methCallExpression = new CodeMethodInvokeExpression(ctrlRefExpr, "InitializeAsUserControl");
                methCallExpression.Parameters.Add(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), pagePropertyName));
                methCallStatement = new CodeExpressionStatement(methCallExpression);
                methCallStatement.LinePragma = linePragma;
                statements.Add(methCallStatement);
            }

            // Process the simple attributes
            if (builder.SimplePropertyEntries.Count > 0) {
                // Used to deal with the device filter conditionals
                CodeStatementCollection currentStmts;
                CodeStatementCollection nextStmts = statements;
                PropertyEntry previous = null;

                foreach (SimplePropertyEntry pseSub in builder.SimplePropertyEntries) {
                    currentStmts = nextStmts;

                    HandleDeviceFilterConditional(ref previous, pseSub, statements, ref currentStmts, out nextStmts);

                    CodeStatement statement = pseSub.GetCodeStatement(this, ctrlRefExpr);
                    statement.LinePragma = linePragma;
                    currentStmts.Add(statement);
                }
            }

            // Call the helper method for allowing page developers to customize culture settings
            if (typeof(Page).IsAssignableFrom(ctrlType) && !fControlSkin) {
                // e.g. this.InitializeCulture();
                methCallExpression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InitializeCulture");
                methCallStatement = new CodeExpressionStatement(methCallExpression);
                methCallStatement.LinePragma = linePragma;
                statements.Add(methCallStatement);
            }

            // Automatic template support (i.e. <asp:template name=SomeTemplate/>)
            CodeMethodInvokeExpression instantiateTemplateExpr = null;
            CodeConditionStatement templateIfStmt = null;
            CodeStatementCollection buildSubControlBlock = statements;
            string autoTemplateName = null;
            if (builder is System.Web.UI.WebControls.ContentPlaceHolderBuilder) {

                string templateName = ((System.Web.UI.WebControls.ContentPlaceHolderBuilder)builder).Name;
                autoTemplateName = MasterPageControlBuilder.AutoTemplatePrefix + templateName;

                Debug.Assert(autoTemplateName != null && autoTemplateName.Length > 0, "Template Name is empty.");

                // Generate a private field and public property for the ITemplate
                string fieldName = "__"+ autoTemplateName;

                Type containerType = builder.BindingContainerType;
                // Use the base class or template type if INamingContainer cannot be found.
                if (!typeof(INamingContainer).IsAssignableFrom(containerType)) {
                    if (typeof(INamingContainer).IsAssignableFrom(Parser.BaseType)) {
                        containerType = Parser.BaseType;
                    }
                    else {
                        // This should not occur as all base classes are namingcontainers.
                        Debug.Assert(false, "baseClassType is not an INamingContainer");
                        containerType = typeof(System.Web.UI.Control);
                    }
                }

                CodeAttributeDeclarationCollection attrDeclarations = new CodeAttributeDeclarationCollection();

                CodeAttributeDeclaration templateContainerAttrDeclaration = new CodeAttributeDeclaration(
                    "TemplateContainer",
                    new CodeAttributeArgument[] {
                        new CodeAttributeArgument(new CodeTypeOfExpression(containerType))});

                attrDeclarations.Add(templateContainerAttrDeclaration);

                // If the template control is in a template, assume its container allows multiple instances,
                // otherwise set the TemplateInstanceAttribute
                if (fInTemplate == false) {
                    CodeAttributeDeclaration templateInstanceAttrDeclaration = new CodeAttributeDeclaration(
                        "TemplateInstanceAttribute",
                        new CodeAttributeArgument[] {
                            new CodeAttributeArgument(
                                new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(TemplateInstance)),
                                                                 "Single"))});
                    attrDeclarations.Add(templateInstanceAttrDeclaration);
                }

                BuildFieldAndAccessorProperty(autoTemplateName, fieldName, typeof(ITemplate), false /*fStatic*/, attrDeclarations);
                CodeExpression templateFieldRef = new CodeFieldReferenceExpression(
                    new CodeThisReferenceExpression(), fieldName);

                if (builder is System.Web.UI.WebControls.ContentPlaceHolderBuilder) {
                    // We generate something like this:
                    // if (this.ContentTemplates != null) {
                    //     this.__Template_TestTemplate = (ITemplate)this.ContentTemplates[{templateName}];
                    // }
                    CodePropertyReferenceExpression contentTemplatesFieldRef = 
                        new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ContentTemplates");

                    CodeAssignStatement setStatement = new CodeAssignStatement();
                    setStatement.Left = templateFieldRef;
                    setStatement.Right = new CodeCastExpression(typeof(ITemplate), new CodeIndexerExpression(contentTemplatesFieldRef, 
                                                                                       new CodePrimitiveExpression(templateName)));

                    CodeConditionStatement contentTemplateIfStmt = new CodeConditionStatement();

                    CodeBinaryOperatorExpression contentNullCheckExpr = new CodeBinaryOperatorExpression(contentTemplatesFieldRef, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));

                    CodeMethodInvokeExpression removeExpr = new CodeMethodInvokeExpression(contentTemplatesFieldRef, "Remove");
                    removeExpr.Parameters.Add(new CodePrimitiveExpression(templateName));

                    contentTemplateIfStmt.Condition = contentNullCheckExpr;
                    contentTemplateIfStmt.TrueStatements.Add(setStatement);
                    
                    statements.Add(contentTemplateIfStmt);
                }

                // We generate something like this:
                // if ((this.__Template_TestTemplate != null)) {
                //     // For 2.0:
                //     this.__Template_TestTemplate.InstantiateIn(__ctrl);
                //     // For 4.0, use a new method. This is for fixing Dev10 bug 776195.
                //     this.InstantiateInContentPlaceHolder(__ctrl, this.__Template_TestTemplate);
                // }
                // else {
                //     // normal sub control building code
                // }
                if (MultiTargetingUtil.IsTargetFramework40OrAbove) {
                    instantiateTemplateExpr = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InstantiateInContentPlaceHolder");
                    instantiateTemplateExpr.Parameters.Add(ctrlRefExpr);
                    instantiateTemplateExpr.Parameters.Add(templateFieldRef);
                }
                else {
                    instantiateTemplateExpr = new CodeMethodInvokeExpression(templateFieldRef, "InstantiateIn");
                    instantiateTemplateExpr.Parameters.Add(ctrlRefExpr);
                }

                templateIfStmt = new CodeConditionStatement();
                templateIfStmt.Condition = new CodeBinaryOperatorExpression(templateFieldRef, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
                templateIfStmt.TrueStatements.Add(new CodeExpressionStatement(instantiateTemplateExpr));
                buildSubControlBlock = templateIfStmt.FalseStatements;
                statements.Add(templateIfStmt);
            }

            ICollection contentBuilderEntries = null;
            if (builder is FileLevelPageControlBuilder) {
                contentBuilderEntries = ((FileLevelPageControlBuilder)builder).ContentBuilderEntries;

                if (contentBuilderEntries != null) {
                    CodeStatementCollection currentStmts;
                    CodeStatementCollection nextStmts = statements;
                    PropertyEntry previous = null;

                    foreach (TemplatePropertyEntry entry in contentBuilderEntries) {
                        System.Web.UI.WebControls.ContentBuilderInternal child = 
                            (System.Web.UI.WebControls.ContentBuilderInternal)entry.Builder;

                        currentStmts = nextStmts;

                        HandleDeviceFilterConditional(ref previous, entry, statements, ref currentStmts, out nextStmts);

                        string controlName = child.ID;
                        string contentPlaceHolderID = child.ContentPlaceHolder;

                        CodeDelegateCreateExpression newDelegate = new CodeDelegateCreateExpression();
                        newDelegate.DelegateType = new CodeTypeReference(typeof(BuildTemplateMethod));
                        newDelegate.TargetObject = new CodeThisReferenceExpression();
                        newDelegate.MethodName = buildMethodPrefix + controlName;

                        // e.g. this.AddContentTemplate(contentPlaceHolderID, new CompiledTemplateBuilder(
                        // e.g.     new BuildTemplateMethod(this.__BuildControl {{controlName}}));
                        CodeObjectCreateExpression cocExpr = new CodeObjectCreateExpression(typeof(CompiledTemplateBuilder));
                        cocExpr.Parameters.Add(newDelegate);

                        CodeMethodInvokeExpression cmiExpression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "AddContentTemplate");
                        cmiExpression.Parameters.Add(new CodePrimitiveExpression(contentPlaceHolderID));
                        cmiExpression.Parameters.Add(cocExpr);

                        CodeExpressionStatement ceStatement = new CodeExpressionStatement(cmiExpression);
                        ceStatement.LinePragma = CreateCodeLinePragma((ControlBuilder)child);

                        currentStmts.Add(ceStatement);
                    }
                }
            }

            if (builder is DataBoundLiteralControlBuilder) {

                // If it's a DataBoundLiteralControl, build it by calling SetStaticString
                // on all the static literal strings.
                int i = -1;
                foreach (object child in builder.SubBuilders) {
                    i++;

                    // Ignore it if it's null
                    if (child == null)
                        continue;

                    // Only deal with the strings here, which have even index
                    if (i % 2 == 1) {
                        Debug.Assert(child is CodeBlockBuilder, "child is CodeBlockBuilder");
                        continue;
                    }

                    string s = (string) child;

                    // e.g. __ctrl.SetStaticString(3, "literal string");
                    methCallExpression = new CodeMethodInvokeExpression(ctrlRefExpr, "SetStaticString");
                    methCallExpression.Parameters.Add(new CodePrimitiveExpression(i/2));
                    methCallExpression.Parameters.Add(new CodePrimitiveExpression(s));
                    statements.Add(new CodeExpressionStatement(methCallExpression));
                }
            }
            // Process the children
            else if (builder.SubBuilders != null) {

                bool gotParserVariable = false;
                int localVarIndex = 1;

                foreach (object child in builder.SubBuilders) {
                    if (child is ControlBuilder && !(child is CodeBlockBuilder) && !(child is CodeStatementBuilder) && !(child is System.Web.UI.WebControls.ContentBuilderInternal)) {
                        ControlBuilder ctrlBuilder = (ControlBuilder) child;

                        if (fControlSkin) {
                            throw new HttpParseException(SR.GetString(SR.ControlSkin_cannot_contain_controls),
                                null,
                                builder.VirtualPath, null, builder.Line);
                        }

                        PartialCachingAttribute cacheAttrib = (PartialCachingAttribute)
                            TypeDescriptor.GetAttributes(ctrlBuilder.ControlType)[typeof(PartialCachingAttribute)];

                        methCallExpression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(),
                                                                          buildMethodPrefix + ctrlBuilder.ID);
                        methCallStatement = new CodeExpressionStatement(methCallExpression);

                        if (cacheAttrib == null) {
                            string localVariableRef = _localVariableRef + (localVarIndex++).ToString(CultureInfo.InvariantCulture);

                            // Variable reference to the local control variable
                            CodeVariableReferenceExpression childCtrlRefExpr = new CodeVariableReferenceExpression(localVariableRef);

                            // e.g. {{controlTypeName}} ctrl5;
                            CodeTypeReference ctrlTypeReference =
                                CodeDomUtility.BuildGlobalCodeTypeReference(ctrlBuilder.ControlType);
                            buildSubControlBlock.Add(new CodeVariableDeclarationStatement(ctrlTypeReference, localVariableRef));

                            // e.g. ctrl5 = __BuildControl__control6();
                            CodeAssignStatement setCtl = new CodeAssignStatement(childCtrlRefExpr, methCallExpression);
                            setCtl.LinePragma = linePragma;
                            buildSubControlBlock.Add(setCtl);

                            // If there is no caching on the control, just create it and add it
                            // e.g. __parser.AddParsedSubObject(ctrl5);
                            BuildAddParsedSubObjectStatement(
                                buildSubControlBlock,
                                childCtrlRefExpr,
                                linePragma,
                                ctrlRefExpr,
                                ref gotParserVariable);
                        }
                        else {
                            string providerName = null;
                            // Only use the providerName parameter when targeting 4.0 and above
                            bool useProviderName = MultiTargetingUtil.IsTargetFramework40OrAbove;
                            if (useProviderName) {
                                providerName = cacheAttrib.ProviderName;
                                if (providerName == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) {
                                    providerName = null;
                                }
                            }
                            // The control's output is getting cached.  Call
                            // StaticPartialCachingControl.BuildCachedControl to do the work.

                            // e.g. StaticPartialCachingControl.BuildCachedControl(__ctrl, Request, "e4192e6d-cbe0-4df5-b516-682c10415590", __pca, new System.Web.UI.BuildMethod(this.__BuildControlt1));
                            CodeMethodInvokeExpression call = new CodeMethodInvokeExpression();
                            call.Method.TargetObject = new CodeTypeReferenceExpression(typeof(System.Web.UI.StaticPartialCachingControl));
                            call.Method.MethodName = "BuildCachedControl";
                            call.Parameters.Add(ctrlRefExpr);
                            call.Parameters.Add(new CodePrimitiveExpression(ctrlBuilder.ID));

                            // If the caching is shared, use the type of the control as the key
                            // otherwise, generate a guid
                            if (cacheAttrib.Shared) {
                                call.Parameters.Add(new CodePrimitiveExpression(
                                    ctrlBuilder.ControlType.GetHashCode().ToString(CultureInfo.InvariantCulture)));
                            }
                            else
                                call.Parameters.Add(new CodePrimitiveExpression(Guid.NewGuid().ToString()));
                            call.Parameters.Add(new CodePrimitiveExpression(cacheAttrib.Duration));
                            call.Parameters.Add(new CodePrimitiveExpression(cacheAttrib.VaryByParams));
                            call.Parameters.Add(new CodePrimitiveExpression(cacheAttrib.VaryByControls));
                            call.Parameters.Add(new CodePrimitiveExpression(cacheAttrib.VaryByCustom));
                            call.Parameters.Add(new CodePrimitiveExpression(cacheAttrib.SqlDependency));
                            CodeDelegateCreateExpression newDelegate = new CodeDelegateCreateExpression();
                            newDelegate.DelegateType = new CodeTypeReference(typeof(BuildMethod));
                            newDelegate.TargetObject = new CodeThisReferenceExpression();
                            newDelegate.MethodName = buildMethodPrefix + ctrlBuilder.ID;
                            call.Parameters.Add(newDelegate);
                            if (useProviderName) {
                                call.Parameters.Add(new CodePrimitiveExpression(providerName));
                            }
                            buildSubControlBlock.Add(new CodeExpressionStatement(call));
                        }

                    }
                    else if (child is string && !builder.HasAspCode) {

                        // VSWhidbey 276806: if the control cares about the inner text (builder does not allow whitespace literals)
                        // the inner literals should be added to the control.
                        if (!fControlSkin || !builder.AllowWhitespaceLiterals()) {
                            string s = (string) child;
                            CodeExpression expr;

                            if (!UseResourceLiteralString(s)) {
                                // e.g. ((IParserAccessor)__ctrl).AddParsedSubObject(new LiteralControl({{@QuoteCString(text)}}));
                                newExpr = new CodeObjectCreateExpression(typeof(LiteralControl));
                                newExpr.Parameters.Add(new CodePrimitiveExpression(s));
                                expr = newExpr;
                            }
                            else {
                                // Add the string to the resource builder, and get back its offset/size
                                int offset, size;
                                bool fAsciiOnly;
                                _stringResourceBuilder.AddString(s, out offset, out size, out fAsciiOnly);

                                methCallExpression = new CodeMethodInvokeExpression();
                                methCallExpression.Method.TargetObject = new CodeThisReferenceExpression();
                                methCallExpression.Method.MethodName = "CreateResourceBasedLiteralControl";
                                methCallExpression.Parameters.Add(new CodePrimitiveExpression(offset));
                                methCallExpression.Parameters.Add(new CodePrimitiveExpression(size));
                                methCallExpression.Parameters.Add(new CodePrimitiveExpression(fAsciiOnly));
                                expr = methCallExpression;
                            }

                            BuildAddParsedSubObjectStatement(buildSubControlBlock, expr, linePragma, ctrlRefExpr, ref gotParserVariable);
                        }
                    }
                }
            }

            // Process the complex attributes
            if (builder.ComplexPropertyEntries.Count > 0) {

                // Used to deal with the device filter conditionals
                CodeStatementCollection currentStmts;
                CodeStatementCollection nextStmts = statements;
                PropertyEntry previous = null;
                int localVarIndex = 1;
                String localVariableRef = null;

                foreach (ComplexPropertyEntry pseSub in builder.ComplexPropertyEntries) {

                    currentStmts = nextStmts;

                    HandleDeviceFilterConditional(ref previous, pseSub, statements, ref currentStmts, out nextStmts);

                    if (pseSub.Builder is StringPropertyBuilder) {
                        // If it's a string inner property, treat it like a simple property
                        CodeExpression leftExpr, rightExpr = null;

                        // __ctrl.{{_name}}
                        // In case of a string property, there should only be one property name (unlike complex properties)
                        Debug.Assert(pseSub.Name.IndexOf('.') < 0, "pseSub._name.IndexOf('.') < 0");
                        leftExpr = new CodePropertyReferenceExpression(ctrlRefExpr, pseSub.Name);

                        // We need to call BuildStringPropertyExpression so any additional processing can be done
                        rightExpr = BuildStringPropertyExpression(pseSub);

                        // Now that we have both side, add the assignment
                        CodeAssignStatement setStatment = new CodeAssignStatement(leftExpr, rightExpr);
                        setStatment.LinePragma = linePragma;
                        currentStmts.Add(setStatment);

                        continue;
                    }

                    if (pseSub.ReadOnly) {

                        if (fControlSkin && pseSub.Builder != null && pseSub.Builder is CollectionBuilder &&
                        pseSub.Builder.ComplexPropertyEntries.Count > 0) {

                            // If it's a collection on a control theme and the themed collection is not empty, clear it first.
                            // e.g. __ctrl.{{pse_name}}.Clear();

                            BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
                            // Look for the "Clear" method on the collection.
                            if (pseSub.Type.GetMethod("Clear", bindingFlags) != null) {
                                CodeMethodReferenceExpression refExpr = new CodeMethodReferenceExpression();
                                refExpr.MethodName = "Clear";
                                refExpr.TargetObject = new CodePropertyReferenceExpression(ctrlRefExpr, pseSub.Name);
                                CodeMethodInvokeExpression invokeClearExpr = new CodeMethodInvokeExpression();
                                invokeClearExpr.Method = refExpr;
                                currentStmts.Add(invokeClearExpr);
                            }
                        }

                        // If it's a readonly prop, pass it as a parameter to the
                        // build method.
                        // e.g. __BuildControl {{controlName}}(__ctrl.{{pse._name}});
                        methCallExpression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(),
                                                                          buildMethodPrefix + pseSub.Builder.ID);
                        methCallExpression.Parameters.Add(new CodePropertyReferenceExpression(ctrlRefExpr, pseSub.Name));
                        methCallStatement = new CodeExpressionStatement(methCallExpression);
                        methCallStatement.LinePragma = linePragma;
                        currentStmts.Add(methCallStatement);
                    }
                    else {
                        localVariableRef = _localVariableRef + (localVarIndex++).ToString(CultureInfo.InvariantCulture);

                        // e.g. {{controlTypeName}} ctrl4;
                        CodeTypeReference ctrlTypeReference =
                            CodeDomUtility.BuildGlobalCodeTypeReference(pseSub.Builder.ControlType);
                        currentStmts.Add(new CodeVariableDeclarationStatement(ctrlTypeReference, localVariableRef));

                        // Variable reference to the local control variable.
                        CodeVariableReferenceExpression childCtrlRefExpr = new CodeVariableReferenceExpression(localVariableRef);

                        methCallExpression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(),
                                                                          buildMethodPrefix + pseSub.Builder.ID);
                        methCallStatement = new CodeExpressionStatement(methCallExpression);

                        // e.g. ctrl4 = __BuildControl {{controlName}}();
                        CodeAssignStatement setCtl = new CodeAssignStatement(childCtrlRefExpr, methCallExpression);
                        setCtl.LinePragma = linePragma;
                        currentStmts.Add(setCtl);

                        if (pseSub.IsCollectionItem) {
                            // e.g. __ctrl.Add(ctrl4);
                            methCallExpression = new CodeMethodInvokeExpression(ctrlRefExpr, "Add");
                            methCallStatement = new CodeExpressionStatement(methCallExpression);
                            methCallStatement.LinePragma = linePragma;
                            currentStmts.Add(methCallStatement);
                            methCallExpression.Parameters.Add(childCtrlRefExpr);
                        }
                        else {
                            // e.g. __ctrl.{{pse._name}} = {{controlName}};
                            CodeAssignStatement set = new CodeAssignStatement();
                            set.Left = new CodePropertyReferenceExpression(ctrlRefExpr, pseSub.Name);
                            set.Right = childCtrlRefExpr;
                            set.LinePragma = linePragma;
                            currentStmts.Add(set);
                        }
                    }
                }
            }

            // If there are bound properties, hook up the binding method
            if (builder.BoundPropertyEntries.Count > 0) {

                bool isBindableTemplateBuilder = builder is BindableTemplateBuilder;
                bool hasDataBindingEntry = false;

                // Used to deal with the device filter conditionals
                CodeStatementCollection currentStmts;
                CodeStatementCollection methodStatements = statements;
                CodeStatementCollection nextStmts = statements;
                PropertyEntry previous = null;

                bool hasTempObject = false;

                foreach (BoundPropertyEntry entry in builder.BoundPropertyEntries) {

                    // Skip two-way entries if it's a BindableTemplateBuilder or the two-way entry has no setter
                    if (entry.TwoWayBound && (isBindableTemplateBuilder || entry.ReadOnlyProperty))
                        continue;

                    if (entry.IsDataBindingEntry) {
                        hasDataBindingEntry = true;
                        continue;
                    }

                    currentStmts = nextStmts;

                    HandleDeviceFilterConditional(ref previous, entry, statements, ref currentStmts, out nextStmts);

                    ExpressionBuilder eb = entry.ExpressionBuilder;
                    Debug.Assert(eb != null, "Did not expect null expression builder");
                    eb.BuildExpression(entry, builder, ctrlRefExpr, methodStatements, currentStmts, null, ref hasTempObject);
                }

                if (hasDataBindingEntry) {

                    EventInfo eventInfo = DataBindingExpressionBuilder.Event;

                    // __ctrl.{EventName} += new EventHandler(this.{{bindingMethod}})
                    CodeDelegateCreateExpression newDelegate = new CodeDelegateCreateExpression();
                    CodeAttachEventStatement attachEvent = new CodeAttachEventStatement(ctrlRefExpr, eventInfo.Name, newDelegate);
                    attachEvent.LinePragma = linePragma;
                    newDelegate.DelegateType = new CodeTypeReference(typeof(EventHandler));
                    newDelegate.TargetObject = new CodeThisReferenceExpression();
                    newDelegate.MethodName = GetExpressionBuilderMethodName(eventInfo.Name, builder);
                    statements.Add(attachEvent);
                }
            }

            if (builder is DataBoundLiteralControlBuilder) {

                // __ctrl.DataBinding += new EventHandler(this.{{bindingMethod}})
                CodeDelegateCreateExpression newDelegate = new CodeDelegateCreateExpression();
                CodeAttachEventStatement attachEvent = new CodeAttachEventStatement(ctrlRefExpr, "DataBinding", newDelegate);
                attachEvent.LinePragma = linePragma;
                newDelegate.DelegateType = new CodeTypeReference(typeof(EventHandler));
                newDelegate.TargetObject = new CodeThisReferenceExpression();
                newDelegate.MethodName = BindingMethodName(builder);
                statements.Add(attachEvent);
            }

            // If there is any ASP code, set the render method delegate
            if (builder.HasAspCode && !fControlSkin) {
                // e.g. __ctrl.SetRenderMethodDelegate(new RenderMethod(this.__Render {{controlName}}));
                CodeDelegateCreateExpression newDelegate = new CodeDelegateCreateExpression();
                newDelegate.DelegateType = new CodeTypeReference(typeof(RenderMethod));
                newDelegate.TargetObject = new CodeThisReferenceExpression();
                newDelegate.MethodName = "__Render" + builder.ID;

                methCallExpression = new CodeMethodInvokeExpression(ctrlRefExpr, "SetRenderMethodDelegate");
                methCallExpression.Parameters.Add(newDelegate);
                methCallStatement = new CodeExpressionStatement(methCallExpression);

                // VSWhidbey 579101
                // If this is a contentPlaceHolder, we need to check if there is any content defined.
                // We set the render method only when there is no contentTemplate defined.
                // if ((this.__Template_TestTemplate == null)) {
                //     __ctrl.SetRenderMethodDelegate(new RenderMethod(this.__Render {{controlName}}));
                // }
                if (builder is System.Web.UI.WebControls.ContentPlaceHolderBuilder) {
                    string templateName = ((System.Web.UI.WebControls.ContentPlaceHolderBuilder)builder).Name;
                    autoTemplateName = MasterPageControlBuilder.AutoTemplatePrefix + templateName;
                    string fieldName = "__" + autoTemplateName;
                    CodeExpression templateFieldRef = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName);
                    templateIfStmt = new CodeConditionStatement();
                    templateIfStmt.Condition = new CodeBinaryOperatorExpression(templateFieldRef, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null));
                    templateIfStmt.TrueStatements.Add(methCallStatement);
                    statements.Add(templateIfStmt);
                }
                else {
                    statements.Add(methCallStatement);
                }
            }

            // Process the events
            if (builder.EventEntries.Count > 0) {

                foreach (EventEntry eventEntry in builder.EventEntries) {

                    // Attach the event.  Detach it first to avoid duplicates (see ASURT 42603),
                    // but only if there is codebehind
                    // 


                    // e.g. __ctrl.ServerClick -= new System.EventHandler(this.buttonClicked);
                    // e.g. __ctrl.ServerClick += new System.EventHandler(this.buttonClicked);
                    CodeDelegateCreateExpression newDelegate = new CodeDelegateCreateExpression();
                    newDelegate.DelegateType = new CodeTypeReference(eventEntry.HandlerType);
                    newDelegate.TargetObject = new CodeThisReferenceExpression();
                    newDelegate.MethodName = eventEntry.HandlerMethodName;

                    if (Parser.HasCodeBehind) {
                        CodeRemoveEventStatement detachEvent = new CodeRemoveEventStatement(ctrlRefExpr, eventEntry.Name, newDelegate);
                        detachEvent.LinePragma = linePragma;
                        statements.Add(detachEvent);
                    }

                    CodeAttachEventStatement attachEvent = new CodeAttachEventStatement(ctrlRefExpr, eventEntry.Name, newDelegate);
                    attachEvent.LinePragma = linePragma;
                    statements.Add(attachEvent);
                }
            }

            // If a control field is declared, we need to return it at the end of the method.
            if (fControlFieldDeclared)
                statements.Add(new CodeMethodReturnStatement(ctrlRefExpr));
        }
 private void BuildBuildMethodInternal(ControlBuilder builder, Type ctrlType, bool fInTemplate, bool topLevelControlInTemplate, PropertyEntry pse, CodeStatementCollection statements, bool fStandardControl, bool fControlFieldDeclared, string deviceFilter, bool fControlSkin)
 {
     CodeObjectCreateExpression expression;
     CodeExpressionStatement statement;
     CodeMethodInvokeExpression expression2;
     CodeExpression expression3;
     CodeLinePragma linePragma = base.CreateCodeLinePragma(builder);
     if (fControlSkin)
     {
         CodeCastExpression initExpression = new CodeCastExpression(builder.ControlType.FullName, new CodeArgumentReferenceExpression("ctrl"));
         statements.Add(new CodeVariableDeclarationStatement(builder.ControlType.FullName, "__ctrl", initExpression));
         expression3 = new CodeVariableReferenceExpression("__ctrl");
     }
     else if (!fControlFieldDeclared)
     {
         expression3 = new CodeArgumentReferenceExpression("__ctrl");
     }
     else
     {
         CodeTypeReference createType = CodeDomUtility.BuildGlobalCodeTypeReference(ctrlType);
         expression = new CodeObjectCreateExpression(createType, new CodeExpression[0]);
         ConstructorNeedsTagAttribute attribute = (ConstructorNeedsTagAttribute) TypeDescriptor.GetAttributes(ctrlType)[typeof(ConstructorNeedsTagAttribute)];
         if ((attribute != null) && attribute.NeedsTag)
         {
             expression.Parameters.Add(new CodePrimitiveExpression(builder.TagName));
         }
         DataBoundLiteralControlBuilder builder2 = builder as DataBoundLiteralControlBuilder;
         if (builder2 != null)
         {
             expression.Parameters.Add(new CodePrimitiveExpression(builder2.GetStaticLiteralsCount()));
             expression.Parameters.Add(new CodePrimitiveExpression(builder2.GetDataBoundLiteralCount()));
         }
         statements.Add(new CodeVariableDeclarationStatement(createType, "__ctrl"));
         expression3 = new CodeVariableReferenceExpression("__ctrl");
         CodeAssignStatement statement2 = new CodeAssignStatement(expression3, expression) {
             LinePragma = linePragma
         };
         statements.Add(statement2);
         if (!builder.IsGeneratedID)
         {
             CodeFieldReferenceExpression left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), builder.ID);
             CodeAssignStatement statement3 = new CodeAssignStatement(left, expression3);
             statements.Add(statement3);
         }
         if (topLevelControlInTemplate && !typeof(TemplateControl).IsAssignableFrom(ctrlType))
         {
             statements.Add(this.BuildTemplatePropertyStatement(expression3));
         }
         if (fStandardControl)
         {
             if (builder.SkinID != null)
             {
                 CodeAssignStatement statement4 = new CodeAssignStatement {
                     Left = new CodePropertyReferenceExpression(expression3, "SkinID"),
                     Right = new CodePrimitiveExpression(builder.SkinID)
                 };
                 statements.Add(statement4);
             }
             if (ThemeableAttribute.IsTypeThemeable(ctrlType))
             {
                 CodeMethodInvokeExpression expression6 = new CodeMethodInvokeExpression(expression3, applyStyleSheetMethodName, new CodeExpression[0]);
                 expression6.Parameters.Add(this.BuildPagePropertyReferenceExpression());
                 statements.Add(expression6);
             }
         }
     }
     if (builder.TemplatePropertyEntries.Count > 0)
     {
         CodeStatementCollection nextStmts = statements;
         PropertyEntry previous = null;
         foreach (TemplatePropertyEntry entry2 in builder.TemplatePropertyEntries)
         {
             CodeStatementCollection currentStmts = nextStmts;
             this.HandleDeviceFilterConditional(ref previous, entry2, statements, ref currentStmts, out nextStmts);
             string iD = entry2.Builder.ID;
             CodeDelegateCreateExpression expression7 = new CodeDelegateCreateExpression {
                 DelegateType = new CodeTypeReference(typeof(BuildTemplateMethod)),
                 TargetObject = new CodeThisReferenceExpression(),
                 MethodName = buildMethodPrefix + iD
             };
             CodeAssignStatement statement5 = new CodeAssignStatement();
             if (entry2.PropertyInfo != null)
             {
                 statement5.Left = new CodePropertyReferenceExpression(expression3, entry2.Name);
             }
             else
             {
                 statement5.Left = new CodeFieldReferenceExpression(expression3, entry2.Name);
             }
             if (entry2.BindableTemplate)
             {
                 CodeExpression expression8;
                 if (entry2.Builder.HasTwoWayBoundProperties)
                 {
                     expression8 = new CodeDelegateCreateExpression();
                     ((CodeDelegateCreateExpression) expression8).DelegateType = new CodeTypeReference(typeof(ExtractTemplateValuesMethod));
                     ((CodeDelegateCreateExpression) expression8).TargetObject = new CodeThisReferenceExpression();
                     ((CodeDelegateCreateExpression) expression8).MethodName = extractTemplateValuesMethodPrefix + iD;
                 }
                 else
                 {
                     expression8 = new CodePrimitiveExpression(null);
                 }
                 expression = new CodeObjectCreateExpression(typeof(CompiledBindableTemplateBuilder), new CodeExpression[0]);
                 expression.Parameters.Add(expression7);
                 expression.Parameters.Add(expression8);
             }
             else
             {
                 expression = new CodeObjectCreateExpression(typeof(CompiledTemplateBuilder), new CodeExpression[0]);
                 expression.Parameters.Add(expression7);
             }
             statement5.Right = expression;
             statement5.LinePragma = base.CreateCodeLinePragma(entry2.Builder);
             currentStmts.Add(statement5);
         }
     }
     if ((typeof(UserControl).IsAssignableFrom(ctrlType) && fControlFieldDeclared) && !fControlSkin)
     {
         expression2 = new CodeMethodInvokeExpression(expression3, "InitializeAsUserControl", new CodeExpression[0]);
         expression2.Parameters.Add(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), pagePropertyName));
         statement = new CodeExpressionStatement(expression2) {
             LinePragma = linePragma
         };
         statements.Add(statement);
     }
     if (builder.SimplePropertyEntries.Count > 0)
     {
         CodeStatementCollection statements5 = statements;
         PropertyEntry entry3 = null;
         foreach (SimplePropertyEntry entry4 in builder.SimplePropertyEntries)
         {
             CodeStatementCollection statements4 = statements5;
             this.HandleDeviceFilterConditional(ref entry3, entry4, statements, ref statements4, out statements5);
             CodeStatement codeStatement = entry4.GetCodeStatement(this, expression3);
             codeStatement.LinePragma = linePragma;
             statements4.Add(codeStatement);
         }
     }
     if (typeof(Page).IsAssignableFrom(ctrlType) && !fControlSkin)
     {
         expression2 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InitializeCulture", new CodeExpression[0]);
         statement = new CodeExpressionStatement(expression2) {
             LinePragma = linePragma
         };
         statements.Add(statement);
     }
     CodeMethodInvokeExpression expression9 = null;
     CodeConditionStatement statement7 = null;
     CodeStatementCollection falseStatements = statements;
     string propName = null;
     if (builder is ContentPlaceHolderBuilder)
     {
         string name = ((ContentPlaceHolderBuilder) builder).Name;
         propName = MasterPageControlBuilder.AutoTemplatePrefix + name;
         string fieldName = "__" + propName;
         Type bindingContainerType = builder.BindingContainerType;
         if (!typeof(INamingContainer).IsAssignableFrom(bindingContainerType))
         {
             if (typeof(INamingContainer).IsAssignableFrom(this.Parser.BaseType))
             {
                 bindingContainerType = this.Parser.BaseType;
             }
             else
             {
                 bindingContainerType = typeof(Control);
             }
         }
         CodeAttributeDeclarationCollection attrDeclarations = new CodeAttributeDeclarationCollection();
         CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("TemplateContainer", new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeTypeOfExpression(bindingContainerType)) });
         attrDeclarations.Add(declaration);
         if (!fInTemplate)
         {
             CodeAttributeDeclaration declaration2 = new CodeAttributeDeclaration("TemplateInstanceAttribute", new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(TemplateInstance)), "Single")) });
             attrDeclarations.Add(declaration2);
         }
         base.BuildFieldAndAccessorProperty(propName, fieldName, typeof(ITemplate), false, attrDeclarations);
         CodeExpression expression10 = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName);
         if (builder is ContentPlaceHolderBuilder)
         {
             CodePropertyReferenceExpression targetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ContentTemplates");
             CodeAssignStatement statement8 = new CodeAssignStatement {
                 Left = expression10,
                 Right = new CodeCastExpression(typeof(ITemplate), new CodeIndexerExpression(targetObject, new CodeExpression[] { new CodePrimitiveExpression(name) }))
             };
             CodeConditionStatement statement9 = new CodeConditionStatement();
             CodeBinaryOperatorExpression expression12 = new CodeBinaryOperatorExpression(targetObject, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
             CodeMethodInvokeExpression expression13 = new CodeMethodInvokeExpression(targetObject, "Remove", new CodeExpression[0]);
             expression13.Parameters.Add(new CodePrimitiveExpression(name));
             statement9.Condition = expression12;
             statement9.TrueStatements.Add(statement8);
             statements.Add(statement9);
         }
         if (MultiTargetingUtil.IsTargetFramework40OrAbove)
         {
             expression9 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InstantiateInContentPlaceHolder", new CodeExpression[0]);
             expression9.Parameters.Add(expression3);
             expression9.Parameters.Add(expression10);
         }
         else
         {
             expression9 = new CodeMethodInvokeExpression(expression10, "InstantiateIn", new CodeExpression[0]);
             expression9.Parameters.Add(expression3);
         }
         statement7 = new CodeConditionStatement {
             Condition = new CodeBinaryOperatorExpression(expression10, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null))
         };
         statement7.TrueStatements.Add(new CodeExpressionStatement(expression9));
         falseStatements = statement7.FalseStatements;
         statements.Add(statement7);
     }
     ICollection contentBuilderEntries = null;
     if (builder is FileLevelPageControlBuilder)
     {
         contentBuilderEntries = ((FileLevelPageControlBuilder) builder).ContentBuilderEntries;
         if (contentBuilderEntries != null)
         {
             CodeStatementCollection statements8 = statements;
             PropertyEntry entry5 = null;
             foreach (TemplatePropertyEntry entry6 in contentBuilderEntries)
             {
                 ContentBuilderInternal internal2 = (ContentBuilderInternal) entry6.Builder;
                 CodeStatementCollection statements7 = statements8;
                 this.HandleDeviceFilterConditional(ref entry5, entry6, statements, ref statements7, out statements8);
                 string str5 = internal2.ID;
                 string contentPlaceHolder = internal2.ContentPlaceHolder;
                 CodeDelegateCreateExpression expression14 = new CodeDelegateCreateExpression {
                     DelegateType = new CodeTypeReference(typeof(BuildTemplateMethod)),
                     TargetObject = new CodeThisReferenceExpression(),
                     MethodName = buildMethodPrefix + str5
                 };
                 CodeObjectCreateExpression expression15 = new CodeObjectCreateExpression(typeof(CompiledTemplateBuilder), new CodeExpression[0]);
                 expression15.Parameters.Add(expression14);
                 CodeMethodInvokeExpression expression16 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "AddContentTemplate", new CodeExpression[0]);
                 expression16.Parameters.Add(new CodePrimitiveExpression(contentPlaceHolder));
                 expression16.Parameters.Add(expression15);
                 CodeExpressionStatement statement10 = new CodeExpressionStatement(expression16) {
                     LinePragma = base.CreateCodeLinePragma(internal2)
                 };
                 statements7.Add(statement10);
             }
         }
     }
     if (builder is DataBoundLiteralControlBuilder)
     {
         int num = -1;
         foreach (object obj2 in builder.SubBuilders)
         {
             num++;
             if ((obj2 != null) && ((num % 2) != 1))
             {
                 string str7 = (string) obj2;
                 expression2 = new CodeMethodInvokeExpression(expression3, "SetStaticString", new CodeExpression[0]);
                 expression2.Parameters.Add(new CodePrimitiveExpression(num / 2));
                 expression2.Parameters.Add(new CodePrimitiveExpression(str7));
                 statements.Add(new CodeExpressionStatement(expression2));
             }
         }
     }
     else if (builder.SubBuilders != null)
     {
         bool gotParserVariable = false;
         int num2 = 1;
         foreach (object obj3 in builder.SubBuilders)
         {
             if (((obj3 is ControlBuilder) && !(obj3 is CodeBlockBuilder)) && !(obj3 is ContentBuilderInternal))
             {
                 ControlBuilder builder3 = (ControlBuilder) obj3;
                 if (fControlSkin)
                 {
                     throw new HttpParseException(System.Web.SR.GetString("ControlSkin_cannot_contain_controls"), null, builder.VirtualPath, null, builder.Line);
                 }
                 PartialCachingAttribute attribute2 = (PartialCachingAttribute) TypeDescriptor.GetAttributes(builder3.ControlType)[typeof(PartialCachingAttribute)];
                 expression2 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), buildMethodPrefix + builder3.ID, new CodeExpression[0]);
                 statement = new CodeExpressionStatement(expression2);
                 if (attribute2 == null)
                 {
                     int num6 = num2++;
                     string variableName = "__ctrl" + num6.ToString(CultureInfo.InvariantCulture);
                     CodeVariableReferenceExpression expression17 = new CodeVariableReferenceExpression(variableName);
                     CodeTypeReference type = CodeDomUtility.BuildGlobalCodeTypeReference(builder3.ControlType);
                     falseStatements.Add(new CodeVariableDeclarationStatement(type, variableName));
                     CodeAssignStatement statement11 = new CodeAssignStatement(expression17, expression2) {
                         LinePragma = linePragma
                     };
                     falseStatements.Add(statement11);
                     BuildAddParsedSubObjectStatement(falseStatements, expression17, linePragma, expression3, ref gotParserVariable);
                 }
                 else
                 {
                     string providerName = null;
                     bool flag2 = MultiTargetingUtil.IsTargetFramework40OrAbove;
                     if (flag2)
                     {
                         providerName = attribute2.ProviderName;
                         if (providerName == "AspNetInternalProvider")
                         {
                             providerName = null;
                         }
                     }
                     CodeMethodInvokeExpression expression18 = new CodeMethodInvokeExpression {
                         Method = { TargetObject = new CodeTypeReferenceExpression(typeof(StaticPartialCachingControl)), MethodName = "BuildCachedControl" }
                     };
                     expression18.Parameters.Add(expression3);
                     expression18.Parameters.Add(new CodePrimitiveExpression(builder3.ID));
                     if (attribute2.Shared)
                     {
                         expression18.Parameters.Add(new CodePrimitiveExpression(builder3.ControlType.GetHashCode().ToString(CultureInfo.InvariantCulture)));
                     }
                     else
                     {
                         expression18.Parameters.Add(new CodePrimitiveExpression(Guid.NewGuid().ToString()));
                     }
                     expression18.Parameters.Add(new CodePrimitiveExpression(attribute2.Duration));
                     expression18.Parameters.Add(new CodePrimitiveExpression(attribute2.VaryByParams));
                     expression18.Parameters.Add(new CodePrimitiveExpression(attribute2.VaryByControls));
                     expression18.Parameters.Add(new CodePrimitiveExpression(attribute2.VaryByCustom));
                     expression18.Parameters.Add(new CodePrimitiveExpression(attribute2.SqlDependency));
                     CodeDelegateCreateExpression expression19 = new CodeDelegateCreateExpression {
                         DelegateType = new CodeTypeReference(typeof(BuildMethod)),
                         TargetObject = new CodeThisReferenceExpression(),
                         MethodName = buildMethodPrefix + builder3.ID
                     };
                     expression18.Parameters.Add(expression19);
                     if (flag2)
                     {
                         expression18.Parameters.Add(new CodePrimitiveExpression(providerName));
                     }
                     falseStatements.Add(new CodeExpressionStatement(expression18));
                 }
             }
             else if (((obj3 is string) && !builder.HasAspCode) && (!fControlSkin || !builder.AllowWhitespaceLiterals()))
             {
                 CodeExpression expression20;
                 string s = (string) obj3;
                 if (!this.UseResourceLiteralString(s))
                 {
                     expression = new CodeObjectCreateExpression(typeof(LiteralControl), new CodeExpression[0]);
                     expression.Parameters.Add(new CodePrimitiveExpression(s));
                     expression20 = expression;
                 }
                 else
                 {
                     int num3;
                     int num4;
                     bool flag3;
                     base._stringResourceBuilder.AddString(s, out num3, out num4, out flag3);
                     expression2 = new CodeMethodInvokeExpression {
                         Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "CreateResourceBasedLiteralControl" }
                     };
                     expression2.Parameters.Add(new CodePrimitiveExpression(num3));
                     expression2.Parameters.Add(new CodePrimitiveExpression(num4));
                     expression2.Parameters.Add(new CodePrimitiveExpression(flag3));
                     expression20 = expression2;
                 }
                 BuildAddParsedSubObjectStatement(falseStatements, expression20, linePragma, expression3, ref gotParserVariable);
             }
         }
     }
     if (builder.ComplexPropertyEntries.Count > 0)
     {
         CodeStatementCollection statements10 = statements;
         PropertyEntry entry7 = null;
         int num5 = 1;
         string str11 = null;
         foreach (ComplexPropertyEntry entry8 in builder.ComplexPropertyEntries)
         {
             CodeStatementCollection statements9 = statements10;
             this.HandleDeviceFilterConditional(ref entry7, entry8, statements, ref statements9, out statements10);
             if (entry8.Builder is StringPropertyBuilder)
             {
                 CodeExpression right = null;
                 CodeExpression expression21 = new CodePropertyReferenceExpression(expression3, entry8.Name);
                 right = this.BuildStringPropertyExpression(entry8);
                 CodeAssignStatement statement12 = new CodeAssignStatement(expression21, right) {
                     LinePragma = linePragma
                 };
                 statements9.Add(statement12);
             }
             else if (entry8.ReadOnly)
             {
                 if ((fControlSkin && (entry8.Builder != null)) && ((entry8.Builder is CollectionBuilder) && (entry8.Builder.ComplexPropertyEntries.Count > 0)))
                 {
                     BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance;
                     if (entry8.Type.GetMethod("Clear", bindingAttr) != null)
                     {
                         CodeMethodReferenceExpression expression23 = new CodeMethodReferenceExpression {
                             MethodName = "Clear",
                             TargetObject = new CodePropertyReferenceExpression(expression3, entry8.Name)
                         };
                         CodeMethodInvokeExpression expression24 = new CodeMethodInvokeExpression {
                             Method = expression23
                         };
                         statements9.Add(expression24);
                     }
                 }
                 expression2 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), buildMethodPrefix + entry8.Builder.ID, new CodeExpression[0]);
                 expression2.Parameters.Add(new CodePropertyReferenceExpression(expression3, entry8.Name));
                 statement = new CodeExpressionStatement(expression2) {
                     LinePragma = linePragma
                 };
                 statements9.Add(statement);
             }
             else
             {
                 str11 = "__ctrl" + num5++.ToString(CultureInfo.InvariantCulture);
                 CodeTypeReference reference3 = CodeDomUtility.BuildGlobalCodeTypeReference(entry8.Builder.ControlType);
                 statements9.Add(new CodeVariableDeclarationStatement(reference3, str11));
                 CodeVariableReferenceExpression expression25 = new CodeVariableReferenceExpression(str11);
                 expression2 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), buildMethodPrefix + entry8.Builder.ID, new CodeExpression[0]);
                 statement = new CodeExpressionStatement(expression2);
                 CodeAssignStatement statement13 = new CodeAssignStatement(expression25, expression2) {
                     LinePragma = linePragma
                 };
                 statements9.Add(statement13);
                 if (entry8.IsCollectionItem)
                 {
                     expression2 = new CodeMethodInvokeExpression(expression3, "Add", new CodeExpression[0]);
                     statement = new CodeExpressionStatement(expression2) {
                         LinePragma = linePragma
                     };
                     statements9.Add(statement);
                     expression2.Parameters.Add(expression25);
                 }
                 else
                 {
                     CodeAssignStatement statement14 = new CodeAssignStatement {
                         Left = new CodePropertyReferenceExpression(expression3, entry8.Name),
                         Right = expression25,
                         LinePragma = linePragma
                     };
                     statements9.Add(statement14);
                 }
             }
         }
     }
     if (builder.BoundPropertyEntries.Count > 0)
     {
         bool flag4 = builder is BindableTemplateBuilder;
         bool flag5 = false;
         CodeStatementCollection methodStatements = statements;
         CodeStatementCollection statements13 = statements;
         PropertyEntry entry9 = null;
         bool hasTempObject = false;
         foreach (BoundPropertyEntry entry10 in builder.BoundPropertyEntries)
         {
             if (!entry10.TwoWayBound || (!flag4 && !entry10.ReadOnlyProperty))
             {
                 if (entry10.IsDataBindingEntry)
                 {
                     flag5 = true;
                 }
                 else
                 {
                     CodeStatementCollection statements11 = statements13;
                     this.HandleDeviceFilterConditional(ref entry9, entry10, statements, ref statements11, out statements13);
                     entry10.ExpressionBuilder.BuildExpression(entry10, builder, expression3, methodStatements, statements11, null, ref hasTempObject);
                 }
             }
         }
         if (flag5)
         {
             EventInfo info = DataBindingExpressionBuilder.Event;
             CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression();
             CodeAttachEventStatement statement15 = new CodeAttachEventStatement(expression3, info.Name, listener) {
                 LinePragma = linePragma
             };
             listener.DelegateType = new CodeTypeReference(typeof(EventHandler));
             listener.TargetObject = new CodeThisReferenceExpression();
             listener.MethodName = this.GetExpressionBuilderMethodName(info.Name, builder);
             statements.Add(statement15);
         }
     }
     if (builder is DataBoundLiteralControlBuilder)
     {
         CodeDelegateCreateExpression expression27 = new CodeDelegateCreateExpression();
         CodeAttachEventStatement statement16 = new CodeAttachEventStatement(expression3, "DataBinding", expression27) {
             LinePragma = linePragma
         };
         expression27.DelegateType = new CodeTypeReference(typeof(EventHandler));
         expression27.TargetObject = new CodeThisReferenceExpression();
         expression27.MethodName = this.BindingMethodName(builder);
         statements.Add(statement16);
     }
     if (builder.HasAspCode && !fControlSkin)
     {
         CodeDelegateCreateExpression expression28 = new CodeDelegateCreateExpression {
             DelegateType = new CodeTypeReference(typeof(RenderMethod)),
             TargetObject = new CodeThisReferenceExpression(),
             MethodName = "__Render" + builder.ID
         };
         expression2 = new CodeMethodInvokeExpression(expression3, "SetRenderMethodDelegate", new CodeExpression[0]);
         expression2.Parameters.Add(expression28);
         statement = new CodeExpressionStatement(expression2);
         if (builder is ContentPlaceHolderBuilder)
         {
             string str12 = ((ContentPlaceHolderBuilder) builder).Name;
             propName = MasterPageControlBuilder.AutoTemplatePrefix + str12;
             string str13 = "__" + propName;
             CodeExpression expression29 = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), str13);
             statement7 = new CodeConditionStatement {
                 Condition = new CodeBinaryOperatorExpression(expression29, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null))
             };
             statement7.TrueStatements.Add(statement);
             statements.Add(statement7);
         }
         else
         {
             statements.Add(statement);
         }
     }
     if (builder.EventEntries.Count > 0)
     {
         foreach (EventEntry entry11 in builder.EventEntries)
         {
             CodeDelegateCreateExpression expression30 = new CodeDelegateCreateExpression {
                 DelegateType = new CodeTypeReference(entry11.HandlerType),
                 TargetObject = new CodeThisReferenceExpression(),
                 MethodName = entry11.HandlerMethodName
             };
             if (this.Parser.HasCodeBehind)
             {
                 CodeRemoveEventStatement statement17 = new CodeRemoveEventStatement(expression3, entry11.Name, expression30) {
                     LinePragma = linePragma
                 };
                 statements.Add(statement17);
             }
             CodeAttachEventStatement statement18 = new CodeAttachEventStatement(expression3, entry11.Name, expression30) {
                 LinePragma = linePragma
             };
             statements.Add(statement18);
         }
     }
     if (fControlFieldDeclared)
     {
         statements.Add(new CodeMethodReturnStatement(expression3));
     }
 }