dotnet/roslyn

Add IParameterSymbol.IsImplicitValueParameter API

Open

#14.275 aberto em 4 de out. de 2016

Ver no GitHub
 (4 comments) (0 reactions) (0 assignees)C# (4.257 forks)batch import
Area-CompilersConcept-APIFeature Requesthelp wanted

Métricas do repositório

Stars
 (20.414 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (256 fundiu PRs em 30d)

Description

Currently we have the following extension method in Workspaces that determines whether a parameter is an implicit value parameter (in context of property/indexer setters and event accessors).

        public static bool IsImplicitValueParameter(this ISymbol symbol)
        {
            if (symbol.IsImplicitlyDeclared && symbol is IParameterSymbol)
            {
                var method = symbol.ContainingSymbol as IMethodSymbol;
                if (method != null)
                {
                    if (method.MethodKind == MethodKind.EventAdd ||
                        method.MethodKind == MethodKind.EventRemove ||
                        method.MethodKind == MethodKind.PropertySet)
                    {
                        // the name is value in C#, and Value in VB
                        return symbol.Name == "value" || symbol.Name == "Value";
                    }
                }
            }

            return false;
        }

The code is language agnostic yet it needs to deal with differences between C# and VB in casing. Avoiding symbol name comparison like so doesn't work:

((IParameterSymbol)symbol).Ordinal == method.Parameters.Length

since while in C# the implicit value parameter is not included in method.Parameters, VB includes it.

It would be easier if we just had an API for this on IParameterSymbol.

Guia do colaborador