public static TType CreateFromAttributes <TListener>() where TListener : TraceListener { // strategies should have been created Type invocationType = typeof(TType); List <IInterceptor> interceptors = new List <IInterceptor>(); foreach (var attribute in invocationType.GetCustomAttributes(false)) { } 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)) { dynamic data = methodInfo; BaseDiagnosticInterceptor <TListener> interceptor = BaseDiagnosticInterceptorFactory <TListener> .Create(methodAttribute.GetType().FullName, data); if (interceptor != null) { interceptors.Add(interceptor); } } } return(new ProxyGenerator().CreateClassProxy(typeof(TType), interceptors.ToArray()) as TType); }
public static BaseDiagnosticInterceptor <TListener> Create(string type, dynamic data) { // add strategies here BaseDiagnosticInterceptor <TListener> baseInterceptor = null; if (type == "AOPAttributes.MethodTimingAttribute") { baseInterceptor = MethodTimingInterceptorFactory <TListener> .Create(data); } else if (type == "AOPAttributes.MethodDetailLoggingAttribute") { baseInterceptor = MethodDetailsInterceptorFactory <TListener> .Create(data); } return(baseInterceptor); }