Skip to content

Discriminated Unions #1413

Answered by rhemsuda
rhemsuda asked this question in Q&A
Discussion options

You must be logged in to vote

I may have found an answer! 😄 It's a bit heavy in boilerplate but at least I can localize this boilerplate for the time-being, and it's safe at compile-time

public abstract record Document
{
    public Guid ID { get; init; }
    public Guid LocatorID { get; init; }
    public FileDetails FileDetails { get; init; }

    protected Document(Guid id, Guid locatorId, FileDetails fileDetails) 
    {
        ID = id;
        LocatorID = locatorId;
        FileDetails = fileDetails;
    }

    public abstract TResult Match<TResult>(
        Func<RawDocument, TResult> RawDocument,
        Func<PDFDocument, TResult> PDFDocument,
        Func<CSVDocument, TResult> CSVDocument,
        Func<PAMDataDo…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by rhemsuda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants