Browse Source

forcing printing all initializers of members of Flags enums.

pull/52/head
Artur Zgodziski 15 years ago
parent
commit
d8588bde2a
  1. 3
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 10
      ICSharpCode.Decompiler/Tests/Types/EnumSamples.cs

3
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -162,6 +162,7 @@ namespace Decompiler @@ -162,6 +162,7 @@ namespace Decompiler
if (typeDef.IsEnum) {
long expectedEnumMemberValue = 0;
bool forcePrintingInitializers = IsFlagsEnum(typeDef);
foreach (FieldDefinition field in typeDef.Fields) {
if (field.IsRuntimeSpecialName) {
// the value__ field
@ -170,7 +171,7 @@ namespace Decompiler @@ -170,7 +171,7 @@ namespace Decompiler
EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
enumMember.Name = CleanName(field.Name);
long memberValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.Constant, false);
if (memberValue != expectedEnumMemberValue) {
if (forcePrintingInitializers || memberValue != expectedEnumMemberValue) {
enumMember.AddChild(new PrimitiveExpression(field.Constant), EnumMemberDeclaration.InitializerRole);
}
expectedEnumMemberValue = memberValue + 1;

10
ICSharpCode.Decompiler/Tests/Types/EnumSamples.cs

@ -102,3 +102,13 @@ public enum TS_DeclarationByteWithInitializers : byte @@ -102,3 +102,13 @@ public enum TS_DeclarationByteWithInitializers : byte
Item2 = 20,
Item3
}
//$$ DeclarationFlags
[Flags]
public enum TS_DeclarationFlags
{
None = 0,
Item1 = 1,
Item2 = 2,
Item3 = 4,
All = 7
}

Loading…
Cancel
Save