Comments (3)
I've done a little more digging. I think the problem is that the decompiled IL won't contain a cast by design for certain compatible types. For example, if I put the following into LINQPad (I just picked an arbitrary enum):
StringComparison s = StringComparison.CurrentCultureIgnoreCase;
int x = (int)s % 10;
It generates the following IL:
IL_0001: ldc.i4.1
IL_0002: stloc.0 // s
IL_0003: ldloc.0 // s
IL_0004: ldc.i4.s 0A
IL_0006: rem
IL_0007: stloc.1 // x
You can see there's no attempt to convert the enum to an int (which makes sense - enum is obviously a compiler construct). This looks almost identical to the IL generated by the following:
int i = 1;
int x = i % 10;
Which generates:
IL_0001: ldc.i4.1
IL_0002: stloc.0 // i
IL_0003: ldloc.0 // i
IL_0004: ldc.i4.s 0A
IL_0006: rem
IL_0007: stloc.1 // x
So I think the problem is that while the IL we get back from Mono.Reflection
is correct, the Processor
class is not inferring casts when it should because they sometimes get lost in the journey from MethodInfo
to IL as part of the optimization.
The solution would be to check for these cases and insert Expression.Convert()
calls into the expression tree generated by the Processor
when needed. I'll take a look and see if I can find any OSS decompiler code that already implements a check like this.
from delegatedecompiler.
We already have AdjustType method which should do this. I'll check later.
from delegatedecompiler.
Great - thanks. Hadn't noticed the AdjustType method. Just let me know if there's anything else I can do to help with this.
from delegatedecompiler.
Related Issues (20)
- Auto Detect ShouldDecompile members
- ArgumentException for a simple method HOT 1
- Decompiler does not remove transparent identifier expression on root level HOT 2
- Error decompiling unary operator Not for enum parameter
- DelegateDecompiler.EntityFrameworkCore .Net 5 support HOT 1
- NullReferenceException only dotcover test coverage runner HOT 8
- ArgumentException Type must not be ByRef under dotcover HOT 9
- InvalidOperationException on array of enums HOT 1
- No implementation of Decompile extension method for non-generic IQueryable
- Abstract property in hierachy with intermediate generic classes decompiled as default
- EntityFramework Core 6 (.NET6) HOT 1
- Exception using SelectMany
- No coercion operator is defined between types 'System.Int32' and 'System.Nullable`1[System.Boolean]'. - regression between 0.29.1 and 0.30.0 HOT 1
- Automatically decompile using a IDbContextOptionsExtension like LinqKit does? HOT 3
- Unit test failure HOT 3
- Bug: Cannot Decompile IQueryable<T> after using constrained generic when TInterface has multiple implementations HOT 5
- Delegate Decompiler with in-memory databases HOT 1
- Null reference error in TypeHierarchy.BuildChildren
- Performance regression from 0.31.0 to 0.32.0
- .net 8 or vs || HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from delegatedecompiler.