dotnet/roslyn

Add IParameterSymbol.IsImplicitValueParameter API

Open

#14.275 geöffnet am 4. Okt. 2016

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-CompilersConcept-APIFeature Requesthelp wanted

Repository-Metriken

Stars
 (20.414 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

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.

Contributor Guide