/* * 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; }
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; }