示例#1
0
        public virtual void Weave(ILGenerator ilGenerator)
        {
            LocalBuilder argsLocalBuilder = null;
            var          aspectMember     = aspectRepository.GetAspectFieldByType(aspectType);
            var          adviceMethod     = aspectMember.FieldType.GetMethod(AdviceName);

            argsLocalBuilder = localBuilderRepository.Get(argumentsWeavingSettings.ArgumentType);
            ilGenerator.Emit(OpCodes.Ldsfld, aspectMember);
            ilGenerator.EmitLoadLocal(argsLocalBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, adviceMethod);
        }
示例#2
0
        protected override void WeaveFunction(ILGenerator ilGenerator)
        {
            var setReturnValueWeaver = new SetReturnValueWeaver(topAspectInScopeArgType);
            var argsImplLocalBuilder = localBuilderRepository.Get(topAspectInScopeArgType);

            byRefArgumentStoreWeaver.StoreArgsIfNeeded(ilGenerator);
            ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
            argumentsWeaver.Weave(ilGenerator);
            ilGenerator.Emit(OpCodes.Callvirt, Method);
            setReturnValueWeaver.Weave(ilGenerator);
            byRefArgumentStoreWeaver.RestoreArgsIfNeeded(ilGenerator);
        }
        public void Weave(ILGenerator ilGenerator)
        {
            MethodInfo   returnValueGetMethod = null;
            LocalBuilder argsImplLocalBuilder = null;
            var          argumentType         = argumentsWeavingSetings.ArgumentType;
            var          aspectArgsType       = GetAspectArgsType();

            argsImplLocalBuilder = localBuilderRepository.Get(argumentType);
            ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
            returnValueGetMethod = aspectArgsType.GetProperty("ReturnValue").GetGetMethod();
            ilGenerator.Emit(OpCodes.Callvirt, returnValueGetMethod);
        }
        protected override ILGenerator WeaveFunction(ILGenerator ilGenerator)
        {
            var setReturnValueWeaver = new SetReturnValueWeaver(previousAspectArgsType);
            var argsImplLocalBuilder = localBuilderRepository.Get(previousAspectArgsType);

            byRefArgumentStoreWeaver.StoreArgsIfNeeded(ilGenerator);
            ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
            argumentsWeaver.Weave(ilGenerator);
            ilGenerator.Emit(OpCodes.Callvirt, MethodInfoImpl);
            setReturnValueWeaver.Weave(ilGenerator);
            byRefArgumentStoreWeaver.RestoreArgsIfNeeded(ilGenerator);

            return(ilGenerator);
        }
        public ILGenerator Weave(ILGenerator ilGenerator)
        {
            var          typeofException           = typeof(Exception);
            LocalBuilder exceptionLocalBuilder     = null;
            var          typeofFlowBehavior        = typeof(FlowBehavior);
            LocalBuilder flowBehavoiurLocalBuilder = null;
            var          afterRethrowLabel         = ilGenerator.DefineLabel();
            var          throwFlowBehaviorLabel    = ilGenerator.DefineLabel();
            var          rethrowFlowBehaviorLabel  = ilGenerator.DefineLabel();
            var          argsImplLocalBuilder      = localBuilderRepository.Get(aspectArgumentType);
            var          jumpTable              = new[] { throwFlowBehaviorLabel, rethrowFlowBehaviorLabel };
            var          onExceptionMethodInfo  = aspectMember.FieldType.GetMethod("OnException");
            var          setExceptionMethodInfo = aspectArgumentType.GetProperty("Exception").GetSetMethod();
            var          flowBehaviorMethodInfo = aspectArgumentType.GetProperty("FlowBehavior").GetGetMethod();

            exceptionLocalBuilder = localBuilderRepository.GetOrDeclare(typeofException, () => {
                return(ilGenerator.DeclareLocal(typeofException));
            });

            flowBehavoiurLocalBuilder = localBuilderRepository.GetOrDeclare(typeofFlowBehavior, () => {
                return(ilGenerator.DeclareLocal(typeofFlowBehavior));
            });

            ilGenerator.BeginCatchBlock(typeofException);
            ilGenerator.EmitStoreLocal(exceptionLocalBuilder);
            ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
            ilGenerator.EmitLoadLocal(exceptionLocalBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, setExceptionMethodInfo);
            ilGenerator.Emit(OpCodes.Ldsfld, aspectMember);
            ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, onExceptionMethodInfo);
            ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, flowBehaviorMethodInfo);
            ilGenerator.EmitStoreLocal(flowBehavoiurLocalBuilder);
            ilGenerator.EmitLoadLocal(flowBehavoiurLocalBuilder);
            ilGenerator.EmitPushInteger(1);
            ilGenerator.Emit(OpCodes.Sub);
            ilGenerator.Emit(OpCodes.Switch, jumpTable);
            ilGenerator.Emit(OpCodes.Br_S, afterRethrowLabel);
            ilGenerator.MarkLabel(throwFlowBehaviorLabel);
            ilGenerator.EmitLoadLocal(exceptionLocalBuilder);
            ilGenerator.Emit(OpCodes.Throw);
            ilGenerator.MarkLabel(rethrowFlowBehaviorLabel);
            ilGenerator.Emit(OpCodes.Rethrow);
            ilGenerator.MarkLabel(afterRethrowLabel);

            return(ilGenerator);
        }
示例#6
0
        public virtual ILGenerator Weave(ILGenerator ilGenerator)
        {
            MethodInfo             mapGenericMethod     = null;
            Func <int, MethodInfo> getMappingArgsMethod = null;
            var argsImplLocalBuilder = localBuilderRepository.Get(aspectArgumentType);

            getMappingArgsMethod = argumentsSettings.IsFunction ?
                                   aspectWeavingSettings.AspectArgsMapper.GetMappingArgsFunction :
                                   (Func <int, MethodInfo>)aspectWeavingSettings.AspectArgsMapper.GetMappingArgsAction;

            mapGenericMethod = getMappingArgsMethod(mappingParameters.Length);
            mapGenericMethod = mapGenericMethod.MakeGenericMethod(mappingParameters);

            ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
            WeaveAspectArg(ilGenerator);
            ilGenerator.Emit(OpCodes.Call, mapGenericMethod);

            return(ilGenerator);
        }