public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
        {
            if (typeof (Task).IsAssignableFrom(method.ReturnType))
            {
                return interceptors.OfType<WampRpcClientAsyncInterceptor>().Cast<IInterceptor>().ToArray();
            }

            return interceptors.OfType<WampRpcClientSyncInterceptor>().Cast<IInterceptor>().ToArray();
        }
            public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
            {
                var result = method.Name == "GetI"
                    ? interceptors.OfType<AddOneInterceptor>().ToArray<IInterceptor>()
                    : interceptors.OfType<AddTenInterceptor>().ToArray<IInterceptor>();

                if (result.Length == 0)
                    throw new InvalidOperationException("No interceptors for method " + method.Name);

                return result;
            }
示例#3
0
        IInterceptor[] IInterceptorSelector.SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
        {
            if (interceptors.Length == 0)
                return interceptors;

            var markers = new List<MarkerBaseAttribute>();
            if (type != null)
                markers.AddRange(type.GetCustomAttributes(typeof(MarkerBaseAttribute), true).Cast<MarkerBaseAttribute>());

            if (method != null)
                markers.AddRange(method.GetCustomAttributes(typeof(MarkerBaseAttribute), true).Cast<MarkerBaseAttribute>());

            if (markers.Count == 0) // no marker attributes found, no ordering required
                return interceptors;

            markers.Sort((a, b) => a.Order.CompareTo(b.Order));

            var sorted = new List<IInterceptor>();
            for (int i = 0; i < markers.Count; ++i)
            {
                var providers = interceptors.OfType<IInterceptorMarkerProvider>();
                var markerType = markers[i].GetType();
                var matchingInterceptor = providers.FirstOrDefault(x => x.MarkerType == markerType) as IInterceptor;
                if (matchingInterceptor != null)
                    sorted.Add(matchingInterceptor);
            }
            return sorted.ToArray();
        }
 public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
 {
     var filteringInterceptor = interceptors.OfType<FilteringInterceptor>().SingleOrDefault();
     if(filteringInterceptor != null)
     {
         filteringInterceptor.PredicatesToSatisfy = _predicates;
     }
     return interceptors;
 }
 public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
 {
     return method.Name == "GetVisitCount"
         ? interceptors.OfType<AddOneInterceptor>().ToArray<IInterceptor>()
         : interceptors.OfType<AddTenInterceptor>().ToArray<IInterceptor>();
 }
 public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
 {
     return method.Name == "DoWork"
         ? interceptors.OfType<PrependInterceptor>().ToArray<IInterceptor>()
         : interceptors.OfType<AppendInterceptor>().ToArray<IInterceptor>();
 }