Permalink
Browse files

Fix #716: OverflowException when converting System.Enum To System.Int…

…64 in CustomAttribute
  • Loading branch information...
1 parent 6d4ad50 commit a6ae2e4b24241ad8a4430f3aa55f99ca934f69b3 @dgrunwald dgrunwald committed Jun 2, 2016
@@ -1521,7 +1521,8 @@ private static Expression ConvertArgumentValue(CustomAttributeArgument argument)
}
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 {
@@ -39,6 +39,11 @@ public MyAttribute(object val)
{
}
}
+ [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)]
@@ -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>

0 comments on commit a6ae2e4

Please sign in to comment.