Exemple #1
0
        public static bool IsEqual(Reflector.CodeModel.IEventDeclaration e, EventDefinition ed)
        {
            string edName = InsUtils.GetOldMemberName(ed);

            if (e.Name == edName &&
                IsEqual(e.EventType, ed.EventType))
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static bool IsEqual(Reflector.CodeModel.IFieldDeclaration f, FieldDefinition fd)
        {
            string fdName = InsUtils.GetOldMemberName(fd);

            if (f.Name == fdName &&
                IsEqual(f.FieldType, fd.FieldType))
            {
                return(true);
            }
            return(false);
        }
Exemple #3
0
        public static bool IsEqual(TypeReference tr1, TypeReference tr2)
        {
            if (tr1 == null && tr2 == null)
            {
                return(true);
            }
            if ((tr1 == null && tr2 != null) || (tr1 != null && tr2 == null))
            {
                return(false);
            }

            string trName1 = InsUtils.GetOldMemberName(tr1);
            string trName2 = InsUtils.GetOldMemberName(tr2);

            if (trName1 != trName2 || tr1.Namespace != tr2.Namespace)
            {
                return(false);
            }

            if (tr1 is IGenericInstance)
            {
                IGenericInstance gi1 = tr1 as IGenericInstance;
                IGenericInstance gi2 = tr2 as IGenericInstance;
                if (gi2 == null)
                {
                    return(false);
                }
                if (gi1.GenericArguments.Count != gi2.GenericArguments.Count)
                {
                    return(false);
                }
                for (int i = 0; i < gi1.GenericArguments.Count; i++)
                {
                    if (!IsEqual(gi1.GenericArguments[i], gi2.GenericArguments[i]))
                    {
                        return(false);
                    }
                }
            }

            if (tr1.DeclaringType == null && tr2.DeclaringType == null)
            {
                return(true);
            }
            if ((tr1.DeclaringType == null && tr2.DeclaringType != null) ||
                (tr1.DeclaringType != null && tr2.DeclaringType == null))
            {
                return(false);
            }
            return(IsEqual(tr1.DeclaringType, tr2.DeclaringType));
        }
Exemple #4
0
        public static bool IsEqual(Reflector.CodeModel.IPropertyDeclaration p, PropertyDefinition pd)
        {
            string pdName = InsUtils.GetOldMemberName(pd);

            if (p.Name == pdName &&
                IsEqual(p.PropertyType, pd.PropertyType) &&
                p.Parameters.Count == pd.Parameters.Count)
            {
                bool matched = true;
                for (int i = 0; i < pd.Parameters.Count; i++)
                {
                    if (!IsEqual(p.Parameters[i].ParameterType,
                                 pd.Parameters[i].ParameterType))
                    {
                        matched = false;
                        break;
                    }
                }
                return(matched);
            }
            return(false);
        }
Exemple #5
0
        public static bool IsEqual(Reflector.CodeModel.IMethodReference m, MethodReference mr, bool checkReturnType)
        {
            string mrName = InsUtils.GetOldMemberName(mr);

            if (m.Name == mrName &&
                (!checkReturnType || IsEqual(m.ReturnType.Type, mr.ReturnType)) &&
                m.Parameters.Count == mr.Parameters.Count
                )
            {
                bool matched = true;
                for (int i = 0; i < mr.Parameters.Count; i++)
                {
                    if (!IsEqual(m.Parameters[i].ParameterType,
                                 mr.Parameters[i].ParameterType))
                    {
                        matched = false;
                        break;
                    }
                }
                return(matched);
            }
            return(false);
        }
Exemple #6
0
        public static bool IsEqual(Reflector.CodeModel.ITypeReference t, TypeReference tr)
        {
            if (t == null && tr == null)
            {
                return(true);
            }
            if ((t == null && tr != null) || (t != null && tr == null))
            {
                return(false);
            }

            if (tr.Namespace != t.Namespace)
            {
                return(false);
            }

            //if (tr is ByReferenceType)
            //    tr = ((ByReferenceType)tr).ElementType;
            //if (tr is ArrayType)
            //    tr = ((ArrayType)tr).ElementType;

            string trName = InsUtils.GetOldMemberName(tr);

            if (tr is IGenericInstance)
            {
                if (!trName.StartsWith(t.Name + "`") && !trName.Equals(t.Name))
                {
                    return(false);
                }
                IGenericInstance gi = ((IGenericInstance)tr);
                if (gi.GenericArguments.Count != t.GenericArguments.Count)
                {
                    return(false);
                }
                for (int i = 0; i < t.GenericArguments.Count; i++)
                {
                    if (!IsEqual(t.GenericArguments[i],
                                 gi.GenericArguments[i]))
                    {
                        return(false);
                    }
                }
            }
            else if (tr.HasGenericParameters)
            {
                if (!trName.StartsWith(t.Name + "`") && !trName.Equals(t.Name))
                {
                    return(false);
                }
                if (tr.GenericParameters.Count != t.GenericArguments.Count)
                {
                    return(false);
                }
                for (int i = 0; i < t.GenericArguments.Count; i++)
                {
                    if (!IsEqual(t.GenericArguments[i],
                                 tr.GenericParameters[i]))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (trName != t.Name)
                {
                    return(false);
                }
            }

            if (t.Owner == null && tr.DeclaringType == null)
            {
                return(true);
            }
            if (t.Owner is Reflector.CodeModel.ITypeReference)
            {
                if (tr.DeclaringType != null)
                {
                    return(IsEqual((Reflector.CodeModel.ITypeReference)t.Owner, tr.DeclaringType));
                }
                if (tr is Mono.Cecil.TypeSpecification)
                {
                    return(IsEqual((Reflector.CodeModel.ITypeReference)t.Owner, ((TypeSpecification)tr).ElementType.DeclaringType));
                }
                return(false);
            }
            if (t.Owner == null && tr.DeclaringType != null)
            {
                return(false);
            }
            //now owner is not null but not ITypeReference, and DeclaringType is null?
            return(true);
        }
Exemple #7
0
        public static bool IsEqual(Reflector.CodeModel.IType t, TypeReference tr)
        {
            if (t is Reflector.CodeModel.ITypeReference)
            {
                return(IsEqual((Reflector.CodeModel.ITypeReference)t, tr));
            }
            else if ((t is Reflector.CodeModel.IArrayType) && (tr is ArrayType))
            {
                Reflector.CodeModel.IArrayType t2 = (Reflector.CodeModel.IArrayType)t;
                ArrayType tr2 = (ArrayType)tr;
                if (
                    !(t2.Dimensions.Count == 0 && tr2.Dimensions.Count == 1) && // one dimension
                    (t2.Dimensions.Count != tr2.Dimensions.Count)    // two or more dimension
                    )
                {
                    return(false);
                }

                return(IsEqual(t2.ElementType, tr2.ElementType));
            }
            else if ((t is Reflector.CodeModel.IReferenceType) && (tr is ByReferenceType))
            {
                return(IsEqual(((Reflector.CodeModel.IReferenceType)t).ElementType, ((ByReferenceType)tr).ElementType));
            }
            else if ((t is Reflector.CodeModel.IPointerType) && (tr is PointerType))
            {
                return(IsEqual(((Reflector.CodeModel.IPointerType)t).ElementType, ((PointerType)tr).ElementType));
            }
            else if ((t is Reflector.CodeModel.IOptionalModifier) && (tr is OptionalModifierType))
            {
                Reflector.CodeModel.IOptionalModifier t2 = (Reflector.CodeModel.IOptionalModifier)t;
                OptionalModifierType tr2 = (OptionalModifierType)tr;
                return(IsEqual(t2.Modifier, tr2.ModifierType) && IsEqual(t2.ElementType, tr2.ElementType));
            }
            else if ((t is Reflector.CodeModel.IFunctionPointer) && (tr is FunctionPointerType))
            {
                Reflector.CodeModel.IFunctionPointer t2 = (Reflector.CodeModel.IFunctionPointer)t;
                FunctionPointerType tr2 = (FunctionPointerType)tr;
                if (t2.Parameters.Count == tr2.Parameters.Count && IsEqual(t2.ReturnType.Type, tr2.ReturnType))
                {
                    for (int i = 0; i < t2.Parameters.Count; i++)
                    {
                        if (!IsEqual(t2.Parameters[i].ParameterType, tr2.Parameters[i].ParameterType))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                return(false);
            }
            else if ((t is Reflector.CodeModel.IRequiredModifier) && (tr is RequiredModifierType))
            {
                Reflector.CodeModel.IRequiredModifier t2 = (Reflector.CodeModel.IRequiredModifier)t;
                RequiredModifierType tr2 = (RequiredModifierType)tr;
                return(IsEqual(t2.Modifier, tr2.ModifierType) && IsEqual(t2.ElementType, tr2.ElementType));
            }
            else
            {
                string trName = InsUtils.GetOldMemberName(tr);
                //when tr is GenericParameter, it may be !0 or something, no clue what it is, no luck ...
                if ("!0" == trName && t.ToString() == "T")
                {
                    return(true);
                }
                return(t.ToString().Equals(trName));
            }
        }