/// <summary> /// Applies all interceptors for the specified proxy template. /// </summary> /// <param name="proxyTemplate">The proxy template.</param> /// <param name="interceptors">The interceptors.</param> public void ApplyInterceptors(IProxyTemplate proxyTemplate, IEnumerable <IInterceptor> interceptors) { if (proxyTemplate == null) { throw new ArgumentNullException("proxyTemplate"); } if (interceptors == null) { throw new ArgumentNullException("interceptors"); } // Apply type interception behaviors. var typeInterceptors = ApplyInterceptionBehaviors(proxyTemplate.DeclaringType, interceptors); // Apply event interception behaviors. foreach (var eventInfo in proxyTemplate.InterceptedEvents) { ApplyInterceptors(eventInfo, typeInterceptors); } // Apply property interception behaviors. foreach (var propertyInfo in proxyTemplate.InterceptedProperties) { ApplyInterceptors(propertyInfo, typeInterceptors); } // Apply method interception behaviors. foreach (var methodInfo in proxyTemplate.InterceptedMethods) { ApplyInterceptors(methodInfo, typeInterceptors); } }
/// <summary> /// Applies all interceptors for the specified proxy template. /// </summary> /// <param name="proxyTemplate">The proxy template.</param> /// <param name="interceptors">The interceptors.</param> public void ApplyInterceptors(IProxyTemplate proxyTemplate, IEnumerable<IInterceptor> interceptors) { if (proxyTemplate == null) throw new ArgumentNullException("proxyTemplate"); if (interceptors == null) throw new ArgumentNullException("interceptors"); // Apply type interception behaviors. var typeInterceptors = ApplyInterceptionBehaviors(proxyTemplate.DeclaringType, interceptors); // Apply event interception behaviors. foreach (var eventInfo in proxyTemplate.InterceptedEvents) { ApplyInterceptors(eventInfo, typeInterceptors); } // Apply property interception behaviors. foreach (var propertyInfo in proxyTemplate.InterceptedProperties) { ApplyInterceptors(propertyInfo, typeInterceptors); } // Apply method interception behaviors. foreach (var methodInfo in proxyTemplate.InterceptedMethods) { ApplyInterceptors(methodInfo, typeInterceptors); } }
public DynamicProxyCreationBenchmark() { var proxyBuilder = new ProxyBuilder(); var proxyGenerator = new ProxyGenerator(); var proxyFactory = new ProxyFactory(); _proxyType = proxyBuilder.GetProxyType(new ProxyDefinition(typeof(TestClass), true).Implement(() => new LightInjectInterceptor())); _dynamicProxyType = proxyGenerator.ProxyBuilder.CreateClassProxyType(typeof(TestClass), Type.EmptyTypes, ProxyGenerationOptions.Default); _nProxyInterceptor = new NProxyInterceptor(); _nproxyTemplate = proxyFactory.GetProxyTemplate(typeof(TestClass), Enumerable.Empty<Type>()); }
public DynamicProxyCreationBenchmark() { var proxyBuilder = new ProxyBuilder(); var proxyGenerator = new ProxyGenerator(); var proxyFactory = new ProxyFactory(); _proxyType = proxyBuilder.GetProxyType(new ProxyDefinition(typeof(TestClass), true).Implement(() => new LightInjectInterceptor())); _dynamicProxyType = proxyGenerator.ProxyBuilder.CreateClassProxyType(typeof(TestClass), Type.EmptyTypes, ProxyGenerationOptions.Default); _nProxyInterceptor = new NProxyInterceptor(); _nproxyTemplate = proxyFactory.GetProxyTemplate(typeof(TestClass), Enumerable.Empty <Type>()); }
/// <summary> /// Creates an invocation handler. /// </summary> /// <param name="proxyTemplate">The proxy template.</param> /// <param name="defaultInterceptors">The default interceptors.</param> /// <returns>The invocation handler.</returns> private IInvocationHandler CreateInvocationHandler(IProxyTemplate proxyTemplate, params IInterceptor[] defaultInterceptors) { var invocationHandler = new InterceptorInvocationHandler(defaultInterceptors); invocationHandler.ApplyInterceptors(proxyTemplate, _interceptors); if (_mixins.Count > 0) { return(new MixinInvocationHandler(_mixins, invocationHandler)); } return(invocationHandler); }
/// <summary> /// Adapts a proxy to the specified interface type. /// </summary> /// <typeparam name="TInterface">The interface type.</typeparam> /// <param name="proxyTemplate">The proxy template.</param> /// <param name="proxy">The proxy object.</param> /// <returns>The object, of the specified interface type, to which the proxy object has been adapted.</returns> public static TInterface AdaptProxy <TInterface>(this IProxyTemplate proxyTemplate, object proxy) where TInterface : class { var interfaceType = typeof(TInterface); return((TInterface)proxyTemplate.AdaptProxy(interfaceType, proxy)); }