dotnet/roslyn

Improve IDE0059 code fix for TryGetValue

Ouverte

#34 446 ouverte le 26 mars 2019

 (0 commentaire) (0 réaction) (0 personne assignée)C# (4 257 forks)batch import
Area-IDEFeature - IDE0059help wanted

Métriques du dépôt

Stars
 (20 414 étoiles)
Métriques de merge PR
 (Merge moyen 6j 17h) (256 PRs mergées en 30 j)

Description

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;
}

Guide contributeur