This project is read-only.

How to get the argument to parameter map?

Topics: APIs
Aug 25, 2014 at 8:17 PM
Given an invocation like F(arg2: 1, arg1: 2) how can I determine (short of matching strings myself) how the parameters are mapped to invocation arguments?
Aug 26, 2014 at 5:10 AM
I think you have to map the strings in the NamedArgumentSyntax to the IParameterSymbols you get back from SemanticModel.GetSymbolInfo()
Aug 26, 2014 at 11:18 PM
It seems so. IMO this is something the language service should provide.

Also, how can I find out whether an invocation uses expanded form (for param arrays)?
Nov 18, 2014 at 7:54 AM
I have an extension like
public class ArgumentForCall {
    public ExpressionSyntax Argument { get; }
    public TypedConstant ConstantValue { get; }
    public ImmutableArray<ExpressionSyntax> ParamArray { get; }

public class CallInfo {
    public ImmutableArray<int> ArgumentToParameterMap { get; }
    public ImmutableArray<ArgumentForCall> ArgumentsForCall { get; }
    public bool IsNonVirtualInvocation { get; set; }

public static class SemanticModelExtensions {
    public static CallInfo GetCallInfo(this SemanticModel m, InvocationExpressionSyntax syntax) {}
    public static CallInfo GetCallInfo(this SemanticModel m, ObjectCreationExpressionSyntax syntax) {}
    public static CallInfo GetCallInfo(this SemanticModel m, ElementAccessExpressionSyntax syntax) {}
but this methods is, IMO, too complicated to require me and other consumers to correctly implement. Could you consider providing this information somehow?
Nov 18, 2014 at 5:21 PM
Yes, this is a pain. We are considering an API on SemanticModel like:
ParameterSymbol SemanticModel.CorrespondingParameter(ArgumentSyntax argument);
Would you mind filing an issue to track the need for that?
Nov 18, 2014 at 9:04 PM
Your supposed API would solve half of the problem (the one I used ArgumentToParameterMap for), which is "which parameter does this argument correspond to?". It does, however, not address the second question I need answered which is "in this invocation, which value will actually be provided for each parameter?".
Nov 18, 2014 at 9:08 PM