Browse Source

Consider constructor type when lifting decimal constants

pull/2953/head
ElektroKill 2 years ago
parent
commit
bf0fe3aa15
No known key found for this signature in database
GPG Key ID: 7E3C5C084E40E3EC
  1. 17
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

17
ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// Copyright (c) 2014-2017 Daniel Grunwald
// Copyright (c) 2014-2017 Daniel Grunwald
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
@ -428,11 +428,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -428,11 +428,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var args = inst.Arguments;
if (args.Count == 1)
{
int val;
if (args[0].MatchLdcI4(out val))
long val;
if (args[0].MatchLdcI(out val))
{
result = new LdcDecimal(val);
return true;
var paramType = inst.Method.Parameters[0].Type.GetDefinition()?.KnownTypeCode;
result = paramType switch {
KnownTypeCode.Int32 => new LdcDecimal(new decimal((int)val)),
KnownTypeCode.UInt32 => new LdcDecimal(new decimal((uint)val)),
KnownTypeCode.Int64 => new LdcDecimal(new decimal(val)),
KnownTypeCode.UInt64 => new LdcDecimal(new decimal((ulong)val)),
_ => null
};
return result is not null;
}
}
else if (args.Count == 5)

Loading…
Cancel
Save