From 5504a765dc7cc153207db5b6d56a5fcf0e3526d5 Mon Sep 17 00:00:00 2001 From: Kyle Ratti Date: Fri, 3 May 2024 17:07:44 -0400 Subject: [PATCH] BREAKING CHANGE: feat: use record struct for OneOf --- Base/Structures/OneOf.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Base/Structures/OneOf.cs b/Base/Structures/OneOf.cs index 5a082c4..1c9a814 100644 --- a/Base/Structures/OneOf.cs +++ b/Base/Structures/OneOf.cs @@ -2,14 +2,18 @@ namespace FruityFoundation.Base.Structures; -public class OneOf +public readonly record struct OneOf { - private Maybe _itemOne { get; } - private Maybe _itemTwo { get; } + private readonly Maybe _itemOne; + private readonly Maybe _itemTwo; public T1 ItemOne => _itemOne.OrThrow($"{nameof(ItemOne)} must have a value in order to be accessed"); public T2 ItemTwo => _itemTwo.OrThrow($"{nameof(ItemTwo)} must have a value in order to be accessed"); + /// + /// Exposes the underlying object as an object. + /// This is useful for pattern matching from C#. + /// public object? RawItem { get @@ -46,14 +50,18 @@ public class OneOf public class OneOf { - private Maybe _itemOne { get; } - private Maybe _itemTwo { get; } - private Maybe _itemThree { get; } + private readonly Maybe _itemOne; + private readonly Maybe _itemTwo; + private readonly Maybe _itemThree; public T1 ItemOne => _itemOne.OrThrow($"{nameof(ItemOne)} must have a value in order to be accessed"); public T2 ItemTwo => _itemTwo.OrThrow($"{nameof(ItemTwo)} must have a value in order to be accessed"); public T3 ItemThree => _itemThree.OrThrow($"{nameof(ItemThree)} must have a value in order to be accessed"); + /// + /// Exposes the underlying object as an object. + /// This is useful for pattern matching from C#. + /// public object? RawItem { get @@ -108,4 +116,4 @@ public class OneOf public static implicit operator OneOf(T1 oneOf) => new(oneOf, default, default); public static implicit operator OneOf(T2 oneOf) => new(default, oneOf, default); public static implicit operator OneOf(T3 oneOf) => new(default, default, oneOf); -} \ No newline at end of file +}