private void ApplyTemplateProperties(Control control) { object[] parameters = new object[1]; foreach (TemplatePropertyEntry entry in base.GetFilteredPropertyEntrySet(this._skinBuilder.TemplatePropertyEntries)) { try { if (FastPropertyAccessor.GetProperty(control, entry.Name, base.InDesigner) == null) { ControlBuilder builder = entry.Builder; builder.SetServiceProvider(base.ServiceProvider); try { object obj3 = builder.BuildObject(true); parameters[0] = obj3; } finally { builder.SetServiceProvider(null); } Util.InvokeMethod(entry.PropertyInfo.GetSetMethod(), control, parameters); } } catch (Exception) { } catch { } } }
private void ApplyTemplateProperties(Control control) { object[] parameters = new object[1]; ICollection entries = GetFilteredPropertyEntrySet(_skinBuilder.TemplatePropertyEntries); foreach (TemplatePropertyEntry entry in entries) { try { object originalValue = FastPropertyAccessor.GetProperty(control, entry.Name, InDesigner); if (originalValue == null) { ControlBuilder controlBuilder = ((TemplatePropertyEntry)entry).Builder; controlBuilder.SetServiceProvider(ServiceProvider); try { object objectValue = controlBuilder.BuildObject(true); parameters[0] = objectValue; } finally { controlBuilder.SetServiceProvider(null); } MethodInfo methodInfo = entry.PropertyInfo.GetSetMethod(); Util.InvokeMethod(methodInfo, control, parameters); } } catch (Exception e) { Debug.Fail(e.Message); } #pragma warning disable 1058 catch { } #pragma warning restore 1058 } }
private static Control[] ParseControlsInternalHelper(DesignTimeParseData data, bool returnFirst) { TemplateParser parser = new PageParser { FInDesigner = true, DesignerHost = data.DesignerHost, DesignTimeDataBindHandler = data.DataBindingHandler, Text = data.ParseText }; parser.Parse(); ArrayList list = new ArrayList(); ArrayList subBuilders = parser.RootBuilder.SubBuilders; if (subBuilders != null) { IEnumerator enumerator = subBuilders.GetEnumerator(); for (int i = 0; enumerator.MoveNext(); i++) { object current = enumerator.Current; if ((current is ControlBuilder) && !(current is CodeBlockBuilder)) { ControlBuilder builder = (ControlBuilder)current; IServiceProvider serviceProvider = null; if (data.DesignerHost != null) { serviceProvider = data.DesignerHost; } else { ServiceContainer container = new ServiceContainer(); container.AddService(typeof(IFilterResolutionService), new SimpleDesignTimeFilterResolutionService(data.Filter)); serviceProvider = container; } builder.SetServiceProvider(serviceProvider); try { Control control = (Control)builder.BuildObject(data.ShouldApplyTheme); list.Add(control); } finally { builder.SetServiceProvider(null); } if (!returnFirst) { continue; } break; } if (!returnFirst && (current is string)) { LiteralControl control2 = new LiteralControl(current.ToString()); list.Add(control2); } } } data.SetUserControlRegisterEntries(parser.UserControlRegisterEntries, parser.TagRegisterEntries); return((Control[])list.ToArray(typeof(Control))); }
private void ExtractTemplateValuesRecursive(ArrayList subBuilders, OrderedDictionary table, Control container) { foreach (object obj2 in subBuilders) { ControlBuilder builder = obj2 as ControlBuilder; if (builder != null) { ICollection boundPropertyEntries; if (!builder.HasFilteredBoundEntries) { boundPropertyEntries = builder.BoundPropertyEntries; } else { ServiceContainer serviceProvider = new ServiceContainer(); serviceProvider.AddService(typeof(IFilterResolutionService), builder.TemplateControl); try { builder.SetServiceProvider(serviceProvider); boundPropertyEntries = builder.GetFilteredPropertyEntrySet(builder.BoundPropertyEntries); } finally { builder.SetServiceProvider(null); } } string strA = null; bool flag = true; Control o = null; foreach (BoundPropertyEntry entry in boundPropertyEntries) { if (entry.TwoWayBound) { string str2; if (string.Compare(strA, entry.ControlID, StringComparison.Ordinal) != 0) { flag = true; } else { flag = false; } strA = entry.ControlID; if (flag) { o = container.FindControl(entry.ControlID); if ((o == null) || !entry.ControlType.IsInstanceOfType(o)) { continue; } } object target = PropertyMapper.LocatePropertyObject(o, entry.Name, out str2, base.InDesigner); table[entry.FieldName] = FastPropertyAccessor.GetProperty(target, str2, base.InDesigner); } } this.ExtractTemplateValuesRecursive(builder.SubBuilders, table, container); } } }
/* * 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; }
private static Control[] ParseControlsInternalHelper(DesignTimeParseData data, bool returnFirst) { TemplateParser parser = new PageParser(); parser.FInDesigner = true; parser.DesignerHost = data.DesignerHost; parser.DesignTimeDataBindHandler = data.DataBindingHandler; parser.Text = data.ParseText; parser.Parse(); ArrayList parsedControls = new ArrayList(); ArrayList subBuilders = parser.RootBuilder.SubBuilders; if (subBuilders != null) { // Look for the first control builder IEnumerator en = subBuilders.GetEnumerator(); for (int i = 0; en.MoveNext(); i++) { object cur = en.Current; if ((cur is ControlBuilder) && !(cur is CodeBlockBuilder)) { // Instantiate the control ControlBuilder controlBuilder = (ControlBuilder)cur; System.Diagnostics.Debug.Assert(controlBuilder.CurrentFilterResolutionService == null); IServiceProvider builderServiceProvider = null; // If there's a designer host, use it as the service provider if (data.DesignerHost != null) { builderServiceProvider = data.DesignerHost; } // If it doesn't exist, use a default ---- filter resolution service else { ServiceContainer serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(IFilterResolutionService), new SimpleDesignTimeFilterResolutionService(data.Filter)); builderServiceProvider = serviceContainer; } controlBuilder.SetServiceProvider(builderServiceProvider); try { Control control = (Control)controlBuilder.BuildObject(data.ShouldApplyTheme); parsedControls.Add(control); } finally { controlBuilder.SetServiceProvider(null); } if (returnFirst) { break; } } // To preserve backwards compatibility, we don't add LiteralControls // to the control collection when parsing for a single control else if (!returnFirst && (cur is string)) { LiteralControl literalControl = new LiteralControl(cur.ToString()); parsedControls.Add(literalControl); } } } data.SetUserControlRegisterEntries(parser.UserControlRegisterEntries, parser.TagRegisterEntries); return((Control[])parsedControls.ToArray(typeof(Control))); }
private void ExtractTemplateValuesRecursive(ArrayList subBuilders, OrderedDictionary table, Control container) { foreach (object subBuilderObject in subBuilders) { ControlBuilder subBuilderControlBuilder = subBuilderObject as ControlBuilder; if (subBuilderControlBuilder != null) { ICollection entries; // filter out device filtered bound entries that don't apply to this device if (!subBuilderControlBuilder.HasFilteredBoundEntries) { entries = subBuilderControlBuilder.BoundPropertyEntries; } else { Debug.Assert(subBuilderControlBuilder.ServiceProvider == null); Debug.Assert(subBuilderControlBuilder.TemplateControl != null, "TemplateControl should not be null in no-compile pages. We need it for the FilterResolutionService."); ServiceContainer serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(IFilterResolutionService), subBuilderControlBuilder.TemplateControl); try { subBuilderControlBuilder.SetServiceProvider(serviceContainer); entries = subBuilderControlBuilder.GetFilteredPropertyEntrySet(subBuilderControlBuilder.BoundPropertyEntries); } finally { subBuilderControlBuilder.SetServiceProvider(null); } } string previousControlName = null; bool newControl = true; Control control = null; foreach (BoundPropertyEntry entry in entries) { // Skip all entries that are not two-way if (!entry.TwoWayBound) { continue; } // Reset the "previous" Property Entry if we're not looking at the same control. // If we don't do this, Two controls that have conditionals on the same named property will have // their conditionals incorrectly merged. if (String.Compare(previousControlName, entry.ControlID, StringComparison.Ordinal) != 0) { newControl = true; } else { newControl = false; } previousControlName = entry.ControlID; if (newControl) { control = container.FindControl(entry.ControlID); if (control == null || !entry.ControlType.IsInstanceOfType(control)) { Debug.Assert(false, "BoundPropertyEntry is of wrong control type or couldn't be found. Expected " + entry.ControlType.Name); continue; } } string propertyName; // map the property in case it's a complex property object targetObject = PropertyMapper.LocatePropertyObject(control, entry.Name, out propertyName, InDesigner); // FastPropertyAccessor uses ReflectEmit for lightning speed table[entry.FieldName] = FastPropertyAccessor.GetProperty(targetObject, propertyName, InDesigner); } ExtractTemplateValuesRecursive(subBuilderControlBuilder.SubBuilders, table, container); } } }