public virtual void Weave(ILGenerator ilGenerator) { MethodScopeWeaversQueue methodScopeWeaversQueue = null; weavers.Add(new BeginExceptionBlockMethodScopeWeaver()); weavers.AddRange(tryWeavers); weavers.Add(new FinallyMethodScopeWeaver(finallyWeavers)); weavers.Add(new EndExceptionBlockMethodScopeWeaver()); if (returnValueWeaver.IsNotNull()) { weavers.Add(returnValueWeaver); } methodScopeWeaversQueue = new MethodScopeWeaversQueue(weavers); methodScopeWeaversQueue.Weave(ilGenerator); }
internal AbstractOnMethodBoundaryAspectWeaver(IAspectWeaver nestedAspect, IAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings) : base(aspectDefinition, aspectWeavingSettings) { IMethodScopeWeaver entryWeaver = null; IMethodScopeWeaver catchWeaver = null; Action <ILGenerator> storeArgsAction = null; IAdviceExpression selectedExpression = null; IMethodScopeWeaver storeArgsArgsWeaver = null; var finallyWeavers = new List <IMethodScopeWeaver>(); var adviceWeavingSettings = new AdviceWeavingSettings(aspectWeavingSettings, argumentsWeavingSetings); ArgumentType = argumentsWeavingSetings.ArgumentType; byRefArgumentsStoreWeaver = aspectWeavingSettings.ByRefArgumentsStoreWeaver; storeArgsAction = byRefArgumentsStoreWeaver.StoreArgsIfNeeded; storeArgsArgsWeaver = storeArgsAction.ToMethodScopeWeaver(); tryWeavers = new List <IMethodScopeWeaver>() { nestedAspect }; localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository; if (adviceDiscoveryVistor.HasOnMethodEntryAdvice) { selectedExpression = ResolveOnMethodEntryAdvice(); entryWeaver = selectedExpression.Reduce(adviceWeavingSettings); } if (adviceDiscoveryVistor.HasOnMethodSuccessAdvice) { selectedExpression = ResolveOnMethodSuccessAdvice(); tryWeavers.Add(selectedExpression.Reduce(adviceWeavingSettings)); } if (argumentsWeavingSetings.IsFunction) { OnFunctionWeavingDetected(); } if (adviceDiscoveryVistor.HasFinallyAdvice) { selectedExpression = ResolveFinallyAdvice(); finallyWeavers.Add(selectedExpression.Reduce(adviceWeavingSettings)); finallyWeavers.Add(storeArgsArgsWeaver); if (adviceDiscoveryVistor.HasOnMethodExceptionAdvice) { var aspectMember = aspectRepository.GetAspectFieldByType(aspectDefinition.Aspect.AspectType); var settings = new TryCatchFinallySettings(ArgumentType, aspectMember, localBuilderRepository); selectedExpression = ResolveOnMethodExceptionAdvice(); catchWeaver = selectedExpression.Reduce(adviceWeavingSettings); weaver = new TryCatchFinallyAspectWeaver(settings, entryWeaver, tryWeavers, catchWeaver, finallyWeavers, returnValueWeaver); } else { weaver = new OnMethodBoundaryTryFinallyAspectWeaver(entryWeaver, tryWeavers, finallyWeavers, returnValueWeaver); } } else { var weavers = new List <IMethodScopeWeaver> { entryWeaver }; if (!byRefArgumentsStoreWeaver.ContainsByRefParams) { weavers.AddRange(tryWeavers); if (returnValueWeaver.IsNotNull()) { weavers.Add(returnValueWeaver); } weaver = new MethodScopeWeaversQueue(weavers); } else { finallyWeavers.Add(storeArgsArgsWeaver); weaver = new OnMethodBoundaryTryFinallyAspectWeaver(entryWeaver, weavers, finallyWeavers, returnValueWeaver); } } }