Browse Source

Fix #1095: C# decompilation, for flags enums always use hex prefix

pull/1108/head
Siegfried Pammer 7 years ago
parent
commit
62770cf94c
  1. 4
      ICSharpCode.Decompiler.Tests/CustomAttributes/CustomAttributeTests.cs
  2. 2
      ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributeSamples.cs
  3. 10
      ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs
  4. 8
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs
  5. 2
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

4
ICSharpCode.Decompiler.Tests/CustomAttributes/CustomAttributeTests.cs

@ -12,13 +12,13 @@ namespace ICSharpCode.Decompiler.Tests.CustomAttributes @@ -12,13 +12,13 @@ namespace ICSharpCode.Decompiler.Tests.CustomAttributes
}
[Test]
public void CustomAttributesMultiTest()
public void CustomAttributes()
{
ValidateFileRoundtrip(@"CustomAttributes/S_CustomAttributes.cs");
}
[Test]
public void AssemblyCustomAttributesMultiTest()
public void AssemblyCustomAttribute()
{
ValidateFileRoundtrip(@"CustomAttributes/S_AssemblyCustomAttribute.cs");
}

2
ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributeSamples.cs

@ -28,7 +28,7 @@ namespace ParameterLessAttributeUsage @@ -28,7 +28,7 @@ namespace ParameterLessAttributeUsage
[Flags]
public enum EnumWithFlagsAttribute
{
None = 0
None = 0x0
}
}
//$$ AttributeWithEnumArgument

10
ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs

@ -27,11 +27,11 @@ namespace CustomAttributes @@ -27,11 +27,11 @@ namespace CustomAttributes
public enum EnumWithFlag
{
All = 0xF,
None = 0,
Item1 = 1,
Item2 = 2,
Item3 = 4,
Item4 = 8
None = 0x0,
Item1 = 0x1,
Item2 = 0x2,
Item3 = 0x4,
Item4 = 0x8
}
[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute

8
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs

@ -26,10 +26,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -26,10 +26,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
[Flags]
private enum MyEnum
{
None = 0,
One = 1,
Two = 2,
Four = 4
None = 0x0,
One = 0x1,
Two = 0x2,
Four = 0x4
}
public enum ShortEnum : short

2
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1174,7 +1174,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1174,7 +1174,7 @@ namespace ICSharpCode.Decompiler.CSharp
long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false);
if (decompilationContext.CurrentTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "System.FlagsAttribute")) {
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, field.ConstantValue);
if (enumDec.Initializer is PrimitiveExpression primitive && initValue > 9)
if (enumDec.Initializer is PrimitiveExpression primitive)
primitive.SetValue(initValue, $"0x{initValue:X}");
} else if (previousValue + 1 != initValue) {
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, field.ConstantValue);

Loading…
Cancel
Save