diff --git a/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs b/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs index e7bc4ed69..a5d5de72c 100644 --- a/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; +using ICSharpCode.NRefactory.Utils; using Ast = ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp; using Cecil = Mono.Cecil; @@ -500,11 +501,11 @@ namespace Decompiler return new Ast.PrimitiveExpression(false); else if (byteCode.InferredType == typeSystem.Boolean && (int)operand == 1) return new Ast.PrimitiveExpression(true); - if (byteCode.InferredType != null && byteCode.InferredType.IsValueType) { + if (byteCode.InferredType != null) { // cannot rely on IsValueType, it's not set for typerefs (but is set for typespecs) TypeDefinition enumDefinition = byteCode.InferredType.Resolve(); if (enumDefinition != null && enumDefinition.IsEnum) { foreach (FieldDefinition field in enumDefinition.Fields) { - if (field.IsStatic && object.Equals(field.Constant, operand)) + if (field.IsStatic && object.Equals(CSharpPrimitiveCast.Cast(TypeCode.Int32, field.Constant, false), operand)) return AstBuilder.ConvertType(enumDefinition).Member(field.Name).WithAnnotation(field); } } diff --git a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs index 6ce6c77d9..4f99002ce 100644 --- a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs +++ b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs @@ -620,13 +620,11 @@ namespace Decompiler { if (type == null) return null; - if (type.IsValueType) { - // value type might be an enum - TypeDefinition typeDef = type.Resolve() as TypeDefinition; - if (typeDef != null && typeDef.IsEnum) { - TypeReference underlyingType = typeDef.Fields.Single(f => f.IsRuntimeSpecialName && !f.IsStatic).FieldType; - return IsSigned(typeDef.Module.TypeSystem, underlyingType); - } + // unfortunately we cannot rely on type.IsValueType here - it's not set when the instruction operand is a typeref (as opposed to a typespec) + TypeDefinition typeDef = type.Resolve() as TypeDefinition; + if (typeDef != null && typeDef.IsEnum) { + TypeReference underlyingType = typeDef.Fields.Single(f => f.IsRuntimeSpecialName && !f.IsStatic).FieldType; + return IsSigned(typeDef.Module.TypeSystem, underlyingType); } if (type == typeSystem.Byte || type == typeSystem.UInt16 || type == typeSystem.UInt32 || type == typeSystem.UInt64 || type == typeSystem.UIntPtr) return false;