Skip to content

Idea: the DU source-generator automatically writes the dispatching of the Match. #779

Closed

Description

@FreeApophis

I often rely on polymorphic overloads of the same method to handle DU cases indivdually:

Ideally I would have some syntax like this:

shape.Dipatch(Canvas.Draw);

This is obviously not possible, usually I write code like this: I write a public function which is delegating to individual overloads of the same Methodgroup. This is similar to the accept method in the visitor pattern:

public static Task<Image> Draw(Shape shape)
        => shape.Match(triangle: Draw, rectangle: Draw, polygon: Draw);

Source Generator:

[DispatchToMethodGroup] // name to discuss...
public partial static Task<Image> Draw(Shape shape)

DispatchToMethodGroup could take a parameter name optionally.

[DispatchToMethodGroup(nameof(Canvas.DrawInternal))]
public partial static Task<Image> Draw(Shape shape)

Activity

  1. FreeApophis commented on Sep 24, 2026

    @FreeApophis
    MemberAuthor

    Closed: see parent item.

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

    area: DiscriminatedUnionIssues for Funcky.DiscriminateUnionto discussThere are open points which need to be discussed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions