public bool Equals(MethodModel x, MethodModel y)
        {
            var xSymbol = x?.MethodSymbol;
            var ySymbol = y?.MethodSymbol;

            if (SymbolEqualityComparer.Default.Equals(xSymbol, ySymbol))
            {
                return(true);
            }
            if (xSymbol == null || ySymbol == null)
            {
                return(false);
            }

            if (xSymbol.Name != ySymbol.Name)
            {
                return(false);
            }
            var xParameters = xSymbol.Parameters;
            var yParameters = ySymbol.Parameters;

            if (xParameters.Length != yParameters.Length)
            {
                return(false);
            }
            if (xSymbol.IsGenericMethod != ySymbol.IsGenericMethod)
            {
                return(false);
            }
            var xGenericArgs = xSymbol.TypeArguments;
            var yGenericArgs = ySymbol.TypeArguments;

            if (xSymbol.IsGenericMethod && xGenericArgs.Length != yGenericArgs.Length)
            {
                return(false);
            }
            for (int i = 0; i < xParameters.Length; i++)
            {
                var xParam = xParameters[i];
                var yParam = yParameters[i];
                if (xParam.Type.Kind != yParam.Type.Kind)
                {
                    return(false);
                }
                if ((xParam.RefKind == RefKind.None) != (yParam.RefKind == RefKind.None))
                {
                    return(false);
                }

                if (xParam.Type.Kind == SymbolKind.TypeParameter)
                {
                    if (xGenericArgs.IndexOf(xParam.Type) != yGenericArgs.IndexOf(yParam.Type))
                    {
                        return(false);
                    }
                }
                else if (!SymbolEqualityComparer.Default.Equals(xParam.Type, yParam.Type))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        public bool Equals(MethodModel x, MethodModel y)
        {
            var xInfo = x?.MethodInfo;
            var yInfo = y?.MethodInfo;

            if (xInfo == yInfo)
            {
                return(true);
            }
            if (xInfo == null || yInfo == null)
            {
                return(false);
            }

            if (xInfo.Name != yInfo.Name)
            {
                return(false);
            }
            var xParameters = xInfo.GetParameters();
            var yParameters = yInfo.GetParameters();

            if (xParameters.Length != yParameters.Length)
            {
                return(false);
            }
            if (xInfo.IsGenericMethod != yInfo.IsGenericMethod)
            {
                return(false);
            }
            var xGenericArgs = xInfo.GetGenericArguments();
            var yGenericArgs = yInfo.GetGenericArguments();

            if (xInfo.IsGenericMethod && xGenericArgs.Length != yGenericArgs.Length)
            {
                return(false);
            }
            for (int i = 0; i < xParameters.Length; i++)
            {
                var xParam = xParameters[i];
                var yParam = yParameters[i];
                if (xParam.ParameterType.IsGenericParameter != yParam.ParameterType.IsGenericParameter)
                {
                    return(false);
                }
                if (xParam.ParameterType.IsByRef != yParam.ParameterType.IsByRef)
                {
                    return(false);
                }

                if (xParam.ParameterType.IsGenericParameter)
                {
                    if (Array.IndexOf(xGenericArgs, xParam.ParameterType) != Array.IndexOf(yGenericArgs, yParam.ParameterType))
                    {
                        return(false);
                    }
                }
                else if (xParam.ParameterType != yParam.ParameterType)
                {
                    return(false);
                }
            }

            return(true);
        }