Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / UI / BindableTemplateBuilder.cs / 5 / BindableTemplateBuilder.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Classes related to templated control support * * Copyright (c) 1999 Microsoft Corporation */ namespace System.Web.UI { using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.ComponentModel.Design; using System.Globalization; using System.Reflection; using System.Security.Permissions; using System.Web.Util; ////// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class BindableTemplateBuilder : TemplateBuilder, IBindableTemplate { private ExtractTemplateValuesMethod _extractTemplateValuesMethod; /* * No-compile delegate handler for ExtractValues. */ private IOrderedDictionary ExtractTemplateValuesMethod(Control container) { /*System.Web.UI.OrderedDictionary @__table; System.Web.UI.WebControls.DropDownList ddl2; @__table = new System.Web.UI.OrderedDictionary(); ddl2 = ((System.Web.UI.WebControls.DropDownList)(@__container.FindControl("ddl2"))); if ((ddl2 != null)) { @__table["FavVegetable"] = ddl2.SelectedValue; } return @__table;*/ BindableTemplateBuilder bindableTemplateBuilder = this as BindableTemplateBuilder; Debug.Assert(bindableTemplateBuilder != null, "ExtractTemplateValuesMethod called on non-BindableTemplateBuilder."); OrderedDictionary table = new OrderedDictionary(); if (bindableTemplateBuilder != null) { ExtractTemplateValuesRecursive(bindableTemplateBuilder.SubBuilders, table, container); } return table; } 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); // FastPropertyAccessor uses ReflectEmit for lightning speed table[entry.FieldName] = FastPropertyAccessor.GetProperty(targetObject, propertyName); } ExtractTemplateValuesRecursive(subBuilderControlBuilder.SubBuilders, table, container); } } } /* * IBindableTemplate implementation * This implementation of ITemplate is used in the designer and no-compile. */ public IOrderedDictionary ExtractValues(Control container) { if (_extractTemplateValuesMethod != null && !InDesigner) { return _extractTemplateValuesMethod(container); } return new OrderedDictionary(); } public override void OnAppendToParentBuilder(ControlBuilder parentBuilder) { base.OnAppendToParentBuilder(parentBuilder); if (HasTwoWayBoundProperties) { _extractTemplateValuesMethod = new ExtractTemplateValuesMethod(ExtractTemplateValuesMethod); } } } // Delegates used for the compiled template and no-compile Bind ///[To be supplied.] ////// /// public delegate IOrderedDictionary ExtractTemplateValuesMethod(Control control); /* * This class is the ITemplate implementation that is called from the * generated page class code. It just passes the Initialize call on to a * delegate. */ ///[To be supplied.] ////// /// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class CompiledBindableTemplateBuilder : IBindableTemplate { private BuildTemplateMethod _buildTemplateMethod; private ExtractTemplateValuesMethod _extractTemplateValuesMethod; ///[To be supplied.] ////// public CompiledBindableTemplateBuilder(BuildTemplateMethod buildTemplateMethod, ExtractTemplateValuesMethod extractTemplateValuesMethod) { _buildTemplateMethod = buildTemplateMethod; _extractTemplateValuesMethod = extractTemplateValuesMethod; } // IBindableTemplate::ExtractValues ///[To be supplied.] ////// public IOrderedDictionary ExtractValues(Control container) { if (_extractTemplateValuesMethod != null) { return _extractTemplateValuesMethod(container); } return new OrderedDictionary(); } // ITemplate::InstantiateIn ///Calls the ExtractTemplateValuesMethod delegate, which will return a dictionary of values. ////// public void InstantiateIn(Control container) { _buildTemplateMethod(container); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //[To be supplied.] ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Classes related to templated control support * * Copyright (c) 1999 Microsoft Corporation */ namespace System.Web.UI { using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.ComponentModel.Design; using System.Globalization; using System.Reflection; using System.Security.Permissions; using System.Web.Util; ////// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class BindableTemplateBuilder : TemplateBuilder, IBindableTemplate { private ExtractTemplateValuesMethod _extractTemplateValuesMethod; /* * No-compile delegate handler for ExtractValues. */ private IOrderedDictionary ExtractTemplateValuesMethod(Control container) { /*System.Web.UI.OrderedDictionary @__table; System.Web.UI.WebControls.DropDownList ddl2; @__table = new System.Web.UI.OrderedDictionary(); ddl2 = ((System.Web.UI.WebControls.DropDownList)(@__container.FindControl("ddl2"))); if ((ddl2 != null)) { @__table["FavVegetable"] = ddl2.SelectedValue; } return @__table;*/ BindableTemplateBuilder bindableTemplateBuilder = this as BindableTemplateBuilder; Debug.Assert(bindableTemplateBuilder != null, "ExtractTemplateValuesMethod called on non-BindableTemplateBuilder."); OrderedDictionary table = new OrderedDictionary(); if (bindableTemplateBuilder != null) { ExtractTemplateValuesRecursive(bindableTemplateBuilder.SubBuilders, table, container); } return table; } 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); // FastPropertyAccessor uses ReflectEmit for lightning speed table[entry.FieldName] = FastPropertyAccessor.GetProperty(targetObject, propertyName); } ExtractTemplateValuesRecursive(subBuilderControlBuilder.SubBuilders, table, container); } } } /* * IBindableTemplate implementation * This implementation of ITemplate is used in the designer and no-compile. */ public IOrderedDictionary ExtractValues(Control container) { if (_extractTemplateValuesMethod != null && !InDesigner) { return _extractTemplateValuesMethod(container); } return new OrderedDictionary(); } public override void OnAppendToParentBuilder(ControlBuilder parentBuilder) { base.OnAppendToParentBuilder(parentBuilder); if (HasTwoWayBoundProperties) { _extractTemplateValuesMethod = new ExtractTemplateValuesMethod(ExtractTemplateValuesMethod); } } } // Delegates used for the compiled template and no-compile Bind ///[To be supplied.] ////// /// public delegate IOrderedDictionary ExtractTemplateValuesMethod(Control control); /* * This class is the ITemplate implementation that is called from the * generated page class code. It just passes the Initialize call on to a * delegate. */ ///[To be supplied.] ////// /// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class CompiledBindableTemplateBuilder : IBindableTemplate { private BuildTemplateMethod _buildTemplateMethod; private ExtractTemplateValuesMethod _extractTemplateValuesMethod; ///[To be supplied.] ////// public CompiledBindableTemplateBuilder(BuildTemplateMethod buildTemplateMethod, ExtractTemplateValuesMethod extractTemplateValuesMethod) { _buildTemplateMethod = buildTemplateMethod; _extractTemplateValuesMethod = extractTemplateValuesMethod; } // IBindableTemplate::ExtractValues ///[To be supplied.] ////// public IOrderedDictionary ExtractValues(Control container) { if (_extractTemplateValuesMethod != null) { return _extractTemplateValuesMethod(container); } return new OrderedDictionary(); } // ITemplate::InstantiateIn ///Calls the ExtractTemplateValuesMethod delegate, which will return a dictionary of values. ////// public void InstantiateIn(Control container) { _buildTemplateMethod(container); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.[To be supplied.] ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObjectQueryExecutionPlan.cs
- PnrpPeerResolver.cs
- MdImport.cs
- AsnEncodedData.cs
- IChannel.cs
- ParameterCollection.cs
- ApplyHostConfigurationBehavior.cs
- SmtpNetworkElement.cs
- IUnknownConstantAttribute.cs
- RSAPKCS1SignatureDeformatter.cs
- RubberbandSelector.cs
- ConfigViewGenerator.cs
- DesignerActionMethodItem.cs
- UTF32Encoding.cs
- AmbiguousMatchException.cs
- PersonalizationStateInfo.cs
- DataRowView.cs
- Accessible.cs
- BindableTemplateBuilder.cs
- NetTcpBinding.cs
- InstanceDataCollection.cs
- Journal.cs
- DES.cs
- LocatorManager.cs
- Repeater.cs
- InstanceHandleReference.cs
- TextEditorLists.cs
- BinaryParser.cs
- SizeAnimationBase.cs
- MetaData.cs
- ObjectItemCollection.cs
- DocumentXmlWriter.cs
- TextTreeObjectNode.cs
- Point4D.cs
- Sequence.cs
- EarlyBoundInfo.cs
- RoleGroupCollectionEditor.cs
- SafeEventLogWriteHandle.cs
- XmlFormatExtensionAttribute.cs
- Membership.cs
- WinFormsSpinner.cs
- DelegatingConfigHost.cs
- ProcessHostConfigUtils.cs
- _NtlmClient.cs
- DataGridTableCollection.cs
- FlowDocumentReaderAutomationPeer.cs
- MachineKeySection.cs
- UIElement.cs
- EditingScopeUndoUnit.cs
- AnonymousIdentificationModule.cs
- EntityContainerRelationshipSet.cs
- ConfigurationValues.cs
- WebPartCloseVerb.cs
- SAPICategories.cs
- ExtractorMetadata.cs
- OrderingQueryOperator.cs
- Int32Converter.cs
- FormsAuthenticationUser.cs
- EntityStoreSchemaGenerator.cs
- DbSetClause.cs
- CapabilitiesRule.cs
- SetterTriggerConditionValueConverter.cs
- RectangleF.cs
- CacheMemory.cs
- ToolStripContentPanel.cs
- HierarchicalDataBoundControl.cs
- MsmqOutputSessionChannel.cs
- PopupEventArgs.cs
- PointConverter.cs
- NameValuePermission.cs
- UrlUtility.cs
- GenericParameterDataContract.cs
- NameTable.cs
- CalendarKeyboardHelper.cs
- BehaviorEditorPart.cs
- CompiledRegexRunner.cs
- PasswordBoxAutomationPeer.cs
- ExpressionBindingCollection.cs
- Attributes.cs
- OLEDB_Enum.cs
- UnmanagedMarshal.cs
- ParserHooks.cs
- ProtocolsConfigurationHandler.cs
- InvokeHandlers.cs
- ToolTip.cs
- WindowsRichEditRange.cs
- Directory.cs
- RemoteWebConfigurationHostServer.cs
- ButtonStandardAdapter.cs
- SettingsAttributeDictionary.cs
- FormViewDeleteEventArgs.cs
- WebSysDisplayNameAttribute.cs
- RSACryptoServiceProvider.cs
- TextBoxBase.cs
- TransactionInformation.cs
- WebPartHelpVerb.cs
- ObjectCacheHost.cs
- SemanticResolver.cs
- OleServicesContext.cs
- KeyGestureValueSerializer.cs