Exemplo n.º 1
0
        public static string OperatorNameFromDeclaration(Syntax.InternalSyntax.OperatorDeclarationSyntax declaration)
        {
            var opTokenKind = declaration.OperatorToken.Kind;

            if (SyntaxFacts.IsBinaryExpressionOperatorToken(opTokenKind))
            {
                // Some tokens may be either unary or binary operators (e.g. +, -).
                if (SyntaxFacts.IsPrefixUnaryExpressionOperatorToken(opTokenKind) &&
                    declaration.ParameterList.Parameters.Count == 1)
                {
                    return(OperatorFacts.UnaryOperatorNameFromSyntaxKind(opTokenKind));
                }

                return(OperatorFacts.BinaryOperatorNameFromSyntaxKind(opTokenKind));
            }
            else if (SyntaxFacts.IsUnaryOperatorDeclarationToken(opTokenKind))
            {
                return(OperatorFacts.UnaryOperatorNameFromSyntaxKind(opTokenKind));
            }
            else
            {
                // fallback for error recovery
                return(WellKnownMemberNames.UnaryPlusOperatorName);
            }
        }
Exemplo n.º 2
0
        public static string OperatorNameFromDeclaration(Syntax.InternalSyntax.OperatorDeclarationSyntax declaration)
        {
            var  opTokenKind = declaration.OperatorToken.Kind;
            bool isChecked   = declaration.CheckedKeyword?.Kind == SyntaxKind.CheckedKeyword;

            if (SyntaxFacts.IsBinaryExpressionOperatorToken(opTokenKind))
            {
                // Some tokens may be either unary or binary operators (e.g. +, -).
                if (opTokenKind != SyntaxKind.AsteriskToken && // IsPrefixUnaryExpressionOperatorToken treats it as pointer dereference operator
                    SyntaxFacts.IsPrefixUnaryExpressionOperatorToken(opTokenKind) &&
                    declaration.ParameterList.Parameters.Count == 1)
                {
                    return(OperatorFacts.UnaryOperatorNameFromSyntaxKind(opTokenKind, isChecked));
                }

                return(OperatorFacts.BinaryOperatorNameFromSyntaxKind(opTokenKind, isChecked));
            }
            else if (SyntaxFacts.IsUnaryOperatorDeclarationToken(opTokenKind))
            {
                return(OperatorFacts.UnaryOperatorNameFromSyntaxKind(opTokenKind, isChecked));
            }
            else
            {
                // fallback for error recovery
                return(WellKnownMemberNames.UnaryPlusOperatorName);
            }
        }