Skip to content

Commit 401cb77

Browse files
Fix #3189: Support primitive types in Expression.Constant(object) pattern.
1 parent c269b99 commit 401cb77

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using System.Collections.Generic;
2121
using System.Diagnostics;
2222
using System.Linq;
23-
using System.Reflection;
2423

2524
using ICSharpCode.Decompiler.CSharp.Resolver;
2625
using ICSharpCode.Decompiler.Semantics;
@@ -1423,7 +1422,15 @@ bool MatchConstantCall(ILInstruction inst, out ILInstruction value, out IType ty
14231422
value = call.Arguments[0];
14241423
if (call.Arguments.Count == 2)
14251424
return MatchGetTypeFromHandle(call.Arguments[1], out type);
1426-
type = value.InferType(context.TypeSystem);
1425+
type = value switch {
1426+
LdNull => SpecialType.NullType,
1427+
LdStr => context.TypeSystem.FindType(KnownTypeCode.String),
1428+
LdcF4 => context.TypeSystem.FindType(KnownTypeCode.Single),
1429+
LdcF8 => context.TypeSystem.FindType(KnownTypeCode.Double),
1430+
LdcI4 => context.TypeSystem.FindType(KnownTypeCode.Int32),
1431+
LdcI8 => context.TypeSystem.FindType(KnownTypeCode.Int64),
1432+
_ => value.InferType(context.TypeSystem),
1433+
};
14271434
return true;
14281435
}
14291436
return false;

0 commit comments

Comments
 (0)