Exemple #1
0
 private void ifElseAsepct(AhainOfResponsibility ahainOfResponsibility)
 {
     foreach (var attribute in ifElseAsepctAttributes)
     {
         if (attribute.check(invocation.Arguments)) continue;
         attribute.checkForErrors();
         return;
     }
     ahainOfResponsibility.exectue();
 }
Exemple #2
0
 private void asepct(AhainOfResponsibility ahainOfResponsibility)
 {
     var attributes = asepctAttributes;
     var invocationAsepct = invocation;
     attributeBeforeAsepct(attributes);
     ahainOfResponsibility.exectue();
     var task = invocationAsepct.ReturnValue as Task;
     if (task == null)
         attributeAfterAsepct(attributes);
     else
         attributeAfterAsepctTask(task, attributes);
 }
Exemple #3
0
 private async void tryCatchAsepct(AhainOfResponsibility ahainOfResponsibility)
 {
     var attributes = tryCatchAsepctAttributes;
     var invocationAsepct = invocation;
     try
     {
         tryCatchAttributeBeforeAsepct(attributes);
         ahainOfResponsibility.exectue();
         var task = invocationAsepct.ReturnValue as Task;
         if (task == null)
         {
             tryCatchAttributeAfterAsepct(attributes);
         }
         else
         {
             await task;
             tryCatchAattributeAfterAsepctTask(task, attributes);
         }
     }
     catch
     {
         catchAsepct(attributes);
     }
 }
Exemple #4
0
        public void Intercept(IInvocation invocation)
        {
            this.invocation = invocation;
            asepctAttributes = invocation.Method.GetCustomAttributes(typeof(AsepctAttribute), true).Cast<AsepctAttribute>().ToList();
            tryCatchAsepctAttributes = invocation.Method.GetCustomAttributes(typeof(TryCatchAsepctAttribute), true).Cast<TryCatchAsepctAttribute>().ToList();
            ifElseAsepctAttributes = invocation.Method.GetCustomAttributes(typeof(IfElseAsepctAttribute), true).Cast<IfElseAsepctAttribute>().ToList();

            var ahainOfResponsibility = new AhainOfResponsibility {exectueNext = x => invocation.Proceed()};

            //普通切面
            if(asepctAttributes.Any())
                ahainOfResponsibility = new AhainOfResponsibility(ahainOfResponsibility) {exectueNext = asepct};

            //是否执行函数切面
            if(ifElseAsepctAttributes.Any())
                ahainOfResponsibility = new AhainOfResponsibility(ahainOfResponsibility) { exectueNext = ifElseAsepct };

            //异常切面
            if (tryCatchAsepctAttributes.Any())
                ahainOfResponsibility = new AhainOfResponsibility(ahainOfResponsibility) { exectueNext = tryCatchAsepct };

            //开始执行
            ahainOfResponsibility.exectue();
        }
Exemple #5
0
        private void argumentJudgementAsepct(AhainOfResponsibility ahainOfResponsibility)
        {

        }