Closed gansmmm closed 4 years ago
Exact same issue here, thanks for the detailed description.
I was able to find a work around. If you replace 0 with a variable the compiler can't replace it with GetValueOrDefault(). I'm guessing it can't be a const otherwise it might get optimized away.
public class TEntity
{
public int? Int { get; set; }
private static readonly int Zero = 0;
[Computed]
public int Computed => Int ?? Zero;
}
I have a potential fix for this, do you take pull requests? Any guidance on how to submit those?
I added this code to DelegateDecompiler.Processor.BuildMethodCall:
if (m.Name == "GetValueOrDefault" && m.DeclaringType.IsGenericType && m.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable<>) && arguments.Length == 0)
{
return Expression.Coalesce(instance, ExpressionHelper.Default(Nullable.GetUnderlyingType(instance.Type)));
}
TestGroup15Aggregation.Test02Sum.TestSumCountInChildrenWhereChildrenCanBeNone was failing for me in VS 2019 before the added change. It passed afterwards.
I'm getting a lot of other test failures as a result of this change, does it seem to be working for everyone else?
@hazzik Could you please look into this issue / pull request? I can't work in VS2019 on some projects where I am using this library and more people seem to be having problems.
Operator
??
in Computed property decompiled intoGetValueOrDefault()
. If use EntityFramework this this behavior throw exception.Code
Decompiled to in VS 2017 Community version 15.9.11
in VS 2019 Community version 16.0.2
C# 7.3 .Net Framework 4.7.2