private void AddPropertyEntry(PropertyEntry entry) { if ((this._isCollection && (entry is ComplexPropertyEntry)) && ((ComplexPropertyEntry) entry).IsCollectionItem) { this._collectionItems.Add(entry); } else { IDictionary dictionary = (IDictionary) this._propertyTableByFilter[entry.Filter]; if (dictionary == null) { dictionary = new HybridDictionary(true); this._propertyTableByFilter[entry.Filter] = dictionary; } dictionary[entry.Name] = entry; ArrayList list = (ArrayList) this._propertyTableByProperty[entry.Name]; if (list == null) { list = new ArrayList(); this._propertyTableByProperty[entry.Name] = list; } list.Add(entry); } this._allPropertyEntries.Add(entry); }
/// <devdoc> /// /// </devdoc> private void AddEntry(ArrayList entries, PropertyEntry entry) { // Only allow setting the ID property of a control using a simple property (e.g. ID="Button1"). // This restricts the user from using databinding, expressions, implicit expressions, // or inner string properties to set the ID. if (String.Equals(entry.Name, "ID", StringComparison.OrdinalIgnoreCase) && flags[controlTypeIsControl] && !(entry is SimplePropertyEntry)) { throw new HttpException(SR.GetString(SR.ControlBuilder_IDMustUseAttribute)); } // Remember the item index to perform a stable sort. entry.Index = entries.Count; // We used to sort the entries here via an insertion-type sort // But it's faster just to sort before we use the entries. entries.Add(entry); }
internal override CodeExpression BuildStringPropertyExpression(PropertyEntry pse) { // Make the UrlProperty based on virtualDirPath for control themes. if (pse.PropertyInfo != null) { UrlPropertyAttribute urlAttrib = Attribute.GetCustomAttribute(pse.PropertyInfo, typeof(UrlPropertyAttribute)) as UrlPropertyAttribute; if (urlAttrib != null) { if (pse is SimplePropertyEntry) { SimplePropertyEntry spse = (SimplePropertyEntry)pse; string strValue = (string)spse.Value; if (UrlPath.IsRelativeUrl(strValue) && !UrlPath.IsAppRelativePath(strValue)) { spse.Value = UrlPath.MakeVirtualPathAppRelative(UrlPath.Combine(_themeParser.VirtualDirPath.VirtualPathString, strValue)); } } else { Debug.Assert(pse is ComplexPropertyEntry); ComplexPropertyEntry cpe = (ComplexPropertyEntry)pse; StringPropertyBuilder builder = (StringPropertyBuilder)cpe.Builder; string strValue = (string)builder.BuildObject(); if (UrlPath.IsRelativeUrl(strValue) && !UrlPath.IsAppRelativePath(strValue)) { cpe.Builder = new StringPropertyBuilder(UrlPath.MakeVirtualPathAppRelative(UrlPath.Combine(_themeParser.VirtualDirPath.VirtualPathString, strValue))); } } } } return base.BuildStringPropertyExpression(pse); }
protected override void BuildSourceDataTreeFromBuilder(ControlBuilder builder, bool fInTemplate, bool topLevelControlInTemplate, PropertyEntry pse) { // Don't do anything for code blocks if (builder is CodeBlockBuilder) return; // Is the current builder for a template? bool fTemplate = (builder is TemplateBuilder); // Is the current builder the root builder? bool fRootBuilder = (builder == _themeParser.RootBuilder); // Is this a control theme? bool fControlSkin = !fInTemplate && !fTemplate && topLevelControlInTemplate; // Ignore the ID attribute, always auto generate ID. _controlCount++; builder.ID = "__control" + _controlCount.ToString(NumberFormatInfo.InvariantInfo); builder.IsGeneratedID = true; // Check for the SkinID property. if (fControlSkin && !(builder is DataBoundLiteralControlBuilder)) { Type ctrlType = builder.ControlType; Debug.Assert(typeof(Control).IsAssignableFrom(ctrlType)); Debug.Assert(ThemeableAttribute.IsTypeThemeable(ctrlType)); string skinID = builder.SkinID; object skinKey = PageTheme.CreateSkinKey(builder.ControlType, skinID); if (_controlSkinTypeNameCollection.Contains(skinKey)) { if (String.IsNullOrEmpty(skinID)) { throw new HttpParseException(SR.GetString(SR.Page_theme_default_theme_already_defined, builder.ControlType.FullName), null, builder.VirtualPath, null, builder.Line); } else { throw new HttpParseException(SR.GetString(SR.Page_theme_skinID_already_defined, skinID), null, builder.VirtualPath, null, builder.Line); } } _controlSkinTypeNameCollection.Add(skinKey, true); _controlSkinBuilderEntryList.Add(new ControlSkinBuilderEntry(builder, skinID)); } // Process the children // only root builders and template builders are processed. if (builder.SubBuilders != null) { foreach (object child in builder.SubBuilders) { if (child is ControlBuilder) { bool isTopLevelCtrlInTemplate = fTemplate && typeof(Control).IsAssignableFrom(((ControlBuilder)child).ControlType); BuildSourceDataTreeFromBuilder((ControlBuilder)child, fInTemplate, isTopLevelCtrlInTemplate, null); } } } foreach (TemplatePropertyEntry entry in builder.TemplatePropertyEntries) { BuildSourceDataTreeFromBuilder(((TemplatePropertyEntry)entry).Builder, true, false /*topLevelControlInTemplate*/, entry); } foreach (ComplexPropertyEntry entry in builder.ComplexPropertyEntries) { if (!(entry.Builder is StringPropertyBuilder)) { BuildSourceDataTreeFromBuilder(((ComplexPropertyEntry)entry).Builder, fInTemplate, false /*topLevelControlInTemplate*/, entry); } } // Build a Build method for the control // fControlSkin indicates whether the method is a theme build method. if (!fRootBuilder) { BuildBuildMethod(builder, fTemplate, fInTemplate, topLevelControlInTemplate, pse, fControlSkin); } // Build a Render method for the control, unless it has no code if (!fControlSkin && builder.HasAspCode) { BuildRenderMethod(builder, fTemplate); } // Build a method to extract values from the template BuildExtractMethod(builder); // Build a property binding method for the control BuildPropertyBindingMethod(builder, fControlSkin); }
/// <devdoc> /// Adds a property to this persistence data, adding it to all necessary /// data structures. /// </devdoc> private void AddPropertyEntry(PropertyEntry entry) { if (_isCollection && (entry is ComplexPropertyEntry && ((ComplexPropertyEntry)entry).IsCollectionItem)) { _collectionItems.Add(entry); } else { IDictionary filteredProperties = (IDictionary)_propertyTableByFilter[entry.Filter]; if (filteredProperties == null) { filteredProperties = new HybridDictionary(true); _propertyTableByFilter[entry.Filter] = filteredProperties; } Debug.Assert((entry.Name != null) && (entry.Name.Length > 0)); filteredProperties[entry.Name] = entry; ArrayList properties = (ArrayList)_propertyTableByProperty[entry.Name]; if (properties == null) { properties = new ArrayList(); _propertyTableByProperty[entry.Name] = properties; } properties.Add(entry); } _allPropertyEntries.Add(entry); }
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)); }
/* * Helper method to generate the device filter conditionals. e.g. * if (this.TestDeviceFilter("FilterName")) { * // ... * } * else { * // ... * } */ private void HandleDeviceFilterConditional( ref PropertyEntry previous, PropertyEntry current, CodeStatementCollection topStmts, ref CodeStatementCollection currentStmts, out CodeStatementCollection nextStmts) { bool sameAsPrevious = (previous != null) && StringUtil.EqualsIgnoreCase(previous.Name, current.Name); if (current.Filter.Length != 0) { if (!sameAsPrevious) { // If the current property entry is not the same as the previous entries, // we need to start a new block of code currentStmts = topStmts; previous = null; } CodeConditionStatement ifStmt = new CodeConditionStatement(); CodeMethodInvokeExpression methCallExpression = new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "TestDeviceFilter"); methCallExpression.Parameters.Add(new CodePrimitiveExpression(current.Filter)); ifStmt.Condition = methCallExpression; currentStmts.Add(ifStmt); // The current entry needs to go in the 'if' clause currentStmts = ifStmt.TrueStatements; // The next entry will tentatively go in the 'else' clause, unless it is // for a different property (which we would catch next time around) nextStmts = ifStmt.FalseStatements; previous = current; } else { // If we're switching to a new property, we need to add to the top-level statements (not the false block of an if) if (!sameAsPrevious) { currentStmts = topStmts; } nextStmts = topStmts; previous = null; } }
protected virtual void BuildSourceDataTreeFromBuilder(ControlBuilder builder, bool fInTemplate, bool topLevelControlInTemplate, PropertyEntry pse) { if (!(builder is CodeBlockBuilder)) { bool fTemplate = builder is TemplateBuilder; if ((builder.ID == null) || fInTemplate) { this._controlCount++; builder.ID = "__control" + this._controlCount.ToString(NumberFormatInfo.InvariantInfo); builder.IsGeneratedID = true; } if (builder.SubBuilders != null) { foreach (object obj2 in builder.SubBuilders) { if (obj2 is ControlBuilder) { bool flag2 = (fTemplate && typeof(Control).IsAssignableFrom(((ControlBuilder) obj2).ControlType)) && !(builder is RootBuilder); this.BuildSourceDataTreeFromBuilder((ControlBuilder) obj2, fInTemplate, flag2, null); } } } foreach (TemplatePropertyEntry entry in builder.TemplatePropertyEntries) { bool isMultiple = true; if (entry.PropertyInfo != null) { isMultiple = entry.IsMultiple; } this.BuildSourceDataTreeFromBuilder(entry.Builder, isMultiple, false, entry); } foreach (ComplexPropertyEntry entry2 in builder.ComplexPropertyEntries) { if (!(entry2.Builder is StringPropertyBuilder)) { this.BuildSourceDataTreeFromBuilder(entry2.Builder, fInTemplate, false, entry2); } } if (!builder.IsGeneratedID) { this.BuildFieldDeclaration(builder); } CodeMemberMethod buildMethod = null; CodeMemberMethod dataBindingMethod = null; if (base._sourceDataClass != null) { if (!base._designerMode) { buildMethod = this.BuildBuildMethod(builder, fTemplate, fInTemplate, topLevelControlInTemplate, pse, false); } if (builder.HasAspCode) { this.BuildRenderMethod(builder, fTemplate); } this.BuildExtractMethod(builder); dataBindingMethod = this.BuildPropertyBindingMethod(builder, false); } builder.ProcessGeneratedCode(base._codeCompileUnit, base._intermediateClass, base._sourceDataClass, buildMethod, dataBindingMethod); } }
protected virtual void BuildSourceDataTreeFromBuilder(ControlBuilder builder, bool fInTemplate, bool topLevelControlInTemplate, PropertyEntry pse) { // Don't do anything for Code blocks if (builder is CodeBlockBuilder || builder is CodeStatementBuilder) return; // Is the current builder for a template? bool fTemplate = (builder is TemplateBuilder); // For the control name in the compiled code, we use the // ID if one is available (but don't use the ID inside a template) // Otherwise, we generate a unique name. if (builder.ID == null || fInTemplate) { // Increase the control count to generate unique ID's _controlCount++; builder.ID = "__control" + _controlCount.ToString(NumberFormatInfo.InvariantInfo); builder.IsGeneratedID = true; } // Process the children if (builder.SubBuilders != null) { foreach (object child in builder.SubBuilders) { if (child is ControlBuilder) { // Do not treat it as top level control in template if the control is at top-level of a file. bool isTopLevelCtrlInTemplate = fTemplate && typeof(Control).IsAssignableFrom(((ControlBuilder)child).ControlType) && !(builder is RootBuilder); BuildSourceDataTreeFromBuilder((ControlBuilder)child, fInTemplate, isTopLevelCtrlInTemplate, null); } } } foreach (TemplatePropertyEntry entry in builder.TemplatePropertyEntries) { bool inTemplate = true; // If the template container does not allow multiple instances, // treat the controls as if not in templates. if (entry.PropertyInfo != null) { inTemplate = entry.IsMultiple; } BuildSourceDataTreeFromBuilder(((TemplatePropertyEntry)entry).Builder, inTemplate, false /*topLevelControlInTemplate*/, entry); } foreach (ComplexPropertyEntry entry in builder.ComplexPropertyEntries) { // Don't create a build method for inner property strings if (!(entry.Builder is StringPropertyBuilder)) { BuildSourceDataTreeFromBuilder(((ComplexPropertyEntry)entry).Builder, fInTemplate, false /*topLevelControlInTemplate*/, entry); } } // Build a field declaration for the control if ID is defined on the control. // (Not a generated ID) if (!builder.IsGeneratedID) BuildFieldDeclaration(builder); CodeMemberMethod buildMethod = null; CodeMemberMethod dataBindingMethod = null; // Skip the rest if we're only generating the intermediate class if (_sourceDataClass != null) { if (!_designerMode) { // Build a Build method for the control buildMethod = BuildBuildMethod(builder, fTemplate, fInTemplate, topLevelControlInTemplate, pse, false); } // Build a Render method for the control, unless it has no code if (builder.HasAspCode) { BuildRenderMethod(builder, fTemplate); } // Build a method to extract values from the template BuildExtractMethod(builder); // Build a property binding method for the control dataBindingMethod = BuildPropertyBindingMethod(builder, false); } // Give the ControlBuilder a chance to look at and modify the tree builder.ProcessGeneratedCode(_codeCompileUnit, _intermediateClass, _sourceDataClass, buildMethod, dataBindingMethod); if (Parser.ControlBuilderInterceptor != null) { Parser.ControlBuilderInterceptor.OnProcessGeneratedCode(builder, _codeCompileUnit, _intermediateClass, _sourceDataClass, buildMethod, dataBindingMethod, builder.AdditionalState); } // Give the ParseRecorder a chance to look at and modify the tree Parser.ParseRecorders.ProcessGeneratedCode(builder, _codeCompileUnit, _intermediateClass, _sourceDataClass, buildMethod, dataBindingMethod); }
/* * Build the data tree for a control's build method */ protected CodeMemberMethod BuildBuildMethod(ControlBuilder builder, bool fTemplate, bool fInTemplate, bool topLevelControlInTemplate, PropertyEntry pse, bool fControlSkin) { Debug.Assert(builder.ServiceProvider == null); ServiceContainer container = new ServiceContainer(); container.AddService(typeof(IFilterResolutionService), HttpCapabilitiesBase.EmptyHttpCapabilitiesBase); try { builder.SetServiceProvider(container); builder.EnsureEntriesSorted(); } finally { builder.SetServiceProvider(null); } string methodName = GetMethodNameForBuilder(buildMethodPrefix, builder); Type ctrlType = GetCtrlTypeForBuilder(builder, fTemplate); bool fStandardControl = false; bool fControlFieldDeclared = false; CodeMemberMethod method = new CodeMemberMethod(); AddDebuggerNonUserCodeAttribute(method); method.Name = methodName; method.Attributes = MemberAttributes.Private | MemberAttributes.Final; _sourceDataClass.Members.Add(method); // If it's for a template or a r/o complex prop, pass a parameter of the control's type ComplexPropertyEntry cpse = pse as ComplexPropertyEntry; if (fTemplate || (cpse != null && cpse.ReadOnly)) { if (builder is RootBuilder) method.Parameters.Add(new CodeParameterDeclarationExpression(_sourceDataClass.Name, "__ctrl")); else method.Parameters.Add(new CodeParameterDeclarationExpression(ctrlType, "__ctrl")); } else { // If it's a standard control, return it from the method if (typeof(Control).IsAssignableFrom(builder.ControlType)) { fStandardControl = true; } Debug.Assert(builder.ControlType != null); if (builder.ControlType != null) { if (fControlSkin) { // ReturnType needs to be of type Control in a skin file to match // the controlskin delegate. if (fStandardControl) { method.ReturnType = new CodeTypeReference(typeof(Control)); } } else { PartialCachingAttribute cacheAttrib = (PartialCachingAttribute) TypeDescriptor.GetAttributes(builder.ControlType)[typeof(PartialCachingAttribute)]; if (cacheAttrib != null) { method.ReturnType = new CodeTypeReference(typeof(Control)); } else { // Otherwise the return type is always the actual component type. method.ReturnType = CodeDomUtility.BuildGlobalCodeTypeReference(builder.ControlType); } } } // A control field declaration is required, this field will be returned // in the method. fControlFieldDeclared = true; } // Add a control parameter if it's a ControlSkin if (fControlSkin) { method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Control).FullName, "ctrl")); } BuildBuildMethodInternal(builder, builder.ControlType, fInTemplate, topLevelControlInTemplate, pse, method.Statements, fStandardControl, fControlFieldDeclared, null, fControlSkin); return method; }
private void AddEntry(ArrayList entries, PropertyEntry entry) { if ((string.Equals(entry.Name, "ID", StringComparison.OrdinalIgnoreCase) && this.flags[0x2000]) && !(entry is SimplePropertyEntry)) { throw new HttpException(System.Web.SR.GetString("ControlBuilder_IDMustUseAttribute")); } entry.Index = entries.Count; entries.Add(entry); }
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)); } }
private void HandleDeviceFilterConditional(ref PropertyEntry previous, PropertyEntry current, CodeStatementCollection topStmts, ref CodeStatementCollection currentStmts, out CodeStatementCollection nextStmts) { bool flag = (previous != null) && StringUtil.EqualsIgnoreCase(previous.Name, current.Name); if (current.Filter.Length != 0) { if (!flag) { currentStmts = topStmts; previous = null; } CodeConditionStatement statement = new CodeConditionStatement(); CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "TestDeviceFilter", new CodeExpression[0]); expression.Parameters.Add(new CodePrimitiveExpression(current.Filter)); statement.Condition = expression; currentStmts.Add(statement); currentStmts = statement.TrueStatements; nextStmts = statement.FalseStatements; previous = current; } else { if (!flag) { currentStmts = topStmts; } nextStmts = topStmts; previous = null; } }
internal virtual CodeExpression BuildStringPropertyExpression(PropertyEntry pse) { string str = string.Empty; if (pse is SimplePropertyEntry) { str = (string) ((SimplePropertyEntry) pse).Value; } else { ComplexPropertyEntry entry = (ComplexPropertyEntry) pse; str = (string) ((StringPropertyBuilder) entry.Builder).BuildObject(); } return CodeDomUtility.GenerateExpressionForValue(pse.PropertyInfo, str, typeof(string)); }
protected CodeMemberMethod BuildBuildMethod(ControlBuilder builder, bool fTemplate, bool fInTemplate, bool topLevelControlInTemplate, PropertyEntry pse, bool fControlSkin) { ServiceContainer serviceProvider = new ServiceContainer(); serviceProvider.AddService(typeof(IFilterResolutionService), HttpCapabilitiesBase.EmptyHttpCapabilitiesBase); try { builder.SetServiceProvider(serviceProvider); builder.EnsureEntriesSorted(); } finally { builder.SetServiceProvider(null); } string methodNameForBuilder = this.GetMethodNameForBuilder(buildMethodPrefix, builder); Type ctrlTypeForBuilder = this.GetCtrlTypeForBuilder(builder, fTemplate); bool fStandardControl = false; bool fControlFieldDeclared = false; CodeMemberMethod method = new CodeMemberMethod(); base.AddDebuggerNonUserCodeAttribute(method); method.Name = methodNameForBuilder; method.Attributes = MemberAttributes.Private | MemberAttributes.Final; base._sourceDataClass.Members.Add(method); ComplexPropertyEntry entry = pse as ComplexPropertyEntry; if (fTemplate || ((entry != null) && entry.ReadOnly)) { if (builder is RootBuilder) { method.Parameters.Add(new CodeParameterDeclarationExpression(base._sourceDataClass.Name, "__ctrl")); } else { method.Parameters.Add(new CodeParameterDeclarationExpression(ctrlTypeForBuilder, "__ctrl")); } } else { if (typeof(Control).IsAssignableFrom(builder.ControlType)) { fStandardControl = true; } if (builder.ControlType != null) { if (fControlSkin) { if (fStandardControl) { method.ReturnType = new CodeTypeReference(typeof(Control)); } } else if (((PartialCachingAttribute) TypeDescriptor.GetAttributes(builder.ControlType)[typeof(PartialCachingAttribute)]) != null) { method.ReturnType = new CodeTypeReference(typeof(Control)); } else { method.ReturnType = CodeDomUtility.BuildGlobalCodeTypeReference(builder.ControlType); } } fControlFieldDeclared = true; } if (fControlSkin) { method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Control).FullName, "ctrl")); } this.BuildBuildMethodInternal(builder, builder.ControlType, fInTemplate, topLevelControlInTemplate, pse, method.Statements, fStandardControl, fControlFieldDeclared, null, fControlSkin); return method; }
protected override void BuildSourceDataTreeFromBuilder(ControlBuilder builder, bool fInTemplate, bool topLevelControlInTemplate, PropertyEntry pse) { if (!(builder is CodeBlockBuilder)) { bool fTemplate = builder is TemplateBuilder; bool flag2 = builder == this._themeParser.RootBuilder; bool fControlSkin = (!fInTemplate && !fTemplate) && topLevelControlInTemplate; this._controlCount++; builder.ID = "__control" + this._controlCount.ToString(NumberFormatInfo.InvariantInfo); builder.IsGeneratedID = true; if (fControlSkin && !(builder is DataBoundLiteralControlBuilder)) { Type controlType = builder.ControlType; string skinID = builder.SkinID; object key = PageTheme.CreateSkinKey(builder.ControlType, skinID); if (this._controlSkinTypeNameCollection.Contains(key)) { if (string.IsNullOrEmpty(skinID)) { throw new HttpParseException(System.Web.SR.GetString("Page_theme_default_theme_already_defined", new object[] { builder.ControlType.FullName }), null, builder.VirtualPath, null, builder.Line); } throw new HttpParseException(System.Web.SR.GetString("Page_theme_skinID_already_defined", new object[] { skinID }), null, builder.VirtualPath, null, builder.Line); } this._controlSkinTypeNameCollection.Add(key, true); this._controlSkinBuilderEntryList.Add(new ControlSkinBuilderEntry(builder, skinID)); } if (builder.SubBuilders != null) { foreach (object obj3 in builder.SubBuilders) { if (obj3 is ControlBuilder) { bool flag4 = fTemplate && typeof(Control).IsAssignableFrom(((ControlBuilder) obj3).ControlType); this.BuildSourceDataTreeFromBuilder((ControlBuilder) obj3, fInTemplate, flag4, null); } } } foreach (TemplatePropertyEntry entry in builder.TemplatePropertyEntries) { this.BuildSourceDataTreeFromBuilder(entry.Builder, true, false, entry); } foreach (ComplexPropertyEntry entry2 in builder.ComplexPropertyEntries) { if (!(entry2.Builder is StringPropertyBuilder)) { this.BuildSourceDataTreeFromBuilder(entry2.Builder, fInTemplate, false, entry2); } } if (!flag2) { base.BuildBuildMethod(builder, fTemplate, fInTemplate, topLevelControlInTemplate, pse, fControlSkin); } if (!fControlSkin && builder.HasAspCode) { base.BuildRenderMethod(builder, fTemplate); } base.BuildExtractMethod(builder); base.BuildPropertyBindingMethod(builder, fControlSkin); } }
internal override CodeExpression BuildStringPropertyExpression(PropertyEntry pse) { if ((pse.PropertyInfo != null) && (Attribute.GetCustomAttribute(pse.PropertyInfo, typeof(UrlPropertyAttribute)) is UrlPropertyAttribute)) { if (pse is SimplePropertyEntry) { SimplePropertyEntry entry = (SimplePropertyEntry) pse; string virtualPath = (string) entry.Value; if (UrlPath.IsRelativeUrl(virtualPath) && !UrlPath.IsAppRelativePath(virtualPath)) { entry.Value = UrlPath.MakeVirtualPathAppRelative(UrlPath.Combine(this._themeParser.VirtualDirPath.VirtualPathString, virtualPath)); } } else { ComplexPropertyEntry entry2 = (ComplexPropertyEntry) pse; StringPropertyBuilder builder = (StringPropertyBuilder) entry2.Builder; string str2 = (string) builder.BuildObject(); if (UrlPath.IsRelativeUrl(str2) && !UrlPath.IsAppRelativePath(str2)) { entry2.Builder = new StringPropertyBuilder(UrlPath.MakeVirtualPathAppRelative(UrlPath.Combine(this._themeParser.VirtualDirPath.VirtualPathString, str2))); } } } return base.BuildStringPropertyExpression(pse); }
internal virtual CodeExpression BuildStringPropertyExpression(PropertyEntry pse) { string value = String.Empty; if (pse is SimplePropertyEntry) { value = (string)((SimplePropertyEntry)pse).Value; } else { Debug.Assert(pse is ComplexPropertyEntry); ComplexPropertyEntry cpe = (ComplexPropertyEntry)pse; value = (string)((StringPropertyBuilder)cpe.Builder).BuildObject(); } return CodeDomUtility.GenerateExpressionForValue(pse.PropertyInfo, value, typeof(string)); }