private IEnumerable<string> FindInterceptorRefNames(InterceptMethodElement interceptMethodElement)
 {
     if (interceptMethodElement == null)
         return null;
     if (interceptMethodElement.InterceptorRefs == null)
         return null;
     var ret = new List<string>();
     foreach (InterceptorRefElement interceptorRefElement in interceptMethodElement.InterceptorRefs)
     {
         ret.Add(interceptorRefElement.Name);
     }
     return ret;
 }
Beispiel #2
0
 /// <summary>
 ///     为制定类型的指定方法添加拦截器
 /// </summary>
 /// <param name="contractType">需要拦截方法的类型</param>
 /// <param name="method">需要拦截的方法</param>
 /// <param name="name">拦截器的名字</param>
 public void AddInterceptorRef(Type contractType, MethodInfo method, string name)
 {
     if (config.Interception != null)
     {
         if (config.Interception.Contracts != null)
         {
             foreach (InterceptContractElement interceptContract in config.Interception.Contracts)
             {
                 if (interceptContract.Type.Equals(contractType.AssemblyQualifiedName))
                 {
                     if (interceptContract.Methods != null)
                     {
                         foreach (InterceptMethodElement interceptMethod in interceptContract.Methods)
                         {
                             if (interceptMethod.Signature.Equals(method.GetSignature()))
                             {
                                 if (interceptMethod.InterceptorRefs != null)
                                 {
                                     foreach (
                                         InterceptorRefElement interceptorRef in interceptMethod.InterceptorRefs)
                                     {
                                         if (interceptorRef.Name.Equals(name))
                                             return;
                                     }
                                     interceptMethod.InterceptorRefs.Add(new InterceptorRefElement {Name = name});
                                 }
                                 else
                                 {
                                     interceptMethod.InterceptorRefs = new InterceptorRefElementCollection();
                                     interceptMethod.InterceptorRefs.Add(new InterceptorRefElement {Name = name});
                                 }
                                 return;
                             }
                         }
                         var interceptMethodAdd = new InterceptMethodElement();
                         interceptMethodAdd.Signature = method.GetSignature();
                         interceptMethodAdd.InterceptorRefs = new InterceptorRefElementCollection();
                         interceptMethodAdd.InterceptorRefs.Add(new InterceptorRefElement {Name = name});
                         interceptContract.Methods.Add(interceptMethodAdd);
                     }
                     else
                     {
                         interceptContract.Methods = new InterceptMethodElementCollection();
                         var interceptMethodAdd = new InterceptMethodElement();
                         interceptMethodAdd.Signature = method.GetSignature();
                         interceptMethodAdd.InterceptorRefs = new InterceptorRefElementCollection();
                         interceptMethodAdd.InterceptorRefs.Add(new InterceptorRefElement {Name = name});
                         interceptContract.Methods.Add(interceptMethodAdd);
                     }
                     return;
                 }
             }
             var interceptContractAdd = new InterceptContractElement();
             interceptContractAdd.Type = contractType.AssemblyQualifiedName;
             interceptContractAdd.Methods = new InterceptMethodElementCollection();
             var interceptMethodAddToContract = new InterceptMethodElement();
             interceptMethodAddToContract.Signature = method.GetSignature();
             interceptMethodAddToContract.InterceptorRefs = new InterceptorRefElementCollection();
             interceptMethodAddToContract.InterceptorRefs.Add(new InterceptorRefElement {Name = name});
             interceptContractAdd.Methods.Add(interceptMethodAddToContract);
             config.Interception.Contracts.Add(interceptContractAdd);
         }
         else
         {
             config.Interception.Contracts = new InterceptContractElementCollection();
             var interceptContractAdd = new InterceptContractElement();
             interceptContractAdd.Type = contractType.AssemblyQualifiedName;
             interceptContractAdd.Methods = new InterceptMethodElementCollection();
             var interceptMethodAddToContract = new InterceptMethodElement();
             interceptMethodAddToContract.Signature = method.GetSignature();
             interceptMethodAddToContract.InterceptorRefs = new InterceptorRefElementCollection();
             interceptMethodAddToContract.InterceptorRefs.Add(new InterceptorRefElement {Name = name});
             interceptContractAdd.Methods.Add(interceptMethodAddToContract);
             config.Interception.Contracts.Add(interceptContractAdd);
         }
     }
     else
     {
         config.Interception = new InterceptionElement();
         config.Interception.Contracts = new InterceptContractElementCollection();
         var interceptContractAdd = new InterceptContractElement();
         interceptContractAdd.Type = contractType.AssemblyQualifiedName;
         interceptContractAdd.Methods = new InterceptMethodElementCollection();
         var interceptMethodAddToContract = new InterceptMethodElement();
         interceptMethodAddToContract.Signature = method.GetSignature();
         interceptMethodAddToContract.InterceptorRefs = new InterceptorRefElementCollection();
         interceptMethodAddToContract.InterceptorRefs.Add(new InterceptorRefElement {Name = name});
         interceptContractAdd.Methods.Add(interceptMethodAddToContract);
         config.Interception.Contracts.Add(interceptContractAdd);
     }
 }