Ejemplo n.º 1
0
        private static bool ConvertedHasEqual(BinaryOperatorKind oldOperatorKind, BoundNode node, out TypeSymbol type)
        {
            type = null;
            if (node.Kind != BoundKind.Conversion)
            {
                return(false);
            }
            var conv = (BoundConversion)node;

            if (conv.ExplicitCastInCode)
            {
                return(false);
            }
            NamedTypeSymbol nt = conv.Operand.Type as NamedTypeSymbol;

            if ((object)nt == null || !nt.IsReferenceType || nt.IsInterface)
            {
                return(false);
            }

            string opName = (oldOperatorKind == BinaryOperatorKind.ObjectEqual) ? WellKnownMemberNames.EqualityOperatorName : WellKnownMemberNames.InequalityOperatorName;

            for (var t = nt; (object)t != null; t = t.BaseTypeNoUseSiteDiagnostics)
            {
                foreach (var sym in t.GetMembers(opName))
                {
                    MethodSymbol op = sym as MethodSymbol;
                    if ((object)op == null || op.MethodKind != MethodKind.UserDefinedOperator)
                    {
                        continue;
                    }
                    var parameters = op.GetParameters();
                    if (parameters.Length == 2 && TypeSymbol.Equals(parameters[0].Type, t, TypeCompareKind.ConsiderEverything2) && TypeSymbol.Equals(parameters[1].Type, t, TypeCompareKind.ConsiderEverything2))
                    {
                        type = t;
                        return(true);
                    }
                }
            }

            return(false);
        }