コード例 #1
0
            private bool Equals(IType x, IType y)
            {
                if (x == y)
                {
                    return(true);
                }

                if (x == null || y == null)
                {
                    return(false);
                }

                if (x.ElementCode != y.ElementCode)
                {
                    return(false);
                }

                switch (x.ElementCode)
                {
                case TypeElementCode.Array:
                {
                    if (!SignatureComparer.EqualsArrayDimensions(x.ArrayDimensions, y.ArrayDimensions))
                    {
                        return(false);
                    }

                    if (!object.ReferenceEquals(x.ElementType, y.ElementType))
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.ByRef:
                {
                    if (!object.ReferenceEquals(x.ElementType, y.ElementType))
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.CustomModifier:
                {
                    CustomModifierType xModifierType;
                    var xModifier = x.GetCustomModifier(out xModifierType);

                    CustomModifierType yModifierType;
                    var yModifier = y.GetCustomModifier(out yModifierType);

                    if (xModifierType != yModifierType)
                    {
                        return(false);
                    }

                    if (!object.ReferenceEquals(x.ElementType, y.ElementType))
                    {
                        return(false);
                    }

                    if (!object.ReferenceEquals(xModifier, yModifier))
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.FunctionPointer:
                {
                    if (!object.ReferenceEquals(x.GetFunctionPointer(), y.GetFunctionPointer()))
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.GenericParameter:
                {
                    bool xIsMethod;
                    int  xPosition;
                    x.GetGenericParameter(out xIsMethod, out xPosition);

                    bool yIsMethod;
                    int  yPosition;
                    y.GetGenericParameter(out yIsMethod, out yPosition);

                    if (xIsMethod != yIsMethod)
                    {
                        return(false);
                    }

                    if (xPosition != yPosition)
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.GenericType:
                {
                    if (!object.ReferenceEquals(x.DeclaringType, y.DeclaringType))
                    {
                        return(false);
                    }

                    if (!Equals(x.GenericArguments, y.GenericArguments))
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.Pinned:
                {
                    if (!object.ReferenceEquals(x.ElementType, y.ElementType))
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.Pointer:
                {
                    if (!object.ReferenceEquals(x.ElementType, y.ElementType))
                    {
                        return(false);
                    }

                    return(true);
                }

                case TypeElementCode.DeclaringType:
                    throw new InvalidOperationException();

                default:
                    throw new NotImplementedException();
                }
            }