dotnet/roslyn

Improve IDE0059 code fix for TryGetValue

オープン

#34,446 opened on 2019/03/26

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-IDEFeature - IDE0059help wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

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

コントリビューターガイド