Exemplo n.º 1
0
 /// <summary>
 /// Provides a handler for all methods, async or otherwise.
 /// </summary>
 public InvocationHandler(Func <Invocation, Task <object> > asyncHandler, Func <object, MethodInfo, PropertyInfo, bool> proxyPredicate = null, AsyncInvocationMode asyncMode = AsyncInvocationMode.Throw)
 {
     this.asyncHandler   = asyncHandler;
     this.proxyPredicate = proxyPredicate ?? ((x, method, property) => true);
     this.asyncMode      = asyncMode;
 }
Exemplo n.º 2
0
 ///  <summary>
 ///  Creates a proxy for a given type.  This method supports two discrete usage scenarios.<p/>
 ///  If T is an interface, the target should be an implementation of that interface. In
 ///  this scenario, T should be <i>explicitly</i> specified unless the type of <i>target</i>
 ///  at the calling site is of that interface.  In other words, if the calling site has the
 ///  <i>target</i> declared as the concrete implementation, the proxy will be generated
 ///  for the implementation, rather than for the interface.
 ///
 ///  If T is a class, the target should be an instance of that class, and a subclassing
 ///  proxy will be created for it.  However, because target is specified in this case,
 ///  the base class behavior will be ignored (it will all be delegated to the target).
 ///  </summary>
 ///  <typeparam name="T">The type to create the proxy for.  May be an interface or a
 ///  concrete base class.</typeparam>
 ///  <param name="invocationHandler">This is where you get to inject your logic.</param>
 ///  <param name="predicate">Optional predicate to determine if the interception should happen.  Useful
 ///  improving performance in certain situations</param>
 /// <param name="asyncMode">Controls what happens when an async invocation handler performs async related actions
 /// where the original method being proxied is not an async method.</param>
 /// <returns>The new instance of the proxy that is an instance of T</returns>
 public static T CreateProxy <T>(Func <Invocation, Task <object> > invocationHandler, ProxyPredicate <T> predicate = null,
                                 AsyncInvocationMode asyncMode = AsyncInvocationMode.Throw)
 {
     return(CreateProxy(default(T), invocationHandler, predicate, asyncMode));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a proxy for a given type.  This method supports two discrete usage scenarios.<p/>
 /// If T is an interface, the target should be an implementation of that interface. In
 /// this scenario, T should be <i>explicitly</i> specified unless the type of <i>target</i>
 /// at the calling site is of that interface.  In other words, if the calling site has the
 /// <i>target</i> declared as the concrete implementation, the proxy will be generated
 /// for the implementation, rather than for the interface.
 ///
 /// If T is a class, the target should be an instance of that class, and a subclassing
 /// proxy will be created for it.  However, because target is specified in this case,
 /// the base class behavior will be ignored (it will all be delegated to the target).
 /// </summary>
 /// <typeparam name="T">The type to create the proxy for.  May be an interface or a
 /// concrete base class.</typeparam>
 /// <param name="target">The instance of T that should be the recipient of all invocations
 /// on the proxy via Invocation.Proceed.</param>
 /// <param name="invocationHandler">This is where you get to inject your logic.</param>
 /// <param name="predicate">Optional predicate to determine if the interception should happen.  Useful
 /// improving performance in certain situations</param>
 /// <param name="asyncMode">Controls what happens when an async invocation handler performs async related actions
 /// where the original method being proxied is not an async method.</param>
 /// <returns>The new instance of the proxy that is an instance of T</returns>
 public static T CreateProxy <T>(T target, Func <Invocation, Task <object> > invocationHandler, ProxyPredicate <T> predicate = null,
                                 AsyncInvocationMode asyncMode = AsyncInvocationMode.Throw)
 {
     return(Proxy <T> .CreateProxy(target, invocationHandler, predicate, asyncMode));
 }