/// <summary>Create a MethodInvoker from the delegate based on the attributeType. Ensure that the decorated method has a valid set of parameters.</summary> /// <param name="attributeType">The attribute type.</param> /// <param name="target">The target.</param> /// <param name="expectedParamTypes">The expected param types.</param> /// <returns>The Spring.Retry.Classify.Util.IMethodInvoker.</returns> public static IMethodInvoker GetMethodInvokerByAttribute(Type attributeType, object target, params Type[] expectedParamTypes) { AssertUtils.AssertArgumentType(attributeType, "attributeType", typeof(Attribute), "attributeType should be an Attribute"); var mi = GetMethodInvokerByAttribute(attributeType, target); var targetClass = (target is IAdvised) ? ((IAdvised)target).TargetSource.TargetType : target.GetType(); if (mi != null) { var methods = targetClass.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var method in methods) { var attribute = method.FindAttribute(attributeType); if (attribute != null) { var paramTypes = method.GetParameters(); if (paramTypes.Length > 0) { var errorMsg = "The method [" + method.Name + "] on target class [" + targetClass.Name + "] is incompatable with the signature [" + GetParamTypesString(expectedParamTypes) + "] expected for the attribute [" + attributeType.Name + "]."; AssertUtils.IsTrue(paramTypes.Length == expectedParamTypes.Length, errorMsg); for (var i = 0; i < paramTypes.Length; i++) { AssertUtils.IsTrue(expectedParamTypes[i].IsAssignableFrom(paramTypes[i].ParameterType), errorMsg); } } } } } return(mi); }
/// <summary> /// Adds an element with the specified key and value into the <see cref="T:System.Collections.Hashtable"/>. /// </summary> /// <param name="key">The key of the element to add.</param> /// <param name="value">The value of the element to add. The value can be null.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key"/> is null. </exception> /// <exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.Hashtable"/>. /// or key is not a string or value is not an IExceptionHandler.</exception> /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Hashtable"/> is read-only.-or- The <see cref="T:System.Collections.Hashtable"/> has a fixed size. </exception> public override void Add(object key, object value) { AssertUtils.AssertArgumentType(key, "key", typeof(string), "Key must be a string"); AssertUtils.AssertArgumentType(value, "value", typeof(IExceptionHandler), "Key must be a IExceptionHandler"); this.Add((string)key, (IExceptionHandler)value); }
public override void Add(object key, object value) { AssertUtils.AssertArgumentType(key, "key", typeof(string), "Key must be a string"); AssertUtils.AssertArgumentType(value, "value", typeof(IObjectDefinition), "Key must be a string"); this.Add((string)key, (IObjectDefinition)value); }