Наследование: AspectWeavingSettingsImpl, IAdviceWeavingSettings
Пример #1
0
        internal AbstractMethodInterceptionAspectWeaver(IAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
            : base(aspectDefinition, aspectWeavingSettings)
        {
            IAdviceExpression selectedExpression = null;
            var argumentsWeavingSettings         = aspectDefinition.ToArgumentsWeavingSettings();
            var aspectSettings = new AdviceWeavingSettings(aspectWeavingSettings, argumentsWeavingSettings);

            bindingDependency  = weavedType;
            selectedExpression = ResolveOnMethodInvokeAdvice();
            methodScopeWeavers = new List <IMethodScopeWeaver>();
            methodScopeWeavers.Add(selectedExpression.Reduce(aspectSettings));
            localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository;
        }
        internal AbstractInterceptionAspectWeaver(IAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
            : base(aspectDefinition, aspectWeavingSettings)
        {
            IAdviceExpression selectedExpression = null;
            AdviceWeavingSettings adviceWeavingSettings = null;

            bindingDependency = weavedType;
            argumentsWeavingSettings = aspectDefinition.ToArgumentsWeavingSettings();
            adviceWeavingSettings = new AdviceWeavingSettings(aspectWeavingSettings, argumentsWeavingSettings);
            selectedExpression = ResolveInterceptionAdviceExpression();
            methodScopeWeavers = new List<IMethodScopeWeaver> {
                selectedExpression.Reduce(adviceWeavingSettings)
            };

            localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository;
        }
        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 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);
                }
            }
        }