本文整理汇总了C#中IInterceptor.GetExcepionInterceptors方法的典型用法代码示例。如果您正苦于以下问题:C# IInterceptor.GetExcepionInterceptors方法的具体用法?C# IInterceptor.GetExcepionInterceptors怎么用?C# IInterceptor.GetExcepionInterceptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInterceptor
的用法示例。
在下文中一共展示了IInterceptor.GetExcepionInterceptors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExcepionIntercept
private static void ExcepionIntercept(ILGenerator ilGenerator, IInterceptor[] interceptors, LocalBuilder[] local)
{
var excepionInterceptors = interceptors.GetExcepionInterceptors();
if (!excepionInterceptors.Any())
{
ilGenerator.Emit(OpCodes.Throw);
return;
}
var invocationType = InternalDynamicTypeProvider.CreateType<IExceptionInvocation>();
var setException = invocationType.GetMethod("set_Exception");
var setInterceptedType = invocationType.GetMethod("set_InterceptedType");
var setInterceptedInstance = invocationType.GetMethod("set_InterceptedInstance");
var getExceptionHandled = invocationType.GetMethod("get_ExceptionHandled");
var getExcepionInterceptMethod = typeof(IExceptionInterceptor).GetMethod("OnExcepion");
var getExcepionInterceptorsMethod = typeof(InterceptorExtends).GetMethod("GetExcepionInterceptors");
var exceptionLocal = ilGenerator.DeclareLocal(typeof(Exception));
var interceptorLocal = ilGenerator.DeclareLocal(typeof(IExceptionInterceptor[]));
var invocationLocal = ilGenerator.DeclareLocal(invocationType);
var breakExceptionLable = ilGenerator.DefineLabel();
ilGenerator.StoreLocal(exceptionLocal).LoadLocal(local[0]).Call(getExcepionInterceptorsMethod).StoreLocal(interceptorLocal);
ilGenerator.New(invocationType.GetConstructor(Type.EmptyTypes)).StoreLocal(invocationLocal);
ilGenerator.LoadLocal(invocationLocal).LoadLocal(exceptionLocal).Callvirt(setException);
ilGenerator.LoadLocal(invocationLocal).LoadLocal(local[2]).Callvirt(setInterceptedType);
ilGenerator.LoadLocal(invocationLocal).This().Callvirt(setInterceptedInstance);
ilGenerator.ForEach(excepionInterceptors, (il, interceptor, index) =>
il.LoadLocal(invocationLocal).Callvirt(getExceptionHandled).False(breakExceptionLable).LoadLocal(interceptorLocal).LoadArrayItem(index).
LoadLocal(invocationLocal).Callvirt(getExcepionInterceptMethod)).MarkLabelFor(breakExceptionLable);
}