Exemplo n.º 1
0
 /// <summary>
 /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public override bool Equals(object obj)
 {
     // Ez a kódrészlet a Java Method implementációjából való.
     // Fontos különbség, hogy itt nem vizsgálom a DeclaringClass-t, azaz nem számít melyik interface-ből való.
     // Nem vizsgálom a visszatérési típust sem, mert irreveláns azokban az esetekben, ahol ezt az osztályt használom.
     // Ami számít, hogy a neve és a paraméterlistája pontosan megegyezzen.
     if (obj != null && obj is MethodComparator)
     {
         MethodComparator other = (MethodComparator)obj;
         if (Method.Name.Equals(other.Method.Name))
         {
             /* Avoid unnecessary cloning */
             ParameterInfo[] params1 = mMethod.GetParameters();
             ParameterInfo[] params2 = other.Method.GetParameters();
             if (params1.Length == params2.Length)
             {
                 for (int i = 0; i < params1.Length; i++)
                 {
                     if (params1[i].ParameterType != params2[i].ParameterType)
                     {
                         return(false);
                     }
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyComparator"/> class.
 /// </summary>
 /// <param name="pi">The pi.</param>
 public PropertyComparator(PropertyInfo pi)
 {
     if (pi == null)
     {
         ThrowHelper.ThrowArgumentNullException("pi");
     }
     this.mPropertyInfo = pi;
     if (pi.GetGetMethod() != null)
     {
         this.mGetMethod = new MethodComparator(pi.GetGetMethod());
     }
     if (pi.GetSetMethod() != null)
     {
         this.mSetMethod = new MethodComparator(pi.GetSetMethod());
     }
 }
Exemplo n.º 3
0
        private static void CheckInvalidMethodDeclaration(Type contractInterface, List <MethodComparator> methods)
        {
            foreach (MethodInfo m in contractInterface.GetMethods())
            {
                {
                    OperationContractAttribute ocAnnotation = TypeHelper.GetAttribute <OperationContractAttribute>(m);
                    if (ocAnnotation != null)
                    {
                        // 4. szabály ellenőrzése
                        if (!m.ReturnType.Equals(typeof(Stream)) && typeof(Stream).IsAssignableFrom(m.ReturnType))
                        {
                            throw new InvalidContractDefinitionException(String.Format("Return type '{0}' of the method '{1}' of contract '{2}' is not allowed. Use the base class instead.", m.ReturnType.FullName, m.Name, contractInterface.Name));
                        }
                        if (m.GetParameters().Length > 0)
                        {
                            foreach (ParameterInfo pt in m.GetParameters())
                            {
                                if (!pt.ParameterType.Equals(typeof(Stream)) && typeof(Stream).IsAssignableFrom(pt.ParameterType))
                                {
                                    throw new InvalidContractDefinitionException(String.Format("Parameter type '{0}' of the method '{1}' of contract '{2}' is not allowed. Use the base class instead.", pt.ParameterType.FullName, m.Name, contractInterface.Name));
                                }
                            }
                        }

                        // 5. szabály ellenőrzése
                        if (ocAnnotation.IsOneWay && !m.ReturnType.Equals(typeof(void)))
                        {
                            throw new InvalidContractDefinitionException(String.Format("Return type '{0}' of the method '{1}' of contract '{2}' is not allowed for OneWay mode.", m.ReturnType.FullName, m.Name, contractInterface.Name));
                        }
                        // 6. szabály ellenőrzése
                        if (!ocAnnotation.IsOneWay && !ocAnnotation.IsReliable)
                        {
                            throw new InvalidContractDefinitionException(String.Format("Invalid reliable mode setting for method '{0}' of the contract type '{1}'. Non reliable communication allowed only for OneWay mode.", m.Name, contractInterface.Name));
                        }
                    }
                    // 7. szabály ellenőrzése
                    MethodComparator cmp = new MethodComparator(m);
                    if (methods.Contains(cmp))
                    {
                        MethodComparator otherCmp = null;
                        foreach (MethodComparator mc in methods)
                        {
                            if (mc.Equals(cmp))
                            {
                                otherCmp = mc;
                                break;
                            }
                        }
                        OperationContractAttribute otherOcAnnotation = TypeHelper.GetAttribute <OperationContractAttribute>(otherCmp.Method);
                        if (ocAnnotation == null && otherOcAnnotation == null)
                        {
                            // do nothing
                        }
                        else if (ocAnnotation != null && otherOcAnnotation != null)
                        {
                            if (ocAnnotation.Direction != otherOcAnnotation.Direction)
                            {
                                throw new InvalidContractDefinitionException(String.Format("Different {0} definition found on method {1}. Contract interfaces are '{2}' and '{3}'. Setting 'direction' is different.", typeof(OperationContractAttribute).Name, m.Name, contractInterface.Name, otherCmp.Method.DeclaringType.FullName));
                            }
                            if (ocAnnotation.IsOneWay != otherOcAnnotation.IsOneWay)
                            {
                                throw new InvalidContractDefinitionException(String.Format("Different {0} definition found on method {1}. Contract interfaces are '{2}' and '{3}'. Setting 'isOneWay' is different.", typeof(OperationContractAttribute).Name, m.Name, contractInterface.Name, otherCmp.Method.DeclaringType.FullName));
                            }
                            if (ocAnnotation.IsReliable != otherOcAnnotation.IsReliable)
                            {
                                throw new InvalidContractDefinitionException(String.Format("Different {0} definition found on method {1}. Contract interfaces are '{2}' and '{3}'. Setting 'isReliable' is different.", typeof(OperationContractAttribute).Name, m.Name, contractInterface.Name, otherCmp.Method.DeclaringType.FullName));
                            }
                            if (ocAnnotation.CallTimeout != otherOcAnnotation.CallTimeout)
                            {
                                throw new InvalidContractDefinitionException(String.Format("Different {0} definition found on method {1}. Contract interfaces are '{2}' and '{3}'. Setting 'timeout' is different.", typeof(OperationContractAttribute).Name, m.Name, contractInterface.Name, otherCmp.Method.DeclaringType.FullName));
                            }
                        }
                        else
                        {
                            // az egyiken van annotáció, a másikon meg nincs
                            throw new InvalidContractDefinitionException(String.Format("Different {0} definition found on method {1}. Contract interfaces are '{2}' and '{3}'. Same {4} must be exist on methods.", typeof(OperationContractAttribute).Name, m.Name, contractInterface.Name, otherCmp.Method.DeclaringType.FullName, typeof(OperationContractAttribute).Name));
                        }
                    }
                    else
                    {
                        methods.Add(cmp);
                    }
                }
            }
        }