From a6ae2e4b24241ad8a4430f3aa55f99ca934f69b3 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 2 Jun 2016 20:49:23 +0200 Subject: [PATCH] Fix #716: OverflowException when converting System.Enum To System.Int64 in CustomAttribute --- ICSharpCode.Decompiler/Ast/AstBuilder.cs | 3 ++- .../Tests/CustomAttributes/S_CustomAttributes.cs | 5 +++++ .../ICSharpCode.NRefactory.VB.Tests.csproj | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index aa97dc9bf..8dbf82cd3 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -1521,7 +1521,8 @@ namespace ICSharpCode.Decompiler.Ast } var type = argument.Type.Resolve(); if (type != null && type.IsEnum) { - return MakePrimitive(Convert.ToInt64(argument.Value), type); + long val = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, argument.Value, false); + return MakePrimitive(val, type); } else if (argument.Value is TypeReference) { return CreateTypeOfExpression((TypeReference)argument.Value); } else { diff --git a/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs b/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs index 37c1c0d71..67052909a 100644 --- a/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs +++ b/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs @@ -39,6 +39,11 @@ namespace aa { } } + [CustomAttributes.MyAttribute(CustomAttributes.ULongEnum.MaxUInt64)] + public enum ULongEnum : ulong + { + MaxUInt64 = 18446744073709551615uL + } [CustomAttributes.MyAttribute(CustomAttributes.EnumWithFlag.Item1 | CustomAttributes.EnumWithFlag.Item2)] private static int field; [CustomAttributes.MyAttribute(CustomAttributes.EnumWithFlag.All)] diff --git a/NRefactory.VB/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj b/NRefactory.VB/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj index 53e04c07e..ee1d38229 100644 --- a/NRefactory.VB/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj +++ b/NRefactory.VB/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj @@ -102,5 +102,8 @@ ICSharpCode.NRefactory + + + \ No newline at end of file