It's 9 o'clock, no nonsense, directly to the lecture, today is a simple introduction to the framework of the use of some of the interfaces and properties. Yesterday we divided the sections of our attention into three categories, now give the definition of these 3 interfaces:
Interface definition
/// <summary>
/// 在调用方法体前执行的处理接口
/// </summary>
public interface IPreProcess
{
bool PreProcess(MethodContext methodContext);
}
/// <summary>
/// 在调用方法体后执行的处理接口
/// </summary>
public interface IPostProcess
{
void PostProcess(MethodContext methodContext);
}
/// <summary>
/// 处理方法调用所产生的异常的接口
/// </summary>
public interface IExceptionHandler
{
void ProcessException(MethodContext methodContext, Exception exception);
}
L The inherited Ipreprocess interface enables processing of a method before it is executed, passing in a Methodcontext object containing some contextual information about the execution of the method, and then returning a bool value indicating whether the following method continues to be executed;
L Inherit the Ipostprocess interface to implement the processing of the method, the same pass to a Methodcontext object, and, unlike before, the Methodcontext object is also set up the true method of the implementation of the results, for some subsequent processing ;
L an inherited Iexceptionhandler interface can implement exception handling in the event of an exception to the method, which has a exception parameter that represents the exception information that was intercepted, compared to the above two methods.
For any one interface, each method can have more than one handler, and the framework will call execution in the order defined in the configuration file. Here is an example of a pseudo code after a method is implanted:
Pseudo code
public virtual void Test1(string text1)
{
MethodContext context;
try
{
//调用预处理程序
if (_addPreProcessLog.PreProcess(context))
{
//调用真正的方法
base.Test1(text1);
//调用事后处理程序
_addPostProcessLog.PostProcess(context);
}
}
catch (Exception exception)
{
//调用异常处理程序
_simplyExceptionHandler.ProcessException(context, exception);
}
}