Click or drag to resize

ISimpleMethodInterceptor Interface

Represents a simple method interceptor

Namespace:  Cauldron.Interception
Assembly:  Cauldron.Interception (in Cauldron.Interception.dll) Version: 3.2.0.1 (3.2.0.1)
Syntax
C#
public interface ISimpleMethodInterceptor

The ISimpleMethodInterceptor type exposes the following members.

Methods
  NameDescription
Public methodOnEnter
Invoked if an intercepted method has been called
Top
Examples
Sample implementation:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class MyInterceptorAttribute : Attribute, ISimpleMethodInterceptor
{
    public void OnEnter(Type declaringType, object instance, MethodBase methodbase, object[] values)
    {
    }
}
The interceptor is also capable of handling attributes with parameters.

Your code:

public class SampleClass
{
    [MyInterceptor]
    public void SampleMethod()
    {
        Debug.WriteLine("Blablablablablabla");
    }
}
What gets compiled:
public class SampleClass
{
    public void SampleMethod()
    {
        var interceptorAttribute = new MyInterceptorAttribute();
        interceptorAttribute.OnEnter(typeof(SampleClass), this, MethodBase.GetMethodFromHandle(methodof(SampleClass.SampleMethod()).MethodHandle, typeof(SampleClass).TypeHandle), new object[0]);
        Debug.WriteLine("Blablablablablabla");
    }
}
See Also