dotnet/roslyn

Add IParameterSymbol.IsImplicitValueParameter API

Open

#14.275 aperta il 4 ott 2016

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-CompilersConcept-APIFeature Requesthelp wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

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.

Guida contributor