This repo contains the implementation in a functional way of the functinality described here:
In order to do this, I went into a learning journey. Find the details here:
A library I recently discovered is Dunet, which has a different approach than OneOf.
Dunet uses newer verison of the Microsoft.CodeAnalysis.Common
and Microsoft.CodeAnalysis.CSharp
that EF, so I had to run:
dotnet add package Microsoft.CodeAnalysis.Common --version 4.7.0
dotnet add package Microsoft.CodeAnalysis.CSharp --version 4.7.0
Then I get the warnings for the different libs, but it builds and runs.
- I actually like this library a lot, it it a bit opinionated because it emulates how other languages are declaring DUs: with a base "name" that has different defined values. So here I need a base record with the different valeus as othe records.
- The syntax is simple and easy to remember and a lot less verbose than OneOf, since I can return only the base type in any method.
- I like the apporach with the autogenerated extension methods (specially because it adds some extra methods with your DU's values names) but it can add clutter to intelli sense (which is a complaint I have heard before).
- I also like that only 1 method (
Match()
) is used for both Actions and Funcs. - For unit tests, I have used the autogenerated
MatchAddNew()
method, so that I keep the pattern amtching style syntax. It also gives me the false option where the result is not of the epected type so I can add a check there. - I have proposed to add a
Func<BaseUnionType>
as the second parameter so that the actual value can be used in the "false path": domn1995/dunet#193 - If I am only looking at working with DUs, I think I will use Dunet instead of OneOf.