internal TryCatchFinallyAspectWeaver(TryCatchFinallySettings tryCatchFinallySettings, IEnumerable<IMethodScopeWeaver> entryWeavers, IEnumerable<IMethodScopeWeaver> tryWeavers, IEnumerable<IMethodScopeWeaver> catchWeavers, IEnumerable<IMethodScopeWeaver> finallyWeavers, IMethodScopeWeaver returnValueWeaver = null)
     : base(entryWeavers, tryWeavers, finallyWeavers, returnValueWeaver)
 {
     this.catchWeavers = catchWeavers;
     this.tryCatchFinallySettings = tryCatchFinallySettings;
 }
        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);
                }
            }
        }
 internal BeginCatchBlockMethodScopeWeaver(TryCatchFinallySettings tryCatchFinallySettings)
 {
     aspectMember           = tryCatchFinallySettings.AspectMember;
     aspectArgumentType     = tryCatchFinallySettings.AspectArgumentType;
     localBuilderRepository = tryCatchFinallySettings.LocalBuilderRepository;
 }
 internal BeginCatchBlockMethodScopeWeaver(IEnumerable<IMethodScopeWeaver> catchWeavers,  TryCatchFinallySettings tryCatchFinallySettings)
 {
     this.catchWeavers = catchWeavers;
     aspectArgumentType = tryCatchFinallySettings.AspectArgumentType;
     localBuilderRepository = tryCatchFinallySettings.LocalBuilderRepository;
 }
 internal TryCatchFinallyAspectWeaver(TryCatchFinallySettings tryCatchFinallySettings, IMethodScopeWeaver entryWeaver, IEnumerable <IMethodScopeWeaver> tryWeavers, IMethodScopeWeaver catchWeaver, IEnumerable <IMethodScopeWeaver> finallyWeavers, IMethodScopeWeaver returnValueWeaver = null)
     : base(entryWeaver, tryWeavers, finallyWeavers, returnValueWeaver)
 {
     this.catchWeaver             = catchWeaver;
     this.tryCatchFinallySettings = tryCatchFinallySettings;
 }
Exemple #6
0
 internal BeginCatchBlockMethodScopeWeaver(IEnumerable <IMethodScopeWeaver> catchWeavers, TryCatchFinallySettings tryCatchFinallySettings)
 {
     this.catchWeavers      = catchWeavers;
     aspectArgumentType     = tryCatchFinallySettings.AspectArgumentType;
     localBuilderRepository = tryCatchFinallySettings.LocalBuilderRepository;
 }
        internal AbstractOnMethodBoundaryAspectWeaver(IAspectWeaver nestedAspect, IAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings)
            : base(aspectDefinition, aspectWeavingSettings)
        {
            IAdviceExpression selectedExpression = null;
            var catchWeavers = new List<IMethodScopeWeaver>();
            var entryWeavers = new List<IMethodScopeWeaver>();
            var finallyWeavers = new List<IMethodScopeWeaver>();
            Action<ILGenerator> restoreArgsIfNeededAction = null;
            IMethodScopeWeaver restoreArgsIfNeededScopeWeaver = null;
            var adviceWeavingSettings = new AdviceWeavingSettings(aspectWeavingSettings, argumentsWeavingSettings);

            ArgumentType = argumentsWeavingSettings.ArgumentType;
            tryWeavers = new List<IMethodScopeWeaver>() { nestedAspect };
            localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository;
            byRefArgumentsStoreWeaver = aspectWeavingSettings.ByRefArgumentsStoreWeaver;
            restoreArgsIfNeededAction = byRefArgumentsStoreWeaver.RestoreArgsIfNeeded;
            restoreArgsIfNeededScopeWeaver = restoreArgsIfNeededAction.ToMethodScopeWeaver();

            if (adviceDiscoveryVistor.HasOnMethodEntryAdvice) {
                selectedExpression = ResolveOnMethodEntryAdvice();
                entryWeavers.Add(selectedExpression.Reduce(adviceWeavingSettings));
            }

            AddEntryScopeWeavers(entryWeavers);

            if (adviceDiscoveryVistor.HasOnMethodSuccessAdvice) {
                selectedExpression = ResolveOnMethodSuccessAdvice();
                tryWeavers.Add(selectedExpression.Reduce(adviceWeavingSettings));
            }

            if (argumentsWeavingSettings.IsFunction()) {
                OnFunctionWeavingDetected();
            }

            if (adviceDiscoveryVistor.HasFinallyAdvice) {
                selectedExpression = ResolveFinallyAdvice();
                finallyWeavers.Add(selectedExpression.Reduce(adviceWeavingSettings));
                AddFinallyScopeWeavers(finallyWeavers);

                if (adviceDiscoveryVistor.HasOnMethodExceptionAdvice) {
                    var aspectMember = aspectRepository.GetAspectFieldByType(aspectDefinition.Aspect.AspectType);
                    var settings = new TryCatchFinallySettings(ArgumentType, localBuilderRepository);

                    selectedExpression = ResolveOnMethodExceptionAdvice();
                    catchWeavers.Add(restoreArgsIfNeededScopeWeaver);
                    catchWeavers.Add(selectedExpression.Reduce(adviceWeavingSettings));
                    weaver = new TryCatchFinallyAspectWeaver(settings, entryWeavers, tryWeavers, catchWeavers, finallyWeavers, returnValueWeaver);
                }
                else {
                    finallyWeavers.Insert(0, restoreArgsIfNeededScopeWeaver);
                    weaver = new OnMethodBoundaryTryFinallyAspectWeaver(entryWeavers, tryWeavers, finallyWeavers, returnValueWeaver);
                }
            }
            else {
                if (!byRefArgumentsStoreWeaver.ContainsByRefParams) {
                    var weavers = entryWeavers;

                    weavers.AddRange(tryWeavers);

                    if (returnValueWeaver.IsNotNull()) {
                        weavers.Add(returnValueWeaver);
                    }

                    weaver = new MethodScopeWeaversQueue(weavers);
                }
                else {
                    AddFinallyScopeWeavers(finallyWeavers);
                    finallyWeavers.Insert(0, restoreArgsIfNeededScopeWeaver);
                    weaver = new OnMethodBoundaryTryFinallyAspectWeaver(entryWeavers, tryWeavers, finallyWeavers, returnValueWeaver);
                }
            }
        }