public static BaseInterceptor Create(Attribute attribute) { BaseInterceptor baseInterceptor = null; if (attribute.GetType() == typeof(FeatureMethodAttribute)) { baseInterceptor = FeatureMethodInterceptorFactory.Create <FeatureMethodAttribute>((attribute as FeatureMethodAttribute)); } return(baseInterceptor); }
public TType Create() { Type invocationType = typeof(TType); List <IInterceptor> interceptors = new List <IInterceptor>(); bool hasClassLevelAttribute = false; // if we have a class level attribute foreach (var attribute in invocationType.GetCustomAttributes(false)) { // we have to handle all methods if (attribute.GetType() == typeof(FeatureClassAttribute)) { hasClassLevelAttribute = true; MethodInfo[] methodInfos = invocationType.GetMethods(); foreach (MethodInfo methodInfo in methodInfos) { FeatureMethodAttribute featureMethodAttribute = new FeatureMethodAttribute((attribute as FeatureClassAttribute).FeatureType); BaseInterceptor interceptor = BaseInterceptorFactory.Create(featureMethodAttribute as Attribute); if (interceptor != null) { interceptors.Add(interceptor); } } } } // if this is defined at the class level we will ignore any other overrides if (!hasClassLevelAttribute) { // get the custom attributes at the method level MethodInfo[] methodInfos = invocationType.GetMethods(); foreach (MethodInfo methodInfo in methodInfos) { // if we have TimeAllMethods add interceptor for every method on the class foreach (var methodAttribute in methodInfo.GetCustomAttributes(false)) { BaseInterceptor interceptor = BaseInterceptorFactory.Create(methodAttribute as Attribute); if (interceptor != null) { interceptors.Add(interceptor); } } } } return(new ProxyGenerator().CreateClassProxy(typeof(TType), interceptors.ToArray()) as TType); }