DelegateDecompiler
DelegateDecompiler copied to clipboard
.net 8 or vs ||
With .net 8 RC2 the "or" causes an exception when decompile, while "||" works. With .net 7 "or" and "||" both works fine.
Unhandled exception. System.InvalidOperationException: The binary operator LessThanOrEqual is not defined for the types 'ConsoleApp1.TestEnum' and 'System.Int32'.
Here is some sample code:
public class TestClass
{
public Guid Id { get; set; }
public TestEnum Enum { get; set; }
// will throw
[Computed] public bool TestWithOr => Enum is TestEnum.A or TestEnum.B;
// works
[Computed] public bool TestWithPipes => Enum is TestEnum.A || Enum is TestEnum.B;
}
public enum TestEnum
{
A,B,C
}
and try to decompile
using var db = new TestContext();
var testPipes = db.TestClasses.Where(x => x.TestWithPipes).Decompile().FirstOrDefault();
Console.WriteLine("Test with pipes woks.");
// this will fail
var testOr = db.TestClasses.Where(x => x.TestWithOr).Decompile().FirstOrDefault();
Console.WriteLine("Test with or woks.");
That is interesting. .NET 8 optimized the condition to:
public bool TestWithOr
{
get
{
TestEnum @enum = Enum;
if ((uint)@enum <= 1u)
{
return true;
}
return false;
}
}