Skip to content

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

Closed

Description

@alexrp

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. 🤔

Activity

  1. sakno commented on Aug 23, 2023

    @sakno
    Collaborator

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

  2. locked and limited conversation to collaborators on Aug 23, 2023
  3. converted this issue into a discussion #189 on Aug 23, 2023
  4. added a commit that references this issue on Aug 23, 2023
    e6c7499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions