dotnet/roslyn

Improve IDE0059 code fix for TryGetValue

开放

#34,446 创建于 2019年3月26日

 (0 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-IDEFeature - IDE0059help wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

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

贡献者指南