diff --git a/ICSharpCode.Decompiler/IL/ILVariable.cs b/ICSharpCode.Decompiler/IL/ILVariable.cs index 60423625c..77b6dbae5 100644 --- a/ICSharpCode.Decompiler/IL/ILVariable.cs +++ b/ICSharpCode.Decompiler/IL/ILVariable.cs @@ -337,6 +337,17 @@ namespace ICSharpCode.Decompiler.IL } } + /// + /// Gets whether the variable is dead - unused. + /// + public bool IsDead { + get { + return StoreCount == (HasInitialValue ? 1 : 0) + && LoadCount == 0 + && AddressCount == 0; + } + } + /// /// The field which was converted to a local variable. /// Set when the variable is from a 'yield return' or 'async' state machine. diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs b/ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs index c3c53092f..2b79902f3 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs @@ -102,8 +102,7 @@ namespace ICSharpCode.Decompiler.IL { for (int i = 0; i < list.Count;) { var v = list[i]; - int deadStoreCount = v.HasInitialValue ? 1 : 0; - if (v.StoreCount == deadStoreCount && v.LoadCount == 0 && v.AddressCount == 0 && v.Kind != VariableKind.DisplayClassLocal) { + if (v.IsDead && v.Kind != VariableKind.DisplayClassLocal) { RemoveAt(i); } else { i++;