Browse Source

Fix #716: OverflowException when converting System.Enum To System.Int64 in CustomAttribute

pull/724/head
Daniel Grunwald 9 years ago
parent
commit
a6ae2e4b24
  1. 3
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 5
      ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs
  3. 3
      NRefactory.VB/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj

3
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -1521,7 +1521,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -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 {

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

@ -39,6 +39,11 @@ namespace aa @@ -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)]

3
NRefactory.VB/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj

@ -102,5 +102,8 @@ @@ -102,5 +102,8 @@
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>
Loading…
Cancel
Save