dotnet/roslyn

Add IParameterSymbol.IsImplicitValueParameter API

Open

#14,275 opened on 2016年10月4日

GitHub で見る
 (4 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-CompilersConcept-APIFeature Requesthelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

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.

コントリビューターガイド