public override void OnProcessGeneratedCode(ControlBuilder controlBuilder, CodeCompileUnit codeCompileUnit, CodeTypeDeclaration baseType, CodeTypeDeclaration derivedType, CodeMemberMethod buildMethod, CodeMemberMethod dataBindingMethod, System.Collections.IDictionary additionalState) { // only run this once during page compilation, and only use this one builder (so that we don't get master pages, etc.) if (controlBuilder.GetType() == typeof(FileLevelPageControlBuilder)) { // the page will only contain one namespace and one type var ns = codeCompileUnit.Namespaces.Cast<CodeNamespace>().FirstOrDefault(); if (ns != null) { var type = ns.Types.Cast<CodeTypeDeclaration>().FirstOrDefault(); if (type != null) { /* When this is output, it will inject this into every page: * * protected override PageStatePersister PageStatePersister { * get { return new CompressedHiddenFieldPageStatePersister(this); } * } * */ CodeMemberProperty property = new CodeMemberProperty() { Name = "PageStatePersister", HasGet = true, Attributes = MemberAttributes.Override | MemberAttributes.Family, Type = new CodeTypeReference(typeof(PageStatePersister)) }; var newObj = new CodeObjectCreateExpression(typeof(CompressedHiddenFieldPageStatePersister), new CodeThisReferenceExpression()); property.GetStatements.Add(new CodeMethodReturnStatement(newObj)); type.Members.Add(property); } } } base.OnProcessGeneratedCode(controlBuilder, codeCompileUnit, baseType, derivedType, buildMethod, dataBindingMethod, additionalState); }
public override void AppendSubBuilder(ControlBuilder subBuilder) { if (subBuilder == null) { base.AppendSubBuilder(subBuilder); return; } if (typeof(ContentBuilderInternal).IsAssignableFrom(subBuilder.GetType())) { if (hasOtherControls) { throw new HttpException("Only Content controls are supported on content pages."); } hasContentControls = true; if (hasLiteralControls) { throw new HttpParseException("Only Content controls are supported on content pages."); } } else { hasOtherControls = true; } base.AppendSubBuilder(subBuilder); }
/// <include file='doc\LiteralTextContainerControlBuilder.uex' path='docs/doc[@for="LiteralTextContainerControlBuilder.AppendSubBuilder"]/*' /> public override void AppendSubBuilder(ControlBuilder subBuilder) { if (InDesigner) { base.AppendSubBuilder(subBuilder); } // The first one is used if ASP.NET is compiled with FAST_DATABINDING off. The second // is used if it is compiled with FAST_DATABINDING on. Note: We can't do a type // comparison because CodeBlockBuilder is internal. //else if (typeof(DataBoundLiteralControl).IsAssignableFrom(subBuilder.ControlType)) else if (subBuilder.GetType().FullName == "System.Web.UI.CodeBlockBuilder") { TextParser.AddDataBinding(subBuilder); } else { base.AppendSubBuilder(subBuilder); if (subBuilder.ControlType != typeof(LiteralText)) { if (_textParser != null) { _textParser.ResetBreaking(); } else { _controlsInserted = true; } } } }
void AppendCode(ControlBuilder subBuilder) { if (type != null && !(typeof(Control).IsAssignableFrom(type))) { throw new HttpException("Code render not supported here."); } if (typeof(CodeRenderBuilder) == subBuilder.GetType()) { hasAspCode = true; } AddChild(subBuilder); }
void AppendToProperty(ControlBuilder subBuilder) { if (typeof(CodeRenderBuilder) == subBuilder.GetType()) { throw new HttpException("Code render not supported here."); } if (defaultPropertyBuilder != null) { defaultPropertyBuilder.AppendSubBuilder(subBuilder); return; } AddChild(subBuilder); }
public override void AppendSubBuilder (ControlBuilder subBuilder) { if (subBuilder == null) { base.AppendSubBuilder (subBuilder); return; } if (typeof (ContentBuilderInternal).IsAssignableFrom (subBuilder.GetType ())) { if (hasOtherControls) throw new HttpException ("Only Content controls are supported on content pages."); hasContentControls = true; if (hasLiteralControls) throw new HttpParseException ("Only Content controls are supported on content pages."); } else hasOtherControls = true; base.AppendSubBuilder (subBuilder); }
public virtual void AppendSubBuilder(ControlBuilder subBuilder) { subBuilder.OnAppendToParentBuilder(this); subBuilder.parentBuilder = this; if (childrenAsProperties) { AppendToProperty(subBuilder); return; } if (typeof(CodeRenderBuilder).IsAssignableFrom(subBuilder.GetType())) { AppendCode(subBuilder); return; } AddChild(subBuilder); }
protected void CreateControlTree (ControlBuilder builder, bool inTemplate, bool childrenAsProperties) { EnsureID (builder); bool isTemplate = builder.IsTemplate; if (!isTemplate && !inTemplate) { CreateField (builder, true); } else if (!isTemplate) { bool doCheck = false; bool singleInstance = false; ControlBuilder pb = builder.ParentBuilder; TemplateBuilder tpb; while (pb != null) { tpb = pb as TemplateBuilder; if (tpb == null) { pb = pb.ParentBuilder; continue; } if (tpb.TemplateInstance == TemplateInstance.Single) singleInstance = true; break; } if (!singleInstance) builder.ID = builder.GetNextID (null); else doCheck = true; CreateField (builder, doCheck); } InitMethod (builder, isTemplate, childrenAsProperties); if (!isTemplate || builder.GetType () == typeof (RootBuilder)) CreateAssignStatementsFromAttributes (builder); if (builder.Children != null && builder.Children.Count > 0) { StringBuilder sb = new StringBuilder (); foreach (object b in builder.Children) { if (b is string) { sb.Append ((string) b); continue; } FlushText (builder, sb); if (b is ObjectTagBuilder) { ProcessObjectTag ((ObjectTagBuilder) b); } else if (b is StringPropertyBuilder) { StringPropertyBuilder pb = b as StringPropertyBuilder; if (pb.Children != null && pb.Children.Count > 0) { StringBuilder asb = new StringBuilder (); foreach (string s in pb.Children) asb.Append (s); CodeMemberMethod method = builder.Method; CodeAssignStatement assign = new CodeAssignStatement (); assign.Left = new CodePropertyReferenceExpression (ctrlVar, pb.PropertyName); assign.Right = new CodePrimitiveExpression (asb.ToString ()); method.Statements.Add (AddLinePragma (assign, builder)); } } else if (b is ContentBuilderInternal) { ContentBuilderInternal cb = (ContentBuilderInternal) b; CreateControlTree (cb, false, true); AddContentTemplateInvocation (cb, builder.Method, cb.Method.Name); continue; } // Ignore TemplateBuilders - they are processed in InitMethod else if (b is TemplateBuilder) { } else if (b is CodeRenderBuilder) { AddCodeRender (builder, (CodeRenderBuilder) b); } else if (b is DataBindingBuilder) { AddDataBindingLiteral (builder, (DataBindingBuilder) b); } else if (b is ControlBuilder) { ControlBuilder child = (ControlBuilder) b; CreateControlTree (child, inTemplate, builder.ChildrenAsProperties); AddChildCall (builder, child); continue; } else throw new Exception ("???"); ControlBuilder bldr = b as ControlBuilder; bldr.ProcessGeneratedCode (CompileUnit, BaseType, DerivedType, bldr.Method, bldr.DataBindingMethod); } FlushText (builder, sb); } ControlBuilder defaultPropertyBuilder = builder.DefaultPropertyBuilder; if (defaultPropertyBuilder != null) { CreateControlTree (defaultPropertyBuilder, false, true); AddChildCall (builder, defaultPropertyBuilder); } if (builder.HasAspCode) { CodeMemberMethod renderMethod = builder.RenderMethod; CodeMethodReferenceExpression m = new CodeMethodReferenceExpression (); m.TargetObject = thisRef; m.MethodName = renderMethod.Name; CodeDelegateCreateExpression create = new CodeDelegateCreateExpression (); create.DelegateType = new CodeTypeReference (typeof (RenderMethod)); create.TargetObject = thisRef; create.MethodName = renderMethod.Name; CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (); invoke.Method = new CodeMethodReferenceExpression (ctrlVar, "SetRenderMethodDelegate"); invoke.Parameters.Add (create); builder.MethodStatements.Add (invoke); } if (builder is RootBuilder) if (!String.IsNullOrEmpty (parser.MetaResourceKey)) AssignPropertiesFromResources (builder, parser.BaseType, parser.MetaResourceKey); if ((!isTemplate || builder is RootBuilder) && !String.IsNullOrEmpty (builder.GetAttribute ("meta:resourcekey"))) CreateAssignStatementFromAttribute (builder, "meta:resourcekey"); if ((childrenAsProperties && builder.PropertyBuilderShouldReturnValue) || (!childrenAsProperties && typeof (Control).IsAssignableFrom (builder.ControlType))) builder.Method.Statements.Add (new CodeMethodReturnStatement (ctrlVar)); builder.ProcessGeneratedCode (CompileUnit, BaseType, DerivedType, builder.Method, builder.DataBindingMethod); }
void AppendCode (ControlBuilder subBuilder) { if (type != null && !(typeof (Control).IsAssignableFrom (type))) throw new HttpException ("Code render not supported here."); if (typeof (CodeRenderBuilder) == subBuilder.GetType ()) hasAspCode = true; AddChild (subBuilder); }
void AppendToProperty (ControlBuilder subBuilder) { if (typeof (CodeRenderBuilder) == subBuilder.GetType ()) throw new HttpException ("Code render not supported here."); if (defaultPropertyBuilder != null) { defaultPropertyBuilder.AppendSubBuilder (subBuilder); return; } AddChild (subBuilder); }
public virtual void AppendSubBuilder (ControlBuilder subBuilder) { subBuilder.OnAppendToParentBuilder (this); subBuilder.parentBuilder = this; if (childrenAsProperties) { AppendToProperty (subBuilder); return; } if (typeof (CodeRenderBuilder).IsAssignableFrom (subBuilder.GetType ())) { AppendCode (subBuilder); return; } AddChild (subBuilder); }
/// <include file='doc\Form.uex' path='docs/doc[@for="FormControlBuilder.AppendSubBuilder"]/*' /> public override void AppendSubBuilder(ControlBuilder subBuilder) { Type controlType = subBuilder.ControlType; if(!( (subBuilder.GetType().FullName == "System.Web.UI.CodeBlockBuilder") || (typeof(MobileControl).IsAssignableFrom(controlType)) || (typeof(UserControl).IsAssignableFrom(controlType)) || (typeof(DeviceSpecific).IsAssignableFrom(controlType)) )) { throw(new Exception(SR.GetString(SR.Form_InvalidSubControlType, subBuilder.TagName))); } base.AppendSubBuilder(subBuilder); }
void CreateControlTree (ControlBuilder builder, bool inTemplate, bool childrenAsProperties) { EnsureID (builder); bool isTemplate = (typeof (TemplateBuilder).IsAssignableFrom (builder.GetType ())); if (!isTemplate && !inTemplate) { CreateField (builder, true); } else if (!isTemplate) { builder.ID = builder.GetNextID (null); CreateField (builder, false); } InitMethod (builder, isTemplate, childrenAsProperties); if (!isTemplate || builder.GetType () == typeof (RootBuilder)) CreateAssignStatementsFromAttributes (builder); if (builder.Children != null && builder.Children.Count > 0) { ArrayList templates = null; StringBuilder sb = new StringBuilder (); foreach (object b in builder.Children) { if (b is string) { sb.Append ((string) b); continue; } FlushText (builder, sb); if (b is ObjectTagBuilder) { ProcessObjectTag ((ObjectTagBuilder) b); continue; } #if NET_2_0 if (b is ContentControlBuilder) { ContentControlBuilder cb = (ContentControlBuilder) b; CreateControlTree (cb, false, true); AddContentTemplateInvocation (cb, builder.method, cb.method.Name); continue; } #endif if (b is TemplateBuilder) { if (templates == null) templates = new ArrayList (); templates.Add (b); continue; } if (b is CodeRenderBuilder) { AddCodeRender (builder, (CodeRenderBuilder) b); continue; } if (b is DataBindingBuilder) { AddDataBindingLiteral (builder, (DataBindingBuilder) b); continue; } if (b is ControlBuilder) { ControlBuilder child = (ControlBuilder) b; CreateControlTree (child, inTemplate, builder.ChildrenAsProperties); AddChildCall (builder, child); continue; } throw new Exception ("???"); } FlushText (builder, sb); if (templates != null) { foreach (TemplateBuilder b in templates) { CreateControlTree (b, true, false); #if NET_2_0 if (b.BindingDirection == BindingDirection.TwoWay) { string extractMethod = CreateExtractValuesMethod (b); AddBindableTemplateInvocation (builder.method, b.TagName, b.method.Name, extractMethod); } else #endif AddTemplateInvocation (builder.method, b.TagName, b.method.Name); } } } if (builder.defaultPropertyBuilder != null) { ControlBuilder b = builder.defaultPropertyBuilder; CreateControlTree (b, false, true); AddChildCall (builder, b); } if (builder.HasAspCode) { CodeMethodReferenceExpression m = new CodeMethodReferenceExpression (); m.TargetObject = thisRef; m.MethodName = builder.renderMethod.Name; CodeDelegateCreateExpression create = new CodeDelegateCreateExpression (); create.DelegateType = new CodeTypeReference (typeof (RenderMethod)); create.TargetObject = thisRef; create.MethodName = builder.renderMethod.Name; CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (); invoke.Method = new CodeMethodReferenceExpression (ctrlVar, "SetRenderMethodDelegate"); invoke.Parameters.Add (create); builder.method.Statements.Add (invoke); } if (!childrenAsProperties && typeof (Control).IsAssignableFrom (builder.ControlType)) builder.method.Statements.Add (new CodeMethodReturnStatement (ctrlVar)); }