/// <summary> /// Creates a proxy instance of the specified proxy type using the specified target. /// </summary> /// <typeparam name="TProxy">The type of the proxy.</typeparam> /// <param name="target">The target.</param> /// <param name="interceptor">The interceptor.</param> /// <param name="interfaces">The interfaces.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">The <paramref name="target" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="interceptor" /> is <c>null</c>.</exception> public TProxy Create <TProxy>(TProxy target, IInterceptor interceptor, params Type[] interfaces) { Argument.IsNotNull("target", target); Argument.IsNotNull("interceptor", interceptor); var interceptorAdapter = new InterceptorAdapter(interceptor, target); var proxyType = typeof(TProxy); if (!proxyType.IsInterfaceEx()) { return ((TProxy) _proxyGenerator.CreateClassProxy(proxyType, interfaces, new Castle.DynamicProxy.IInterceptor[] { interceptorAdapter })); } return ((TProxy) _proxyGenerator.CreateInterfaceProxyWithoutTarget(proxyType, interfaces, new Castle.DynamicProxy.IInterceptor[] { interceptorAdapter })); }
/// <summary> /// Creates a proxy instance of the specified proxy type using the specified constructor arguments. /// </summary> /// <typeparam name="TProxy">The type of the proxy.</typeparam> /// <param name="parameters">The parameters.</param> /// <param name="interceptor">The interceptor.</param> /// <param name="interfaces">The interfaces.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">The <paramref name="parameters"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="interceptor"/> is <c>null</c>.</exception> public TProxy Create <TProxy>(object[] parameters, IInterceptor interceptor, params Type[] interfaces) where TProxy : class { Argument.IsNotNullOrEmptyArray("parameters", parameters); Argument.IsNotNull(() => interceptor); var proxyType = typeof(TProxy); var proxy = (TProxy)_typeFactory.CreateInstanceWithParameters(proxyType, parameters); var interceptorAdapter = new InterceptorAdapter(interceptor, proxy); return ((TProxy) _proxyGenerator.CreateClassProxy(proxyType, interfaces, ProxyGenerationOptions.Default, parameters, new Castle.DynamicProxy.IInterceptor[] { interceptorAdapter })); }
/// <summary> /// Creates a proxy instance of <paramref name="proxyType" /> type using the specified proxy type. /// </summary> /// <param name="proxyType">Type of the proxy.</param> /// <param name="interceptor">The interceptor.</param> /// <param name="interfaces">The interfaces.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">The <paramref name="proxyType" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="interceptor" /> is <c>null</c>.</exception> public object Create(Type proxyType, IInterceptor interceptor, params Type[] interfaces) { Argument.IsNotNull("proxyType", proxyType); Argument.IsNotNull("interceptor", interceptor); var interceptorAdapter = new InterceptorAdapter(interceptor, null); if (!proxyType.IsInterfaceEx()) { return(_proxyGenerator.CreateClassProxy(proxyType, interfaces, new Castle.DynamicProxy.IInterceptor[] { interceptorAdapter })); } return(_proxyGenerator.CreateInterfaceProxyWithoutTarget(proxyType, interfaces, new Castle.DynamicProxy.IInterceptor[] { interceptorAdapter })); }