protected override void PreFilterProperties(System.Collections.IDictionary properties) { base.PreFilterProperties(properties); if (!DesignerFeaturesEnabled) { return; } string[] propertyNames = new string[properties.Keys.Count]; properties.Keys.CopyTo(propertyNames, 0); foreach (string propertyName in propertyNames) { PropertyDescriptor pd = (PropertyDescriptor)properties[propertyName]; if (propertyName == "TargetControlID") { // get the control type. // TargetControlTypeAttribute targetControlType = (TargetControlTypeAttribute)TypeDescriptor.GetAttributes(ExtenderControl)[typeof(TargetControlTypeAttribute)]; if (targetControlType != null && !targetControlType.IsDefaultAttribute()) { Type genericType = typeof(TypedControlIDConverter <>).MakeGenericType(targetControlType.TargetControlType); properties[propertyName] = TypeDescriptor.CreateProperty(pd.ComponentType, pd, new TypeConverterAttribute(genericType)); } } ExtenderControlPropertyAttribute extenderPropAttr = (ExtenderControlPropertyAttribute)pd.Attributes[typeof(ExtenderControlPropertyAttribute)]; if (extenderPropAttr == null || !extenderPropAttr.IsScriptProperty) { continue; } BrowsableAttribute browsableAttr = (BrowsableAttribute)pd.Attributes[typeof(BrowsableAttribute)]; if (browsableAttr.Browsable == BrowsableAttribute.Yes.Browsable) { properties[propertyName] = TypeDescriptor.CreateProperty(pd.ComponentType, pd, BrowsableAttribute.No, ExtenderVisiblePropertyAttribute.Yes); } } }
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { PropertyDescriptorCollection propertyDescriptorCollection = TypeDescriptor.GetProperties(this.Target); if (this.propsToHide != null && this.propsToHide.Length > 0) { List <PropertyDescriptor> list = new List <PropertyDescriptor>(); for (int i = 0; i < propertyDescriptorCollection.Count; i++) { PropertyDescriptor prop = propertyDescriptorCollection[i]; ExtenderControlPropertyAttribute extenderControlPropertyAttribute = (ExtenderControlPropertyAttribute)prop.Attributes[typeof(ExtenderControlPropertyAttribute)]; if (extenderControlPropertyAttribute != null) { ExtenderVisiblePropertyAttribute extenderVisiblePropertyAttribute = (ExtenderVisiblePropertyAttribute)prop.Attributes[typeof(ExtenderVisiblePropertyAttribute)]; if (extenderVisiblePropertyAttribute != null && extenderVisiblePropertyAttribute.Value) { int num = Array.FindIndex <string>(this.propsToHide, (string s) => s == prop.Name); if (num == -1) { IDReferencePropertyAttribute idreferencePropertyAttribute = (IDReferencePropertyAttribute)prop.Attributes[typeof(IDReferencePropertyAttribute)]; Attribute attribute = prop.Attributes[typeof(TypeConverterAttribute)]; if (idreferencePropertyAttribute != null && !idreferencePropertyAttribute.IsDefaultAttribute()) { Type type = typeof(TypedControlIDConverter <Control>).GetGenericTypeDefinition(); type = type.MakeGenericType(new Type[] { idreferencePropertyAttribute.ReferencedControlType }); attribute = new TypeConverterAttribute(type); } prop = TypeDescriptor.CreateProperty(prop.ComponentType, prop, new Attribute[] { BrowsableAttribute.Yes, attribute }); list.Add(prop); } } } } propertyDescriptorCollection = new PropertyDescriptorCollection(list.ToArray()); } return(propertyDescriptorCollection); }
// Token: 0x06000048 RID: 72 RVA: 0x00002920 File Offset: 0x00000B20 protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); string[] array = new string[properties.Keys.Count]; properties.Keys.CopyTo(array, 0); foreach (string text in array) { PropertyDescriptor propertyDescriptor = (PropertyDescriptor)properties[text]; if (text == "TargetControlID") { TargetControlTypeAttribute targetControlTypeAttribute = (TargetControlTypeAttribute)TypeDescriptor.GetAttributes(this.ExtenderControl)[typeof(TargetControlTypeAttribute)]; if (targetControlTypeAttribute != null && !targetControlTypeAttribute.IsDefaultAttribute()) { Type type = typeof(TypedControlIDConverter <>).MakeGenericType(new Type[] { targetControlTypeAttribute.TargetControlType }); properties[text] = TypeDescriptor.CreateProperty(propertyDescriptor.ComponentType, propertyDescriptor, new Attribute[] { new TypeConverterAttribute(type) }); } } ExtenderControlPropertyAttribute extenderControlPropertyAttribute = (ExtenderControlPropertyAttribute)propertyDescriptor.Attributes[typeof(ExtenderControlPropertyAttribute)]; if (extenderControlPropertyAttribute != null && extenderControlPropertyAttribute.IsScriptProperty) { BrowsableAttribute browsableAttribute = (BrowsableAttribute)propertyDescriptor.Attributes[typeof(BrowsableAttribute)]; if (browsableAttribute.Browsable == BrowsableAttribute.Yes.Browsable) { properties[text] = TypeDescriptor.CreateProperty(propertyDescriptor.ComponentType, propertyDescriptor, new Attribute[] { BrowsableAttribute.No, ExtenderVisiblePropertyAttribute.Yes }); } } } }
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { // we'll walk the extenders properties looking for the ones marked as ExtenderControl properties. // for those, we'll make them visible, then add them to the list. // PropertyDescriptorCollection propCollection = TypeDescriptor.GetProperties(this.Target); if (_propsToHide != null && _propsToHide.Length > 0) { List <PropertyDescriptor> props = new List <PropertyDescriptor>(); for (int i = 0; i < propCollection.Count; i++) { PropertyDescriptor prop = propCollection[i]; ExtenderControlPropertyAttribute extenderPropAttr = (ExtenderControlPropertyAttribute)prop.Attributes[typeof(ExtenderControlPropertyAttribute)]; if (extenderPropAttr == null) { continue; } ExtenderVisiblePropertyAttribute evpa = (ExtenderVisiblePropertyAttribute)prop.Attributes[typeof(ExtenderVisiblePropertyAttribute)]; if (evpa == null || !evpa.Value) { // if there isn't an ExtenderVisiblePropertyAttribute on here (the designer adds this), // then we shouldn't process it. Usually this means the developer marked it as Browsable.False. // continue; } // if the name is in the list, remove browsable from the name. // int index = Array.FindIndex <string>(_propsToHide, delegate(string s) { return(s == prop.Name); } ); if (index != -1) { continue; } // add the drop down if it is selectable. // IDReferencePropertyAttribute controlRefAttr = (IDReferencePropertyAttribute)prop.Attributes[typeof(IDReferencePropertyAttribute)]; Attribute tca = prop.Attributes[typeof(TypeConverterAttribute)]; if (controlRefAttr != null && !controlRefAttr.IsDefaultAttribute()) { Type t = typeof(TypedControlIDConverter <Control>).GetGenericTypeDefinition(); t = t.MakeGenericType(controlRefAttr.ReferencedControlType); tca = new TypeConverterAttribute(t); } prop = TypeDescriptor.CreateProperty(prop.ComponentType, prop, BrowsableAttribute.Yes, tca); // add it to the list. // props.Add(prop); } propCollection = new PropertyDescriptorCollection(props.ToArray()); } return(propCollection); }
public static void DescribeComponent(object instance, ScriptComponentDescriptor descriptor, IUrlResolutionService urlResolver, IControlResolver controlResolver) { // validate preconditions if (instance == null) { throw new ArgumentNullException("instance"); } if (descriptor == null) { throw new ArgumentNullException("descriptor"); } if (urlResolver == null) { urlResolver = instance as IUrlResolutionService; } if (controlResolver == null) { controlResolver = instance as IControlResolver; } // describe properties PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance); foreach (PropertyDescriptor prop in properties) { ExtenderControlPropertyAttribute propAttr = null; ExtenderControlEventAttribute eventAttr = null; string propertyName = prop.Name; // Try getting a property attribute propAttr = (ExtenderControlPropertyAttribute)prop.Attributes[typeof(ExtenderControlPropertyAttribute)]; if (propAttr == null || !propAttr.IsScriptProperty) { // Try getting an event attribute eventAttr = (ExtenderControlEventAttribute)prop.Attributes[typeof(ExtenderControlEventAttribute)]; if (eventAttr == null || !eventAttr.IsScriptEvent) { continue; } } // attempt to rename the property/event ClientPropertyNameAttribute nameAttr = (ClientPropertyNameAttribute)prop.Attributes[typeof(ClientPropertyNameAttribute)]; if (!string.IsNullOrEmpty(nameAttr.PropertyName)) { propertyName = nameAttr.PropertyName; } object value = prop.GetValue(instance); if (value == null) { continue; } // determine whether to serialize the value of a property. readOnly properties should always be serialized bool serialize = prop.ShouldSerializeValue(instance) || prop.IsReadOnly; if (serialize) { // get the value of the property, skip if it is null Control c = null; // convert and resolve the value if (eventAttr != null && prop.PropertyType != typeof(String)) { throw new InvalidOperationException( "ExtenderControlEventAttribute can only be applied to a property with a PropertyType of System.String."); } else { if (!prop.PropertyType.IsPrimitive && !prop.PropertyType.IsEnum) { // Check if we can use any of our custom converters // (first do a direct lookup on the property type, // but also check all of its base types if nothing // was found) Converter <object, string> customConverter = null; if (!_customConverters.TryGetValue(prop.PropertyType, out customConverter)) { foreach (KeyValuePair <Type, Converter <object, string> > pair in _customConverters) { if (prop.PropertyType.IsSubclassOf(pair.Key)) { customConverter = pair.Value; break; } } } // Use the custom converter if found, otherwise use // its current type converter if (customConverter != null) { value = customConverter(value); } else { // Determine if we should let ASP.NET AJAX handle this type of conversion, as it supports JSON serialization if (propAttr != null && propAttr.UseJsonSerialization) { if (value is IEnumerable) { List <object> lst = new List <object>(); foreach (object a in (IEnumerable)value) { object b; Type typ = a.GetType(); if (a as IUICollectionItem != null) { b = a is UriValue ? urlResolver.ResolveClientUrl(((UriValue)a).Value.ToString()) : ((IUICollectionItem)a).Value; } else if (typ.IsPrimitive || typ.IsValueType) { b = a; } else { b = BuildGraph(a, urlResolver, controlResolver); } if (b != null) { lst.Add(b); } } if (lst.Count > 0) { value = lst; } } else if (value.GetType().IsPrimitive || value.GetType().IsValueType) { } else { value = BuildGraph(value, urlResolver, controlResolver); } // Use ASP.NET JSON serialization } else { // Use the property's own converter TypeConverter conv = prop.Converter; value = conv.ConvertToString(null, CultureInfo.InvariantCulture, value); } } } if (prop.Attributes[typeof(IDReferencePropertyAttribute)] != null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (prop.Attributes[typeof(UrlPropertyAttribute)] != null && urlResolver != null) { value = urlResolver.ResolveClientUrl((string)value); } } // add the value as an appropriate description if (eventAttr != null) { descriptor.AddEvent(propertyName, (string)value); } else if (prop.Attributes[typeof(ElementReferenceAttribute)] != null) { if (c == null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (c != null) { value = c.ClientID; } descriptor.AddElementProperty(propertyName, (string)value); } else if (prop.Attributes[typeof(ComponentReferenceAttribute)] != null) { if (c == null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (c != null) { ExtenderControlBase ex = c as ExtenderControlBase; if (ex != null && ex.BehaviorID.Length > 0) { value = ex.BehaviorID; } else { value = c.ClientID; } } descriptor.AddComponentProperty(propertyName, (string)value); } else { if (c != null) { value = c.ClientID; } descriptor.AddProperty(propertyName, value); } } } // determine if we should describe methods foreach ( MethodInfo method in instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)) { ExtenderControlMethodAttribute methAttr = (ExtenderControlMethodAttribute) Attribute.GetCustomAttribute(method, typeof(ExtenderControlMethodAttribute)); if (methAttr == null || !methAttr.IsScriptMethod) { continue; } // We only need to support emitting the callback target and registering the WebForms.js script if there is at least one valid method Control control = instance as Control; if (control != null) { // Force WebForms.js control.Page.ClientScript.GetCallbackEventReference(control, null, null, null); // Add the callback target descriptor.AddProperty("_callbackTarget", control.UniqueID); } break; } }
private static Dictionary <string, object> BuildGraph(object obj, IUrlResolutionService uriResolver, IControlResolver controlResolver) { Dictionary <string, object> dict = new Dictionary <string, object>(); PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(obj); foreach (PropertyDescriptor pd in pdc) { ExtenderControlPropertyAttribute ecpa = GetAttribute <ExtenderControlPropertyAttribute>(pd); ClientPropertyNameAttribute cpna = GetAttribute <ClientPropertyNameAttribute>(pd); IDReferencePropertyAttribute idr = GetAttribute <IDReferencePropertyAttribute>(pd); UrlPropertyAttribute ura = GetAttribute <UrlPropertyAttribute>(pd); ExtenderControlMethodAttribute ecma = GetAttribute <ExtenderControlMethodAttribute>(pd); ExtenderControlEventAttribute ecea = GetAttribute <ExtenderControlEventAttribute>(pd); ElementReferenceAttribute era = GetAttribute <ElementReferenceAttribute>(pd); ComponentReferenceAttribute cra = GetAttribute <ComponentReferenceAttribute>(pd); if (ecpa == null && cra == null && cpna == null && era == null) { continue; } string propName = cpna != null && !string.IsNullOrEmpty(cpna.PropertyName) ? cpna.PropertyName : pd.Name; if (propName == "ClientClassName") { propName = "typeToBuild"; } object o = null; object value = pd.GetValue(obj); if (value == null) { continue; } if (value as IClientClass != null && ((IClientClass)value).NotSet) { continue; } if (value as ClientEvalScript != null && string.IsNullOrEmpty((value as ClientEvalScript).ClientScript)) { continue; } if (pd.PropertyType == typeof(string)) { o = value; if (ura != null) { o = uriResolver.ResolveClientUrl((string)o); } else if (idr != null || cra != null) { o = BuildGraph(new Reference { ReferenceType = ReferenceType.Component, ClientId = controlResolver.ResolveControl((string)o).ClientID }, uriResolver, controlResolver); } else if (era != null) { Control c = controlResolver.ResolveControl((string)o); o = BuildGraph( new Reference { ReferenceType = ReferenceType.Element, ClientId = c == null ? (string)o : c.ClientID }, uriResolver, controlResolver); } } else if (value is IEnumerable) { List <object> lst = new List <object>(); foreach (object a in (IEnumerable)value) { object b; if (a as IUICollectionItem != null) { b = a is UriValue ? uriResolver.ResolveClientUrl(((UriValue)a).Value.ToString()) : ((IUICollectionItem)a).Value; } else { b = BuildGraph(a, uriResolver, controlResolver); } if (b != null) { lst.Add(b); } } if (lst.Count > 0) { o = lst; } } else if (pd.PropertyType.IsEnum) { o = Enum.GetName(pd.PropertyType, value); } else if (pd.PropertyType.IsPrimitive || pd.PropertyType.IsValueType) { o = value; } else { o = BuildGraph(value, uriResolver, controlResolver); } if (o != null) { dict.Add(propName, o); } } return(dict.Count > 0 ? dict : null); }