상속: IMethodScopeWeaver
        internal TopMethodInterceptionAspectWeaver(IMethodAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
            : base(aspectDefinition, aspectWeavingSettings, weavedType)
        {
            IMethodScopeWeaver getReturnValueWeaver = null;
            var @params = aspectDefinition.Member.GetParameters();
            var byRefArgumentsStoreWeaver = aspectWeavingSettings.ByRefArgumentsStoreWeaver;

            if (argumentsWeavingSettings.IsFunction()) {
                getReturnValueWeaver = new TopGetReturnValueWeaver(aspectWeavingSettings, argumentsWeavingSettings);
            }

            argumentsWeavingSettings.Parameters = @params.ToArray(@param => @param.ParameterType);
            argumentsWeavingSettings.BindingsDependency = weavedType;
            argumentsWeaver = new TopMethodInterceptionArgumentsWeaver(aspectDefinition.Member, argumentsWeavingSettings, aspectWeavingSettings);

            if (!byRefArgumentsStoreWeaver.ContainsByRefParams) {
                if (getReturnValueWeaver.IsNotNull()) {
                    methodScopeWeavers.Add(getReturnValueWeaver);
                }

                weaver = new MethodScopeWeaversQueue(methodScopeWeavers);
            }
            else {
                Action<ILGenerator> storeArgsIfNeededAction = byRefArgumentsStoreWeaver.StoreArgsIfNeeded;
                var finallyWeavers = new[] { storeArgsIfNeededAction.ToMethodScopeWeaver() };

                weaver = new TryFinallyAspectWeaver(methodScopeWeavers, finallyWeavers, getReturnValueWeaver);
            }
        }
 internal TopSetPropertyInterceptionAspectWeaver(IPropertyAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
     : base(aspectDefinition, aspectWeavingSettings, weavedType)
 {
     argumentsWeavingSettings.BindingsDependency = weavedType;
     argumentsWeavingSettings.Parameters = new[] { aspectDefinition.Member.PropertyType };
     argumentsWeaver = new TopSetPropertyInterceptionArgumentsWeaver(aspectDefinition.Member, argumentsWeavingSettings, aspectWeavingSettings);
     weaver = new MethodScopeWeaversQueue(methodScopeWeavers);
 }
 internal BindingRemoveEventInterceptionAspectWeaver(IEventAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
     : base(aspectDefinition, aspectWeavingSettings, weavedType)
 {
     argumentsWeavingSettings.BindingsDependency = weavedType;
     argumentsWeavingSettings.Parameters = new[] { aspectDefinition.Member.EventHandlerType };
     argumentsWeaver = new BindingEventInterceptionArgumentsWeaver(aspectDefinition, argumentsWeavingSettings, aspectWeavingSettings, bindingSettings);
     weaver = new MethodScopeWeaversQueue(methodScopeWeavers);
 }
 internal TopBindingMethodInterceptionAspectWeaver(IMethodAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
     : base(aspectDefinition, aspectWeavingSettings, weavedType)
 {
     argumentsWeavingSettings.BindingsDependency = weavedType;
     argumentsWeaver = new TopBindingMethodInterceptionArgumentsWeaver(aspectDefinition.Member, argumentsWeavingSettings, aspectWeavingSettings);
     methodScopeWeavers.Add(new TopAspectArgsMappingWeaverImpl(aspectWeavingSettings, argumentsWeavingSettings));
     ArgumentType = argumentsWeavingSettings.ArgumentType;
     weaver = new MethodScopeWeaversQueue(methodScopeWeavers);
 }
 internal BindingMethodInterceptionAspectWeaver(Type topAspectInScopeArgType, IMethodAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
     : base(aspectDefinition, aspectWeavingSettings, weavedType)
 {
     this.topAspectInScopeArgType = topAspectInScopeArgType;
     ArgumentType = argumentsWeavingSettings.ArgumentType;
     argumentsWeavingSettings.BindingsDependency = weavedType;
     argumentsWeaver = new BindingMethodInterceptionArgumentsWeaver(aspectDefinition.Member, topAspectInScopeArgType, argumentsWeavingSettings, aspectWeavingSettings);
     methodScopeWeavers.Add(new NestedAspectArgsMappingWeaver(topAspectInScopeArgType, aspectWeavingSettings, argumentsWeavingSettings));
     weaver = new MethodScopeWeaversQueue(methodScopeWeavers);
 }
        internal BindingRaiseEventInterceptionAspectWeaver(IEventAspectDefinition aspectDefinition, IAspectWeavingSettings aspectWeavingSettings, FieldInfo weavedType)
            : base(aspectDefinition, aspectWeavingSettings, weavedType)
        {
            argumentsWeavingSettings.BindingsDependency = weavedType;
            argumentsWeavingSettings.Parameters = new[] { aspectDefinition.Member.EventHandlerType };
            argumentsWeaver = new BindingEventInterceptionArgumentsWeaver(aspectDefinition, argumentsWeavingSettings, aspectWeavingSettings, bindingSettings);

            if (aspectDefinition.Member.IsFunction()) {
                methodScopeWeavers.Add(new TopGetReturnValueWeaver(aspectWeavingSettings, argumentsWeavingSettings));
            }

            weaver = new MethodScopeWeaversQueue(methodScopeWeavers);
        }
예제 #7
0
        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);
        }
예제 #8
0
        public override void Weave(ILGenerator ilGenerator)
        {
            var weavers = new List<IMethodScopeWeaver>();
            MethodScopeWeaversQueue methodScopeWeaversQueue = null;

            weavers.AddRange(entryWeavers);
            weavers.Add(new BeginExceptionBlockMethodScopeWeaver());
            weavers.Add(new BeginExceptionBlockMethodScopeWeaver());
            weavers.AddRange(tryWeavers);
            weavers.Add(new BeginCatchBlockMethodScopeWeaver(catchWeavers, tryCatchFinallySettings));
            weavers.Add(new EndExceptionBlockMethodScopeWeaver());
            weavers.Add(new FinallyMethodScopeWeaver(finallyWeavers));
            weavers.Add(new EndExceptionBlockMethodScopeWeaver());

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

            methodScopeWeaversQueue = new MethodScopeWeaversQueue(weavers);
            methodScopeWeaversQueue.Weave(ilGenerator);
        }
예제 #9
0
 internal FinallyMethodScopeWeaver(IEnumerable<IMethodScopeWeaver> finallyWeavers)
 {
     finallyWeaversQueue = new MethodScopeWeaversQueue(finallyWeavers);
 }
        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);
                }
            }
        }