private IOrderedDictionary ExtractTemplateValuesMethod(Control container)
        {
            BindableTemplateBuilder builder = this;
            OrderedDictionary       table   = new OrderedDictionary();

            if (builder != null)
            {
                this.ExtractTemplateValuesRecursive(builder.SubBuilders, table, container);
            }
            return(table);
        }
Beispiel #2
0
        /*
         * 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 ControlBuilder GetChildPropertyBuilder(string tagName, IDictionary attribs, ref Type childType, TemplateParser templateParser, bool defaultProperty) {
            Debug.Assert(FChildrenAsProperties, "ChildrenAsProperties");

            // Parse the device filter if any
            // The child is supposed to be a property, so look for it
            PropertyInfo pInfo = TargetFrameworkUtil.GetProperty(_controlType, tagName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase);

            if (pInfo == null) {
                throw new HttpException(SR.GetString(SR.Type_doesnt_have_property, _controlType.FullName, tagName));
            }

            // Get its type
            childType = pInfo.PropertyType;

            ControlBuilder builder = null;

            // If it's a collection, return the collection builder
            if (typeof(ICollection).IsAssignableFrom(childType)) {
                // Check whether the prop has an IgnoreUnknownContentAttribute
                IgnoreUnknownContentAttribute attr = (IgnoreUnknownContentAttribute)Attribute.GetCustomAttribute(pInfo, typeof(IgnoreUnknownContentAttribute), true);

                builder = new CollectionBuilder(attr != null /*ignoreUnknownContent*/);
            }
            else if (typeof(ITemplate).IsAssignableFrom(childType)) {
                bool useBindableTemplate = false;
                bool allowMultipleInstances = true;
                object[] containerAttrs = pInfo.GetCustomAttributes(typeof(TemplateContainerAttribute), /*inherits*/ false);

                if ((containerAttrs != null) && (containerAttrs.Length > 0)) {
                    Debug.Assert(containerAttrs[0] is TemplateContainerAttribute);
                    useBindableTemplate = (((TemplateContainerAttribute)containerAttrs[0]).BindingDirection == BindingDirection.TwoWay);
                }

                allowMultipleInstances = Util.IsMultiInstanceTemplateProperty(pInfo);

                if (useBindableTemplate) {  // If it's a bindable template, return the bindable template builder
                    builder = new BindableTemplateBuilder();
                }
                else {  // If it's a template, return the template builder
                    builder = new TemplateBuilder();
                }

                if (builder is TemplateBuilder) {
                    ((TemplateBuilder)builder).AllowMultipleInstances = allowMultipleInstances;
                    // If we're in the designer, set a reference to the designer host
                    // so we can get to a filter resolution service later
                    if (InDesigner) {
                        ((TemplateBuilder)builder).SetDesignerHost(templateParser.DesignerHost);
                    }
                }
            }
            else if (childType == typeof(string)) {
                PersistenceModeAttribute persistenceAttr = (PersistenceModeAttribute)Attribute.GetCustomAttribute(pInfo, typeof(PersistenceModeAttribute), true);

                if (((persistenceAttr == null) || (persistenceAttr.Mode == PersistenceMode.Attribute)) && !defaultProperty) {
                    // If the property is supposed to be declared as an attribute on a control tag, throw if it was declared as an inner property
                    // We don't throw if we are simply building the DefaultPropertyBuilder.
                    throw new HttpException(SR.GetString(SR.ControlBuilder_CannotHaveComplexString, _controlType.FullName, tagName));
                }
                builder = new StringPropertyBuilder();
            }

            if (builder != null) {
                builder.Line = Line;
                builder.VirtualPath = VirtualPath;

                // Initialize the builder
                builder.Init(Parser, (ControlBuilder)this, null, tagName, null, attribs);
                return builder;
            }

            // Otherwise, simply return the builder for the property
            builder = CreateBuilderFromType(Parser, this, childType, tagName, null,
                attribs, Line, PageVirtualPath);
            return builder;
        }
 private ControlBuilder GetChildPropertyBuilder(string tagName, IDictionary attribs, ref Type childType, TemplateParser templateParser, bool defaultProperty)
 {
     PropertyInfo element = TargetFrameworkUtil.GetProperty(this._controlType, tagName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase);
     if (element == null)
     {
         throw new HttpException(System.Web.SR.GetString("Type_doesnt_have_property", new object[] { this._controlType.FullName, tagName }));
     }
     childType = element.PropertyType;
     ControlBuilder builder = null;
     if (typeof(ICollection).IsAssignableFrom(childType))
     {
         IgnoreUnknownContentAttribute attribute = (IgnoreUnknownContentAttribute) Attribute.GetCustomAttribute(element, typeof(IgnoreUnknownContentAttribute), true);
         builder = new CollectionBuilder(attribute != null);
     }
     else if (typeof(ITemplate).IsAssignableFrom(childType))
     {
         bool flag = false;
         bool flag2 = true;
         object[] customAttributes = element.GetCustomAttributes(typeof(TemplateContainerAttribute), false);
         if ((customAttributes != null) && (customAttributes.Length > 0))
         {
             flag = ((TemplateContainerAttribute) customAttributes[0]).BindingDirection == BindingDirection.TwoWay;
         }
         flag2 = System.Web.UI.Util.IsMultiInstanceTemplateProperty(element);
         if (flag)
         {
             builder = new BindableTemplateBuilder();
         }
         else
         {
             builder = new TemplateBuilder();
         }
         if (builder is TemplateBuilder)
         {
             ((TemplateBuilder) builder).AllowMultipleInstances = flag2;
             if (this.InDesigner)
             {
                 ((TemplateBuilder) builder).SetDesignerHost(templateParser.DesignerHost);
             }
         }
     }
     else if (childType == typeof(string))
     {
         PersistenceModeAttribute attribute2 = (PersistenceModeAttribute) Attribute.GetCustomAttribute(element, typeof(PersistenceModeAttribute), true);
         if (((attribute2 == null) || (attribute2.Mode == PersistenceMode.Attribute)) && !defaultProperty)
         {
             throw new HttpException(System.Web.SR.GetString("ControlBuilder_CannotHaveComplexString", new object[] { this._controlType.FullName, tagName }));
         }
         builder = new StringPropertyBuilder();
     }
     if (builder != null)
     {
         builder.Line = this.Line;
         builder.VirtualPath = this.VirtualPath;
         builder.Init(this.Parser, this, null, tagName, null, attribs);
         return builder;
     }
     return CreateBuilderFromType(this.Parser, this, childType, tagName, null, attribs, this.Line, this.PageVirtualPath);
 }