internal TemplateBuilder (ICustomAttributeProvider prov) { object[] ats = prov.GetCustomAttributes (typeof(TemplateContainerAttribute), true); if (ats.Length > 0) { containerAttribute = (TemplateContainerAttribute) ats [0]; } }
public void Ctor1_Deny_Unrestricted () { TemplateContainerAttribute tca = new TemplateContainerAttribute (null); Assert.IsNull (tca.ContainerType, "ContainerType"); #if NET_2_0 Assert.AreEqual (BindingDirection.OneWay, tca.BindingDirection, "BindingDirection"); #endif }
internal TemplateBuilder (ICustomAttributeProvider prov) { object[] ats = prov.GetCustomAttributes (typeof (TemplateContainerAttribute), true); if (ats.Length > 0) containerAttribute = (TemplateContainerAttribute) ats [0]; #if NET_2_0 ats = prov.GetCustomAttributes (typeof (TemplateInstanceAttribute), true); if (ats.Length > 0) instanceAttribute = (TemplateInstanceAttribute) ats [0]; #endif }
internal TemplateBuilder(ICustomAttributeProvider prov) { object[] ats = prov.GetCustomAttributes(typeof(TemplateContainerAttribute), true); if (ats.Length > 0) { containerAttribute = (TemplateContainerAttribute)ats [0]; } ats = prov.GetCustomAttributes(typeof(TemplateInstanceAttribute), true); if (ats.Length > 0) { instanceAttribute = (TemplateInstanceAttribute)ats [0]; } }
/// <summary> /// Construct an instance of a ReflectedControlProperty, given the control for this property and the /// pre-reflected PropertyInfo for the property in question. /// </summary> /// <param name="reflectedControl">The control that owns this property.</param> /// <param name="propertyInfo">The pre-reflected PropertyInfo for this property.</param> public ReflectedControlProperty(ReflectedControl reflectedControl, PropertyInfo propertyInfo) { ReflectedControl = reflectedControl; PropertyInfo = propertyInfo; var custAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.PersistenceModeAttribute)); if (custAtts.Any()) { var parseAtt = custAtts.First(); // public PersistenceModeAttribute(PersistenceMode mode); if (parseAtt.ConstructorArguments.Count == 1) { PersistenceMode val = (PersistenceMode)parseAtt.ConstructorArguments[0].Value; PersistenceModeAttribute = new System.Web.UI.PersistenceModeAttribute(val); //public ParseChildrenAttribute(); } } else { PersistenceModeAttribute = null; } //System.Web.UI.PersistenceModeAttribute[] persistenceModeAttributes = (System.Web.UI.PersistenceModeAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.PersistenceModeAttribute), true); //PersistenceModeAttribute = persistenceModeAttributes.Length == 0 ? null : persistenceModeAttributes[0]; IsTemplateProperty = typeof(System.Web.UI.ITemplate).IsAssignableFrom(PropertyInfo.PropertyType); IsCollectionProperty = typeof(IEnumerable).IsAssignableFrom(PropertyInfo.PropertyType) && !IsTemplateProperty; if (IsTemplateProperty) { var custTemplateInstanceAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.TemplateInstanceAttribute)); if (custTemplateInstanceAtts.Any()) { var parseAtt = custTemplateInstanceAtts.First(); // public TemplateInstanceAttribute(TemplateInstance instances); if (parseAtt.ConstructorArguments.Count == 1) { TemplateInstance val = (TemplateInstance)parseAtt.ConstructorArguments[0].Value; TemplateInstanceAttribute = new System.Web.UI.TemplateInstanceAttribute(val); //public ParseChildrenAttribute(); } } else { TemplateInstanceAttribute = null; } //System.Web.UI.TemplateInstanceAttribute[] templateInstanceAttributes = (System.Web.UI.TemplateInstanceAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.TemplateInstanceAttribute), true); //TemplateInstanceAttribute = templateInstanceAttributes.Length == 0 ? null : templateInstanceAttributes[0]; var custTemplateContainerAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.TemplateContainerAttribute)); if (custTemplateContainerAtts.Any()) { var parseAtt = custTemplateContainerAtts.First(); if (parseAtt.ConstructorArguments.Count == 1) { // public TemplateContainerAttribute(Type containerType); Type val = (Type)parseAtt.ConstructorArguments[0].Value; TemplateContainerAttribute = new System.Web.UI.TemplateContainerAttribute(val); } else if (parseAtt.ConstructorArguments.Count == 2) { // public TemplateContainerAttribute(Type containerType, BindingDirection bindingDirection); Type val = (Type)parseAtt.ConstructorArguments[0].Value; BindingDirection dir = (BindingDirection)parseAtt.ConstructorArguments[1].Value; TemplateContainerAttribute = new System.Web.UI.TemplateContainerAttribute(val, dir); } } else { TemplateContainerAttribute = null; } //System.Web.UI.TemplateContainerAttribute[] templateContainerAttributes = (System.Web.UI.TemplateContainerAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.TemplateContainerAttribute), true); //TemplateContainerAttribute = templateContainerAttributes.Length == 0 ? null : templateContainerAttributes[0]; } else if (IsCollectionProperty) { CollectionItemTypes = GetCollectionItemTypes(PropertyInfo.PropertyType); } }
public void Ctor2_Deny_Unrestricted () { TemplateContainerAttribute tca = new TemplateContainerAttribute (typeof (string), BindingDirection.TwoWay); Assert.AreEqual (typeof (string), tca.ContainerType, "ContainerType"); Assert.AreEqual (BindingDirection.TwoWay, tca.BindingDirection, "BindingDirection"); }
private void AddPropertyInternal(string name, string value, ControlBuilder builder, bool fItemProp) { PropertySetterEntry entry = new PropertySetterEntry(); bool fTemplate = false; string nameForCodeGen = null; entry._value = value; entry._builder = builder; entry._fItemProp = fItemProp; MemberInfo memberInfo = null; PropertyInfo propInfo = null; FieldInfo fieldInfo = null; // Is the property a template? if (builder != null && builder is TemplateBuilder) { fTemplate = true; } if (_objType != null && name != null) // attempt to locate a public property or field // of given name on this type of object { memberInfo = PropertyMapper.GetMemberInfo(_objType, name, out nameForCodeGen); } if (memberInfo != null) // memberInfo may be a PropertyInfo or FieldInfo { if (memberInfo is PropertyInfo) // public property { propInfo = (PropertyInfo)memberInfo; entry._propType = propInfo.PropertyType; if (propInfo.GetSetMethod() == null) // property is readonly { if (builder == null && !_fSupportsAttributes) // only complex property is allowed to be readonly { throw new HttpException( HttpRuntime.FormatResourceString(SR.Property_readonly, name)); } if (builder != null) // complex property is allowed to be readonly // set a flag to note that property is readonly { entry._fReadOnlyProp = true; } else if (_fSupportsAttributes) // allow attribute to be set via SetAttribute { entry._propType = null; entry._name = name; } } } else // public field { fieldInfo = (FieldInfo)memberInfo; entry._propType = fieldInfo.FieldType; } if (entry._propType != null) { entry._propInfo = propInfo; entry._fieldInfo = fieldInfo; entry._name = nameForCodeGen; // If it's a databound prop, we don't want to mess with the value, // since it's a piece of code. if (!_fDataBound) { // check that the property is persistable, i.e., it makes sense to have it in // the aspx template if (_checkPersistable && nameForCodeGen != null) { PropertyDescriptor propDesc = _descriptors[nameForCodeGen]; if (propDesc != null) { if (propDesc.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden)) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Property_Not_Persistable, name)); } } } else { if (_isHtmlControl) { PropertyDescriptor propDesc = _descriptors[nameForCodeGen]; if (propDesc != null) { if (propDesc.Attributes.Contains(HtmlControlPersistableAttribute.No)) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Property_Not_Persistable, name)); } } } } entry._propValue = PropertyConverter.ObjectFromString(entry._propType, memberInfo, entry._value); // use actual property value to get the proper case-sensitive name for enum types if (entry._propType.IsEnum) { if (entry._propValue == null) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Invalid_enum_value, entry._value, name, entry._propType.FullName)); } entry._value = Enum.Format(entry._propType, entry._propValue, "G"); } else if (entry._propType == typeof(Boolean)) { // get the proper case-sensitive value for boolean if (entry._value != null && entry._value.Length > 0) { entry._value = entry._value.ToLower(CultureInfo.InvariantCulture); } else { entry._propValue = true; } } if (fTemplate) { // Check if the property has a TemplateContainerAttribute, and if // it does, get the type out of it. TemplateContainerAttribute templateAttrib = (TemplateContainerAttribute)Attribute.GetCustomAttribute(propInfo, typeof(TemplateContainerAttribute), false); if (templateAttrib != null) { if (!typeof(INamingContainer).IsAssignableFrom(templateAttrib.ContainerType)) { throw new HttpException(HttpRuntime.FormatResourceString( SR.Invalid_template_container, name, templateAttrib.ContainerType.FullName)); } builder._ctrlType = templateAttrib.ContainerType; } } } } } else if (fItemProp) { } else // could not locate a public property or field // determine if there is an event of this name. // do not look for events when running in designer { if (!_fInDesigner && _objType != null && name.Length >= 2 && string.Compare(name.Substring(0, 2), "on", true, CultureInfo.InvariantCulture) == 0) { string eventName = name.Substring(2); if (_eventDescs == null) { _eventDescs = TypeDescriptor.GetEvents(_objType); } EventDescriptor eventFound = _eventDescs.Find(eventName, true); if (eventFound != null) // an Add method has been located { PropertySetterEventEntry eventEntry = new PropertySetterEventEntry(); eventEntry._eventName = eventFound.Name; eventEntry._handlerType = eventFound.EventType; if (value == null || value.Length == 0) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Event_handler_cant_be_empty, name)); } eventEntry._handlerMethodName = value; if (_events == null) { _events = new ArrayList(3); } // add to the list of events _events.Add(eventEntry); return; } } // If attributes are not supported, or the property is a template or a // complex property (which cannot be set through SetAttribute), fail. if (!_fInDesigner && (!_fSupportsAttributes || builder != null)) { if (_objType != null) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Type_doesnt_have_property, _objType.FullName, name)); } if (String.Compare(name, "name", true, CultureInfo.InvariantCulture) != 0) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Templates_cannot_have_properties)); } else { return; } } // use the original property name for generic SetAttribute entry._name = name; } if (_entries == null) { _entries = new ArrayList(3); } // add entry to the list _entries.Add(entry); }