dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.56k stars 119 forks source link

Confusing example and behavior regarding `If(...).Then(() => ...)` #188

Closed alexrp closed 10 months ago

alexrp commented 10 months ago

The docs have this example:

Func<long, bool> isZero = Lambda<Func<long, bool>>(fun => 
{
    var arg = fun[0];
    If((Expression)(arg.AsDynamic() != 0L))
        .Then(() => Return(true))
        .Else(() => Return(false))
    .End();
}).Compile();

Is this doing what it's supposed to be doing? Trying this locally, .Then(() => ...) binds to ConditionalBuilder.Then(Expression), not CodeGenerator.Then(ConditionalBuilder, Action). This also makes the API a bit unwieldy in general, since I have to write code with casts like this:

If(...)
    .Then((Action)(() =>
    {
        // ...
    }))
.End()

Not sure if I'm misunderstanding something or if this is unintended. 🤔

sakno commented 10 months ago

Thanks to MS, they introduced breaking change. See https://github.com/dotnet/csharplang/discussions/5157. If you have any suggestions, I'm ready to discuss.