diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs index 4d3a13fc9..f66be670d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs @@ -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, diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 43d54cae2..89c2fd9b0 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -1405,12 +1405,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. @@ -1418,10 +1418,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) {