public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { if (method.IsAddMethod()) return interceptors.Where(x => x is ListAddInterceptor).ToArray(); if (method.IsSetMethod()) return interceptors.Where(x => x is ListSetInterceptor).ToArray(); if (method.IsRemoveMethod()) return interceptors.Where(x => x is ListRemoveInterceptor).ToArray(); return new IInterceptor[0]; }
/// <summary>Select interceptors which must be applied to the method.</summary> /// <param name="type">The type.</param> /// <param name="method">The method.</param> /// <param name="interceptors">The interceptors.</param> /// <returns>The interceptors after filtering.</returns> public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { if (method.IsGetter()) { var propertyInfo = type.GetProperty(method); if (propertyInfo.IsPropertyWithSelectorAttribute()) { return typeof(BaseHtmlElement).IsAssignableFrom(method.ReturnType) ? interceptors.Where(x => x is PropertyInterceptor).ToArray() : interceptors.Where(x => x is CollectionPropertyInterceptor).ToArray(); } } if (method.IsSetter()) { var propertyInfo = type.GetProperty(method); if (propertyInfo.IsPropertyWithSelectorAttribute()) { return interceptors.Where(x => x is InvalidWriteOperationInterceptor).ToArray(); } } return interceptors.Where(x => !(x is PropertyInterceptor) && !(x is CollectionPropertyInterceptor) && !(x is InvalidWriteOperationInterceptor)).ToArray(); }
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { if (method.IsAddMethod()) return interceptors.Where(x => x is DictionaryAddInterceptor).ToArray(); if (method.IsSetMethod()) return interceptors.Where(x => x is DictionarySetInterceptor).ToArray(); if (method.IsRemoveMethod()) return interceptors.Where(x => x is DictionaryRemoveInterceptor).ToArray(); if (method.IsGetMethod() && !method.Name.StartsWith("get_Count", StringComparison.Ordinal)) return interceptors.Where(x => x is DictionaryGetInterceptor).ToArray(); if (method.IsTryGetValueMethod()) return interceptors.Where(x => x is DictionaryGetInterceptor).ToArray(); return new IInterceptor[0]; }
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { var methodName = method.Name; if (methodName.Equals("GetFilters")) return interceptors.Where(i => i is GetFiltersInterceptor).ToArray(); if (methodName.Equals("InvokeActionMethod")) return interceptors.Where(i => i is InvokeActionMethodInterceptor).ToArray(); if (methodName.Equals("InvokeActionResult")) return interceptors.Where(i => i is InvokeActionResultInterceptor).ToArray(); return null; }
/// <summary> /// The select interceptors. /// </summary> /// <param name="type"> /// The type. /// </param> /// <param name="method"> /// The method. /// </param> /// <param name="interceptors"> /// The interceptors. /// </param> /// <returns> /// The <see cref="IInterceptor[]" />. /// </returns> public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { string name = method.Name; if (method.IsSpecialName) { if (name.StartsWith(AopConstants.PropertyGetter, StringComparison.Ordinal)) name = name.Remove(0, AopConstants.PropertyGetter.Length); if (name.StartsWith(AopConstants.PropertySetter, StringComparison.Ordinal)) name = name.Remove(0, AopConstants.PropertySetter.Length); if (name.StartsWith(AopConstants.EventAdder, StringComparison.Ordinal)) name = name.Remove(0, AopConstants.EventAdder.Length); if (name.StartsWith(AopConstants.EventRemover, StringComparison.Ordinal)) name = name.Remove(0, AopConstants.EventRemover.Length); } return interceptors.Where( inter => { var sinter = inter as ISpecificInterceptor; if (sinter != null) { return sinter.Name == name || sinter.Name == AopConstants.InternalUniversalInterceptorName; } return true; }).OrderBy( inter => { var sinter = inter as ISpecificInterceptor; return sinter == null ? 0 : sinter.Order; }).ToArray(); }
/// <summary> /// Selects the interceptors that should intercept calls to the given <paramref name="method" />. /// </summary> /// <param name="type">The type declaring the method to intercept.</param> /// <param name="method">The method that will be intercepted.</param> /// <param name="interceptors">All interceptors registered with the proxy.</param> /// <returns> /// An array of interceptors to invoke upon calling the <paramref name="method" />. /// </returns> /// <remarks> /// This method is called only once per proxy instance, upon the first call to the /// <paramref name="method" />. Either an empty array or null are valid return values to indicate /// that no interceptor should intercept calls to the method. Although it is not advised, it is /// legal to return other <see cref="T:Castle.DynamicProxy.IInterceptor" /> implementations than these provided in /// <paramref name="interceptors" />. /// </remarks> public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { return interceptors.Where(i => { var ai = i as AlternateTypeToCastleInterceptorAdapter; return ai != null && ai.MethodToImplement == method; }).ToArray(); }
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { var allowNullActuals = method.GetCustomAttributes(typeof (AllowNullActualAttribute), true).Length > 0; if (!allowNullActuals) { return interceptors; } return interceptors.Where(i => !(i is NullActualInterceptorBase)).ToArray(); }
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { if (method.DeclaringType == typeof(IMockInstance)) return interceptors .Where(x => (x is MockInterceptor)) .ToArray(); if (method.DeclaringType == typeof(IMockExpectationContainer)) return interceptors .Where(x => (x is MockInterceptor)) .ToArray(); if (method.DeclaringType == typeof(object)) return interceptors .Where(x => (x is ObjectInterceptor)) .ToArray(); return interceptors .Where(x => (x is ProxyInterceptor)) .ToArray(); }
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { Logger.Trace(m => m("Called interceptor selector for method {0}.{1} and interceptors {2}", type.FullName, method.Name, interceptors .Select(i => i.GetType().Name) .Aggregate((s1, s2) => s1 + " " + s2))); var applicableMappings = GetInterceptorsApplicableTo(type, method); var applicableInterceptors = interceptors.Where(x => applicableMappings.Any(m => m.InterceptorType == x.GetType())).ToArray(); Logger.TraceFormat("Applying {0} interceptors[{1}] to method {2}.{3}...", applicableInterceptors.Length, string.Join(", ", applicableInterceptors.Select(x => x.GetType().Name).ToArray()), type.FullName, method.Name); return applicableInterceptors; }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="method"></param> /// <param name="interceptors"></param>W /// <returns></returns> public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { if (!metaInfo.Contains(method)) { if (IsInterfaceMappingCandidate(type, method)) { var map = type.GetInterfaceMap(method.DeclaringType); var index = Array.IndexOf(map.InterfaceMethods, method); if (index >= 0 && metaInfo.Contains(map.TargetMethods[index])) return interceptors; } interceptors = interceptors.Where(i => i is SynchronizeInterceptor == false).ToArray(); } if (existingSelector != null) { interceptors = existingSelector.SelectInterceptors(type, method, interceptors); } return interceptors; }
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { return interceptors.Where(i => i.GetType() == interceptorType).ToArray(); }
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { return method.IsSetMethod() ? interceptors.Where(i => i is RedisObjectSetInterceptor).ToArray() : interceptors.Where(i => i is GeneralGetInterceptor).ToArray(); }