In this example I had to explicitly declare the variable as IDictionary<string, string> instead of var but I don't understand why.
Can someone explain why when I originally declared it as var
the Visual Studio tooltip indicated it was dynamic
even though DictionaryHelper.ParseOptional() returns an IDictionary<string, string>?
ParseOptional is declared as:
public static IDictionary<string, string> ParseOptional(dynamic json, string variableName);
The mergeVariables parameter is coming from Json.Decode(), hence the dynamic variable.
I'm using Visual Studio 2019, .NET v4.7.2, C#7.3 in case it's relevant.
private static ICollection<IMergeVariable> ParseMergeVariables(dynamic mergeVariables)
{
IDictionary<string, string> mergeDictionary = DictionaryHelper.ParseOptional(mergeVariables, "mergeVariables");
return mergeDictionary?.Select(variable => new MergeVariable(variable.Key, variable.Value)).Cast<IMergeVariable>().ToList();
}