dotnet/roslyn

Improve IDE0059 code fix for TryGetValue

Aperta

#34.446 aperta il 26 mar 2019

 (0 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-IDEFeature - IDE0059help wanted

Metriche repository

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

Descrizione

Version Used: Visual Studio 2019 RC

Steps to Reproduce:

string Method(IDictionary<int, string> map, int key)
{
  if (map.TryGetValue(key, out var text))
  {
    return map[key];
  }

  return null;
}

Apply the code fix for IDE0059 reported for the unused variable text.

Expected Behavior:

string Method(IDictionary<int, string> map)
{
  if (map.TryGetValue(key, out var text))
  {
    return text;
  }

  return null;
}

Actual Behavior:

string Method(IDictionary<int, string> map)
{
  if (map.TryGetValue(key, out _))
  {
    return map[key];
  }

  return null;
}

Guida contributor