KEMBAR78
Add `IParameterSymbol.IsParamCollection` property · Issue #71816 · dotnet/roslyn · GitHub
Skip to content

Add IParameterSymbol.IsParamCollection property  #71816

@AlekseyTs

Description

@AlekseyTs

Background and Motivation

Related to "Params Collections" feature work.

Proposed API

namespace Microsoft.CodeAnalysis
{
    /// <summary>
    /// Represents a parameter of a method or property.
    /// </summary>
    /// <remarks>
    /// This interface is reserved for implementation by its associated APIs. We reserve the right to
    /// change it in the future.
    /// </remarks>
    public interface IParameterSymbol : ISymbol
    {
        /// <summary>
        /// Returns true if the parameter was declared as a parameter array. 
        /// </summary>
        bool IsParams { get; }

+        /// <summary>
+        /// Returns true if the parameter was declared as a parameter collection. 
+        /// </summary>
+        bool IsParamCollection { get; }
    }
}

Alternative Designs

Option 1

We could extend the meaning of IsParams property to return true for non-array param collections instead,
but then VB, for example, will print C# methods like

Public Shared Sub M1(ParamArray a As System.Collections.Generic.IEnumerable(Of Integer))

which is likely to confuse the user. VB is not going to support params collections.

Other consumers can be affected in a similar way.

Option 2

As the top proposal, but with additional new property:

namespace Microsoft.CodeAnalysis
{
    /// <summary>
    /// Represents a parameter of a method or property.
    /// </summary>
    /// <remarks>
    /// This interface is reserved for implementation by its associated APIs. We reserve the right to
    /// change it in the future.
    /// </remarks>
    public interface IParameterSymbol : ISymbol
    {
        /// <summary>
        /// Returns true if the parameter was declared as a parameter array. 
        /// </summary>
        bool IsParams { get; }

+        /// <summary>
+        /// Same as IsParams
+        /// </summary>
+        bool IsParamArray { get; }

+        /// <summary>
+        /// Returns true if the parameter was declared as a parameter collection. 
+        /// </summary>
+        bool IsParamCollection { get; }
    }
}

Option 3

Have IsParams return true if if the parameter was declared either as a parameter array,
or a parameter collection. Add new property for parameter aray.

namespace Microsoft.CodeAnalysis
{
    /// <summary>
    /// Represents a parameter of a method or property.
    /// </summary>
    /// <remarks>
    /// This interface is reserved for implementation by its associated APIs. We reserve the right to
    /// change it in the future.
    /// </remarks>
    public interface IParameterSymbol : ISymbol
    {
        /// <summary>
-       /// Returns true if the parameter was declared as a parameter array. 
+       /// Returns true if the parameter was declared as a parameter array or as a parameter collection. 
        /// </summary>
        bool IsParams { get; }

+        /// <summary>
+        /// Returns true if the parameter was declared as a parameter array 
+        /// </summary>
+        bool IsParamArray { get; }

+        /// <summary>
+        /// Returns true if the parameter was declared as a parameter collection. 
+        /// </summary>
+        bool IsParamCollection { get; }
    }
}

Risks

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions