internal IEnumerable <IInterceptorProvider> GetProvidersForClass(object target) { var providers = target.GetType().GetTypeInfo().GetCustomAttributes().OfType <IInterceptorProvider>(); foreach (var provider in providers) { IAttributeCollector collector = provider as IAttributeCollector; if (null != collector) { collector.Attributes = target.GetType().GetTypeInfo().GetCustomAttributes(); } } return(providers); }
internal IEnumerable <IInterceptorProvider> GetProvidersForMethod(MethodInfo proxyMethod, Type targetType, IEnumerable <IInterceptorProvider> providersForClass) { MethodInfo targetMethod = targetType.GetTypeInfo().GetMethods().FirstOrDefault(it => it.Matches(proxyMethod)); if (null == targetMethod) { return(new IInterceptorProvider[0]); } NonInterceptableAttribute nonInterceptableAttribute = targetMethod.GetCustomAttribute <NonInterceptableAttribute>() ?? targetType.GetTypeInfo().GetCustomAttribute <NonInterceptableAttribute>(); if (null != nonInterceptableAttribute) { return(new IInterceptorProvider[0]); } var providers = targetMethod.GetCustomAttributes().OfType <IInterceptorProvider>().ToList(); //Set Attributes foreach (var provider in providers) { IAttributeCollector collector = provider as IAttributeCollector; if (null != collector) { List <Attribute> attributes = new List <Attribute>(); attributes.AddRange(targetMethod.GetCustomAttributes()); foreach (var attribute in targetType.GetTypeInfo().GetCustomAttributes()) { if (!attribute.AllowMultiple() && attributes.Any(it => it.GetType() == attribute.GetType())) { continue; } attributes.Add(attribute); } collector.Attributes = attributes; } } foreach (var provider in providersForClass) { if (!provider.AllowMultiple && providers.Any(it => it.GetType() == provider.GetType())) { continue; } providers.Add(provider); } return(providers); }