From 9e82b95373e697c6bc169ad6d0c3dc6df344c83e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 14 Feb 2020 23:48:26 +0100 Subject: [PATCH] Fix hexadecimal format of flags enum member initializers. --- .../CSharp/CSharpDecompiler.cs | 2 +- .../Syntax/Expressions/PrimitiveExpression.cs | 28 ++----------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index b4e5cf77b..740097fc3 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -1422,7 +1422,7 @@ namespace ICSharpCode.Decompiler.CSharp if (enumDec.Initializer is PrimitiveExpression primitive && initValue >= 0 && (decompilationContext.CurrentTypeDefinition.HasAttribute(KnownAttribute.Flags) || (initValue > 9 && (unchecked(initValue & (initValue - 1)) == 0 || unchecked(initValue & (initValue + 1)) == 0)))) { - primitive.SetValue(initValue, $"0x{initValue:X}"); + primitive.Format = LiteralFormat.HexadecimalNumber; } } enumDec.Attributes.AddRange(field.GetAttributes().Select(a => new AttributeSection(typeSystemAstBuilder.ConvertAttribute(a)))); diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs index 6ec67431d..eb45b4278 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/PrimitiveExpression.cs @@ -51,11 +51,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public static readonly object AnyValue = new object(); TextLocation startLocation; - public override TextLocation StartLocation { - get { - return startLocation; - } - } + TextLocation endLocation; + public override TextLocation StartLocation => startLocation; + public override TextLocation EndLocation => endLocation; internal void SetLocation(TextLocation startLocation, TextLocation endLocation) { @@ -64,18 +62,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax this.endLocation = endLocation; } - string literalValue; - TextLocation? endLocation; - public override TextLocation EndLocation { - get { - if (!endLocation.HasValue) { - endLocation = value is string ? AdvanceLocation (StartLocation, literalValue ?? "") : - new TextLocation (StartLocation.Line, StartLocation.Column + (literalValue ?? "").Length); - } - return endLocation.Value; - } - } - object value; LiteralFormat format; @@ -87,14 +73,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - public void SetValue(object value, string literalValue) - { - if (value == null) - throw new ArgumentNullException(); - ThrowIfFrozen(); - this.value = value; - this.literalValue = literalValue; - } public LiteralFormat Format { get { return format;}