Browse Source

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

pull/2667/head
Siegfried Pammer 3 years ago
parent
commit
9935f51b96
  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 @@ -34,6 +34,20 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Item0 = 0
}
public enum EnumSkippedItemTest
{
Item0 = 0,
Item2 = 2
}
public enum EnumDuplicateItemTest
{
Item0 = 0,
Item1 = 1,
Item2A = 2,
Item2B = 2
}
public enum LongBasedEnum : long
{
Item1,

18
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1393,12 +1393,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1393,12 +1393,12 @@ namespace ICSharpCode.Decompiler.CSharp
firstValue = currentValue;
first = false;
}
else if (currentValue < previousValue)
else if (currentValue <= previousValue)
{
// If the values are out of order, we fallback to displaying all values.
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,
// so we can abort, and just display all values as-is.
@ -1406,10 +1406,18 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1406,10 +1406,18 @@ namespace ICSharpCode.Decompiler.CSharp
}
previousValue = currentValue;
}
if (allPowersOfTwo && previousValue > 2)
if (allPowersOfTwo)
{
// If all values are powers of 2, display all enum values, but use hex.
return EnumValueDisplayMode.AllHex;
if (previousValue > 8)
{
// 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)
{

Loading…
Cancel
Save