示例#1
0
        ControlBuilder CreatePropertyBuilder(string propName, TemplateParser parser, IDictionary atts)
        {
            int    idx;
            string propertyName;

            if ((idx = propName.IndexOf(':')) >= 0)
            {
                propertyName = propName.Substring(idx + 1);
            }
            else
            {
                propertyName = propName;
            }

            PropertyInfo prop = type.GetProperty(propertyName, FlagsNoCase);

            if (prop == null)
            {
                string msg = String.Format("Property {0} not found in type {1}", propertyName, type);
                throw new HttpException(msg);
            }

            Type           propType = prop.PropertyType;
            ControlBuilder builder  = null;

            if (typeof(ICollection).IsAssignableFrom(propType))
            {
                builder = new CollectionBuilder();
            }
            else if (typeof(ITemplate).IsAssignableFrom(propType))
            {
                builder = new TemplateBuilder(prop);
            }
            else if (typeof(string) == propType)
            {
                builder = new StringPropertyBuilder(prop.Name);
            }
            else
            {
                builder = CreateBuilderFromType(parser, parentBuilder, propType, prop.Name,
                                                null, atts, line, fileName);
                builder.isProperty = true;
                if (idx >= 0)
                {
                    builder.originalTagName = propName;
                }
                return(builder);
            }

            builder.Init(parser, this, null, prop.Name, null, atts);
            builder.fileName   = fileName;
            builder.line       = line;
            builder.isProperty = true;
            if (idx >= 0)
            {
                builder.originalTagName = propName;
            }
            return(builder);
        }
        private ControlBuilder GetChildPropertyBuilder(string tagName, IDictionary attribs,
                                                       ref Type childType)
        {
            Debug.Assert(FChildrenAsProperties, "FChildrenAsProperties");

            // The child is supposed to be a property, so look for it
            PropertyInfo pInfo = _ctrlType.GetProperty(
                tagName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase);

            if (pInfo == null)
            {
                throw new HttpException(HttpRuntime.FormatResourceString(
                                            SR.Type_doesnt_have_property, _ctrlType.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
                object[] attrs = pInfo.GetCustomAttributes(typeof(IgnoreUnknownContentAttribute),
                                                           /*inherit*/ true);
                builder = new CollectionBuilder(((attrs != null) && (attrs.Length == 1)) /*ignoreUnknownContent*/);
            }

            // If it's a template, return the template builder
            if (childType == typeof(ITemplate))
            {
                builder = new TemplateBuilder();
            }

            if (builder != null)
            {
                builder._line           = _line;
                builder._sourceFileName = _sourceFileName;

                // 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, _sourceFileName);
            return(builder);
        }
示例#3
0
		ControlBuilder CreatePropertyBuilder (string propName, TemplateParser parser, IDictionary atts)
		{
			int idx;
			string propertyName;
			
			if ((idx = propName.IndexOf (':')) >= 0)
				propertyName = propName.Substring (idx + 1);
			else
				propertyName = propName;
			
			PropertyInfo prop = type.GetProperty (propertyName, FlagsNoCase);
			if (prop == null) {
				string msg = String.Format ("Property {0} not found in type {1}", propertyName, type);
				throw new HttpException (msg);
			}

			Type propType = prop.PropertyType;
			ControlBuilder builder = null;
			if (typeof (ICollection).IsAssignableFrom (propType)) {
				builder = new CollectionBuilder ();
			} else if (typeof (ITemplate).IsAssignableFrom (propType)) {
				builder = new TemplateBuilder (prop);
			} else if (typeof (string) == propType) {
				builder = new StringPropertyBuilder (prop.Name);
			} else {
				builder = CreateBuilderFromType (parser, parentBuilder, propType, prop.Name,
								 null, atts, line, fileName);
				builder.isProperty = true;
				if (idx >= 0)
					builder.originalTagName = propName;
				return builder;
			}

			builder.Init (parser, this, null, prop.Name, null, atts);
			builder.fileName = fileName;
			builder.line = line;
			builder.isProperty = true;
			if (idx >= 0)
				builder.originalTagName = propName;
			return builder;
		}
        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);
 }