dotnet/roslyn

Analyzer Improvement for IDE0059

オープン

#55,960 opened on 2021/08/27

 (2 件のコメント) (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)

説明

Brief description: The following two variable declarations are equivalent and only vary based on coding style:

a? ret;

if(Condition){
  ret = new a(){ ... };
} else {
  ret = new a(){ ... };
}

AND

var ret = default(a?);

if(Condition){
  ret = new a(){ ... };
} else {
  ret = new a(){ ... };
}

Today, IDE0059 triggers if a variable is initialized with any value and then later reassigned. I suggest updating IDE0059 to trigger only if a variable is initialized to a non-default value and then later reassigned.

Languages applicable: C# any maybe VB.

Code example that the analyzer SHOULD report: Needlessly initializing to a non-default value.

Code example that the analyzer not report: See above

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