Skip to content

Decompiling throws InvalidOperationException for enums with underlying type other than int #96

@gvas

Description

@gvas

.NET Framework 4.5.2
DelegateDecompiler 0.21.0

enum PayGrade : byte
{
    Low,
    High
}

class Employee
{
    public PayGrade PayGrade { get; set; }

    [Computed]
    public decimal Salary
    {
        get
        {
            if (PayGrade == PayGrade.High)
            {
                return 1000M;
            }

            return 10M;
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        var employees = new[]
        {
            new Employee { PayGrade = PayGrade.Low },
            new Employee { PayGrade = PayGrade.High },
        }
        .AsQueryable();

        var salaries = (from employee in employees
                        select employee.Salary)
                        .Decompile()
                        .ToList();
    }
}

The code above throws an InvalidOperationException with the following message:
"The binary operator Equal is not defined for the types 'System.Byte' and 'System.Int32'."

Changing the PayGrade enum's underlying type to int prevents the exception.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions