private InterceptMethodElement FindInterceptMethodElement(InterceptContractElement interceptContractElement, MethodInfo method)
        {
            if (interceptContractElement == null)
                return null;
            if (interceptContractElement.Methods == null)
                return null;

            foreach (InterceptMethodElement interceptMethodElement in interceptContractElement.Methods)
            {
                string methodSignature = null;
                if (method.IsGenericMethod)
                    methodSignature = method.GetGenericMethodDefinition().GetSignature();
                else
                    methodSignature = method.GetSignature();
                if (interceptMethodElement.Signature.Equals(methodSignature))
                    return interceptMethodElement;
            }
            return null;
        }
Пример #2
0
 /// <summary>
 /// Adds an interception reference to the specified contract and the method.
 /// </summary>
 /// <param name="contractType">The type of the contract.</param>
 /// <param name="method">The method.</param>
 /// <param name="name">The name of the interception reference.</param>
 public void AddInterceptorRef(Type contractType, MethodInfo method, string name)
 {
     if (this.config.Interception != null)
     {
         if (this.config.Interception.Contracts != null)
         {
             foreach (InterceptContractElement interceptContract in this.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;
                             }
                         }
                         InterceptMethodElement 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();
                         InterceptMethodElement interceptMethodAdd = new InterceptMethodElement();
                         interceptMethodAdd.Signature = method.GetSignature();
                         interceptMethodAdd.InterceptorRefs = new InterceptorRefElementCollection();
                         interceptMethodAdd.InterceptorRefs.Add(new InterceptorRefElement { Name = name });
                         interceptContract.Methods.Add(interceptMethodAdd);
                     }
                     return;
                 }
             }
             InterceptContractElement interceptContractAdd = new InterceptContractElement();
             interceptContractAdd.Type = contractType.AssemblyQualifiedName;
             interceptContractAdd.Methods = new InterceptMethodElementCollection();
             InterceptMethodElement interceptMethodAddToContract = new InterceptMethodElement();
             interceptMethodAddToContract.Signature = method.GetSignature();
             interceptMethodAddToContract.InterceptorRefs = new InterceptorRefElementCollection();
             interceptMethodAddToContract.InterceptorRefs.Add(new InterceptorRefElement { Name = name });
             interceptContractAdd.Methods.Add(interceptMethodAddToContract);
             this.config.Interception.Contracts.Add(interceptContractAdd);
         }
         else
         {
             this.config.Interception.Contracts = new InterceptContractElementCollection();
             InterceptContractElement interceptContractAdd = new InterceptContractElement();
             interceptContractAdd.Type = contractType.AssemblyQualifiedName;
             interceptContractAdd.Methods = new InterceptMethodElementCollection();
             InterceptMethodElement interceptMethodAddToContract = new InterceptMethodElement();
             interceptMethodAddToContract.Signature = method.GetSignature();
             interceptMethodAddToContract.InterceptorRefs = new InterceptorRefElementCollection();
             interceptMethodAddToContract.InterceptorRefs.Add(new InterceptorRefElement { Name = name });
             interceptContractAdd.Methods.Add(interceptMethodAddToContract);
             this.config.Interception.Contracts.Add(interceptContractAdd);
         }
     }
     else
     {
         this.config.Interception = new InterceptionElement();
         this.config.Interception.Contracts = new InterceptContractElementCollection();
         InterceptContractElement interceptContractAdd = new InterceptContractElement();
         interceptContractAdd.Type = contractType.AssemblyQualifiedName;
         interceptContractAdd.Methods = new InterceptMethodElementCollection();
         InterceptMethodElement interceptMethodAddToContract = new InterceptMethodElement();
         interceptMethodAddToContract.Signature = method.GetSignature();
         interceptMethodAddToContract.InterceptorRefs = new InterceptorRefElementCollection();
         interceptMethodAddToContract.InterceptorRefs.Add(new InterceptorRefElement { Name = name });
         interceptContractAdd.Methods.Add(interceptMethodAddToContract);
         this.config.Interception.Contracts.Add(interceptContractAdd);
     }
 }