dotnet/roslyn

Add IParameterSymbol.IsImplicitValueParameter API

Open

#14,275 建立於 2016年10月4日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)C# (4,257 fork)batch import
Area-CompilersConcept-APIFeature Requesthelp wanted

倉庫指標

Star
 (20,414 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

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.

貢獻者指南