// Token: 0x06000082 RID: 130 RVA: 0x000030E0 File Offset: 0x000012E0 public override bool Equals(object obj) { if (object.ReferenceEquals(obj, this)) { return(true); } ExtenderControlMethodAttribute extenderControlMethodAttribute = obj as ExtenderControlMethodAttribute; return(extenderControlMethodAttribute != null && extenderControlMethodAttribute.isScriptMethod == this.isScriptMethod); }
/// <summary> /// Tests for object equality /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (object.ReferenceEquals(obj, this)) { return(true); } ExtenderControlMethodAttribute other = obj as ExtenderControlMethodAttribute; if (other != null) { return(other._isScriptMethod == _isScriptMethod); } return(false); }
public static void DescribeComponent(object instance, IScriptComponentDescriptor 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; ClientPropertyNameAttribute nameAttr = null; IDReferencePropertyAttribute idRefAttr = null; UrlPropertyAttribute urlAttr = null; ElementReferenceAttribute elementAttr = null; ComponentReferenceAttribute compAttr = null; foreach (Attribute attr in prop.Attributes) { Type attrType = attr.GetType(); if (attrType == typeof(ExtenderControlPropertyAttribute)) { propAttr = attr as ExtenderControlPropertyAttribute; } else if (attrType == typeof(ExtenderControlEventAttribute)) { eventAttr = attr as ExtenderControlEventAttribute; } else if (attrType == typeof(ClientPropertyNameAttribute)) { nameAttr = attr as ClientPropertyNameAttribute; } else if (attrType == typeof(IDReferencePropertyAttribute)) { idRefAttr = attr as IDReferencePropertyAttribute; } else if (attrType == typeof(UrlPropertyAttribute)) { urlAttr = attr as UrlPropertyAttribute; } else if (attrType == typeof(ElementReferenceAttribute)) { elementAttr = attr as ElementReferenceAttribute; } else if (attrType == typeof(ComponentReferenceAttribute)) { compAttr = attr as ComponentReferenceAttribute; } } string propertyName = prop.Name; // Try getting a property attribute if (propAttr == null || !propAttr.IsScriptProperty) { // Try getting an event attribute if (eventAttr == null || !eventAttr.IsScriptEvent) { continue; } } // attempt to rename the property/event if (nameAttr != null && !string.IsNullOrEmpty(nameAttr.PropertyName)) { propertyName = nameAttr.PropertyName; } // 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; object value = prop.GetValue(instance); if (value == null) { continue; } // 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) { // Use ASP.NET JSON serialization } else { // Use the property's own converter TypeConverter conv = prop.Converter; if (value.GetType() == typeof(DateTime)) { value = ((DateTime)value).ToString("s", CultureInfo.InvariantCulture); } else { value = conv.ConvertToString(null, CultureInfo.InvariantCulture, value); } } } } if (idRefAttr != null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (urlAttr != 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 (elementAttr != null) { if (c == null && controlResolver != null) { c = controlResolver.ResolveControl((string)value); } if (c != null) { value = c.ClientID; } descriptor.AddElementProperty(propertyName, (string)value); } else if (compAttr != 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; } }
// Token: 0x060000E6 RID: 230 RVA: 0x000039C0 File Offset: 0x00001BC0 public static string ExecuteCallbackMethod(Control control, string callbackArgument) { Type type = control.GetType(); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); Dictionary <string, object> dictionary = javaScriptSerializer.DeserializeObject(callbackArgument) as Dictionary <string, object>; string text = (string)dictionary["name"]; object[] array = (object[])dictionary["args"]; string clientState = (string)dictionary["state"]; IClientStateManager clientStateManager = control as IClientStateManager; if (clientStateManager != null && clientStateManager.SupportsClientState) { clientStateManager.LoadClientState(clientState); } object value = null; string text2 = null; try { MethodInfo method = type.GetMethod(text, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public); if (method == null) { throw new MissingMethodException(type.FullName, text); } ParameterInfo[] parameters = method.GetParameters(); ExtenderControlMethodAttribute extenderControlMethodAttribute = (ExtenderControlMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ExtenderControlMethodAttribute)); if (extenderControlMethodAttribute == null || !extenderControlMethodAttribute.IsScriptMethod || array.Length != parameters.Length) { throw new MissingMethodException(type.FullName, text); } object[] array2 = new object[array.Length]; for (int i = 0; i < array2.Length; i++) { if (array[i] != null) { array2[i] = Convert.ChangeType(array[i], parameters[i].ParameterType, CultureInfo.InvariantCulture); } } value = method.Invoke(control, array2); } catch (Exception innerException) { if (innerException is TargetInvocationException) { innerException = innerException.InnerException; } text2 = innerException.GetType().FullName + ":" + innerException.Message; } Dictionary <string, object> dictionary2 = new Dictionary <string, object>(); if (text2 == null) { dictionary2["result"] = value; if (clientStateManager != null && clientStateManager.SupportsClientState) { dictionary2["state"] = clientStateManager.SaveClientState(); } } else { dictionary2["error"] = text2; } return(javaScriptSerializer.Serialize(dictionary2)); }
public static string ExecuteCallbackMethod(Control control, string callbackArgument) { Type controlType = control.GetType(); // Deserialize the callback JSON into CLR objects JavaScriptSerializer js = new JavaScriptSerializer(); Dictionary <string, object> callInfo = js.DeserializeObject(callbackArgument) as Dictionary <string, object>; // Get the call information string methodName = (string)callInfo["name"]; object[] args = (object[])callInfo["args"]; string clientState = (string)callInfo["state"]; // Attempt to load the client state IClientStateManager csm = control as IClientStateManager; if (csm != null && csm.SupportsClientState) { csm.LoadClientState(clientState); } // call the method object result = null; string error = null; try { // Find a matching static or instance method. Only public methods can be invoked MethodInfo mi = controlType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (mi == null) { throw new MissingMethodException(controlType.FullName, methodName); } // Verify that the method has the corrent number of parameters as well as the ExtenderControlMethodAttribute ParameterInfo[] methodParams = mi.GetParameters(); ExtenderControlMethodAttribute methAttr = (ExtenderControlMethodAttribute)Attribute.GetCustomAttribute(mi, typeof(ExtenderControlMethodAttribute)); if (methAttr == null || !methAttr.IsScriptMethod || args.Length != methodParams.Length) { throw new MissingMethodException(controlType.FullName, methodName); } // Convert each argument to the parameter type if possible // NOTE: I'd rather have the ObjectConverter from within System.Web.Script.Serialization namespace for this object[] targetArgs = new object[args.Length]; for (int i = 0; i < targetArgs.Length; i++) { if (args[i] == null) { continue; } targetArgs[i] = Convert.ChangeType(args[i], methodParams[i].ParameterType, CultureInfo.InvariantCulture); } result = mi.Invoke(control, targetArgs); } catch (Exception ex) { // Catch the exception information to relay back to the client if (ex is TargetInvocationException) { ex = ex.InnerException; } error = ex.GetType().FullName + ":" + ex.Message; } // return the result Dictionary <string, object> resultInfo = new Dictionary <string, object>(); if (error == null) { resultInfo["result"] = result; if (csm != null && csm.SupportsClientState) { resultInfo["state"] = csm.SaveClientState(); } } else { resultInfo["error"] = error; } // Serialize the result info into JSON return(js.Serialize(resultInfo)); }