Skip to content

New APIs for "User Defined Compound Assignment Operators" feature #78261

@AlekseyTs

Description

@AlekseyTs

Background and Motivation

Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/user-defined-compound-assignment.md

Proposed APIs

namespace Microsoft.CodeAnalysis
{
    public static class WellKnownMemberNames
    {
+        /// <summary>
+        /// The name assigned to the '+=' operator.
+        /// </summary>
+        public const string AdditionAssignmentOperatorName = "op_AdditionAssignment";
+
+        /// <summary>
+        /// The name assigned to the '-=' operator.
+        /// </summary>
+        public const string SubtractionAssignmentOperatorName = "op_SubtractionAssignment";
+
+        /// <summary>
+        /// The name assigned to the '*=' operator.
+        /// </summary>
+        public const string MultiplicationAssignmentOperatorName = "op_MultiplicationAssignment";
+
+        /// <summary>
+        /// The name assigned to the '/=' operator.
+        /// </summary>
+        public const string DivisionAssignmentOperatorName = "op_DivisionAssignment";
+
+        /// <summary>
+        /// The name assigned to the '%=' operator.
+        /// </summary>
+        public const string ModulusAssignmentOperatorName = "op_ModulusAssignment";
+
+        /// <summary>
+        /// The name assigned to the '&amp;=' operator.
+        /// </summary>
+        public const string BitwiseAndAssignmentOperatorName = "op_BitwiseAndAssignment";
+
+        /// <summary>
+        /// The name assigned to the '|=' operator.
+        /// </summary>
+        public const string BitwiseOrAssignmentOperatorName = "op_BitwiseOrAssignment";
+
+        /// <summary>
+        /// The name assigned to the '^=' operator.
+        /// </summary>
+        public const string ExclusiveOrAssignmentOperatorName = "op_ExclusiveOrAssignment";
+
+        /// <summary>
+        /// The name assigned to the '&lt;&lt;=' operator.
+        /// </summary>
+        public const string LeftShiftAssignmentOperatorName = "op_LeftShiftAssignment";
+
+        /// <summary>
+        /// The name assigned to the '>>=' operator.
+        /// </summary>
+        public const string RightShiftAssignmentOperatorName = "op_RightShiftAssignment";
+
+        /// <summary>
+        /// The name assigned to the '>>>=' operator.
+        /// </summary>
+        public const string UnsignedRightShiftAssignmentOperatorName = "op_UnsignedRightShiftAssignment";
+
+        /// <summary>
+        /// The name assigned to the checked '+=' operator.
+        /// </summary>
+        public const string CheckedAdditionAssignmentOperatorName = "op_CheckedAdditionAssignment";
+
+        /// <summary>
+        /// The name assigned to the checked '-=' operator.
+        /// </summary>
+        public const string CheckedSubtractionAssignmentOperatorName = "op_CheckedSubtractionAssignment";
+
+        /// <summary>
+        /// The name assigned to the checked '*=' operator.
+        /// </summary>
+        public const string CheckedMultiplicationAssignmentOperatorName = "op_CheckedMultiplicationAssignment";
+
+        /// <summary>
+        /// The name assigned to the checked '/=' operator.
+        /// </summary>
+        public const string CheckedDivisionAssignmentOperatorName = "op_CheckedDivisionAssignment";
    }
}

namespace Microsoft.CodeAnalysis.CSharp
{
    public static partial class SyntaxFacts
    {
+        public static bool IsOverloadableCompoundAssignmentOperator(SyntaxKind kind)
    }
}

namespace Microsoft.CodeAnalysis.Editing;
{
    public enum OperatorKind
    {
+        /// <summary>
+        /// The name assigned to the AdditionAssignment operator.
+        /// </summary>
+        AdditionAssignment,
+    
+        /// <summary>
+        /// The name assigned to the SubtractionAssignment operator.
+        /// </summary>
+        SubtractionAssignment,
+    
+        /// <summary>
+        /// The name assigned to the MultiplicationAssignment operator.
+        /// </summary>
+        MultiplicationAssignment,
+    
+        /// <summary>
+        /// The name assigned to the DivisionAssignment operator.
+        /// </summary>
+        DivisionAssignment,
+    
+        /// <summary>
+        /// The name assigned to the ModulusAssignment operator.
+        /// </summary>
+        ModulusAssignment,
+    
+        /// <summary>
+        /// The name assigned to the ExclusiveOrAssignment operator.
+        /// </summary>
+        ExclusiveOrAssignment,
+    
+        /// <summary>
+        /// The name assigned to the BitwiseAndAssignment operator.
+        /// </summary>
+        BitwiseAndAssignment,
+    
+        /// <summary>
+        /// The name assigned to the BitwiseOrAssignment operator.
+        /// </summary>
+        BitwiseOrAssignment,
+    
+        /// <summary>
+        /// The name assigned to the LeftShiftAssignment operator.
+        /// </summary>
+        LeftShiftAssignment,
+    
+        /// <summary>
+        /// The name assigned to the RightShiftAssignment operator.
+        /// </summary>
+        RightShiftAssignment,
+    
+        /// <summary>
+        /// The name assigned to the UnsignedRightShiftAssignment operator.
+        /// </summary>
+        UnsignedRightShiftAssignment,
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions