Browse Source

Fix #2646: Missing values for enums with skipped or duplicate items

release/7.2
Siegfried Pammer 3 years ago
parent
commit
7aea1cefbc
  1. 14
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs
  2. 18
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

14
ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs

@ -34,6 +34,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Item0 = 0 Item0 = 0
} }
public enum EnumSkippedItemTest
{
Item0 = 0,
Item2 = 2
}
public enum EnumDuplicateItemTest
{
Item0 = 0,
Item1 = 1,
Item2A = 2,
Item2B = 2
}
public enum LongBasedEnum : long public enum LongBasedEnum : long
{ {
Item1, Item1,

18
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1405,12 +1405,12 @@ namespace ICSharpCode.Decompiler.CSharp
firstValue = currentValue; firstValue = currentValue;
first = false; first = false;
} }
else if (currentValue < previousValue) else if (currentValue <= previousValue)
{ {
// If the values are out of order, we fallback to displaying all values. // If the values are out of order, we fallback to displaying all values.
return EnumValueDisplayMode.All; return EnumValueDisplayMode.All;
} }
else if ((!allConsecutive && !allPowersOfTwo)) else if (!allConsecutive && !allPowersOfTwo)
{ {
// We already know that the values are neither consecutive nor all powers of 2, // We already know that the values are neither consecutive nor all powers of 2,
// so we can abort, and just display all values as-is. // so we can abort, and just display all values as-is.
@ -1418,10 +1418,18 @@ namespace ICSharpCode.Decompiler.CSharp
} }
previousValue = currentValue; previousValue = currentValue;
} }
if (allPowersOfTwo && previousValue > 2) if (allPowersOfTwo)
{ {
// If all values are powers of 2, display all enum values, but use hex. if (previousValue > 8)
return EnumValueDisplayMode.AllHex; {
// If all values are powers of 2 and greater 8, display all enum values, but use hex.
return EnumValueDisplayMode.AllHex;
}
else if (!allConsecutive)
{
// If all values are powers of 2, display all enum values.
return EnumValueDisplayMode.All;
}
} }
if (settings.AlwaysShowEnumMemberValues) if (settings.AlwaysShowEnumMemberValues)
{ {

Loading…
Cancel
Save