44namespace Firecrawl
55{
66 /// <summary>
7- ///
7+ ///
88 /// </summary>
99 public readonly partial struct AllOf < T1 , T2 > : global ::System . IEquatable < AllOf < T1 , T2 > >
1010 {
1111 /// <summary>
12- ///
12+ ///
1313 /// </summary>
1414#if NET6_0_OR_GREATER
1515 public T1 ? Value1 { get ; init ; }
@@ -18,15 +18,28 @@ namespace Firecrawl
1818#endif
1919
2020 /// <summary>
21- ///
21+ ///
2222 /// </summary>
2323#if NET6_0_OR_GREATER
2424 [ global ::System . Diagnostics . CodeAnalysis . MemberNotNullWhen ( true , nameof ( Value1 ) ) ]
2525#endif
2626 public bool IsValue1 => Value1 != null ;
2727
2828 /// <summary>
29- ///
29+ ///
30+ /// </summary>
31+ public bool TryPickValue1 (
32+ #if NET6_0_OR_GREATER
33+ [ global ::System . Diagnostics . CodeAnalysis . NotNullWhen ( true ) ]
34+ #endif
35+ out T1 ? value )
36+ {
37+ value = Value1 ;
38+ return IsValue1 ;
39+ }
40+
41+ /// <summary>
42+ ///
3043 /// </summary>
3144#if NET6_0_OR_GREATER
3245 public T2 ? Value2 { get ; init ; }
@@ -35,50 +48,63 @@ namespace Firecrawl
3548#endif
3649
3750 /// <summary>
38- ///
51+ ///
3952 /// </summary>
4053#if NET6_0_OR_GREATER
4154 [ global ::System . Diagnostics . CodeAnalysis . MemberNotNullWhen ( true , nameof ( Value2 ) ) ]
4255#endif
4356 public bool IsValue2 => Value2 != null ;
57+
58+ /// <summary>
59+ ///
60+ /// </summary>
61+ public bool TryPickValue2 (
62+ #if NET6_0_OR_GREATER
63+ [ global ::System . Diagnostics . CodeAnalysis . NotNullWhen ( true ) ]
64+ #endif
65+ out T2 ? value )
66+ {
67+ value = Value2 ;
68+ return IsValue2 ;
69+ }
4470 /// <summary>
45- ///
71+ ///
4672 /// </summary>
4773 public static implicit operator AllOf < T1 , T2 > ( T1 value ) => new AllOf < T1 , T2 > ( ( T1 ? ) value ) ;
4874
4975 /// <summary>
50- ///
76+ ///
5177 /// </summary>
5278 public static implicit operator T1 ? ( AllOf < T1 , T2 > @this ) => @this . Value1 ;
5379
5480 /// <summary>
55- ///
81+ ///
5682 /// </summary>
5783 public AllOf ( T1 ? value )
5884 {
5985 Value1 = value ;
6086 }
6187
6288 /// <summary>
63- ///
89+ ///
6490 /// </summary>
6591 public static implicit operator AllOf < T1 , T2 > ( T2 value ) => new AllOf < T1 , T2 > ( ( T2 ? ) value ) ;
6692
6793 /// <summary>
68- ///
94+ ///
6995 /// </summary>
7096 public static implicit operator T2 ? ( AllOf < T1 , T2 > @this ) => @this . Value2 ;
7197
7298 /// <summary>
73- ///
99+ ///
74100 /// </summary>
75101 public AllOf ( T2 ? value )
76102 {
77103 Value2 = value ;
78104 }
79105
80106 /// <summary>
81- ///
107+ ///
82108 /// </summary>
83109 public AllOf (
84110 T1 ? value1 ,
@@ -90,56 +116,45 @@ public AllOf(
90116 }
91117
92118 /// <summary>
93- ///
119+ ///
94120 /// </summary>
95121 public object ? Object =>
96122 Value2 as object ??
97- Value1 as object
123+ Value1 as object
98124 ;
99125
100126 /// <summary>
101- ///
127+ ///
102128 /// </summary>
103129 public override string ? ToString ( ) =>
104130 Value1 ? . ToString ( ) ??
105- Value2 ? . ToString ( )
131+ Value2 ? . ToString ( )
106132 ;
107133
108- private static bool RequiresValue < TValue > ( ) => RequirementCache < TValue > . Value ;
109-
110- private static bool DetermineRequiresValue ( global ::System . Type type )
134+ private static bool RequiresValue < TValue > ( )
111135 {
136+ var type = typeof ( TValue ) ;
112137 if ( global ::System . Nullable . GetUnderlyingType ( type ) != null )
113138 {
114139 return false ;
115140 }
116141
117- if ( type . IsValueType ||
118- type == typeof ( string ) ||
119- type . IsArray )
120- {
121- return true ;
122- }
123-
124- return false ;
125- }
126-
127- private static class RequirementCache < TValue >
128- {
129- public static readonly bool Value = DetermineRequiresValue ( typeof ( TValue ) ) ;
142+ return type . IsValueType ||
143+ type == typeof ( string ) ||
144+ type . IsArray ;
130145 }
131146
132147
133148 /// <summary>
134- ///
149+ ///
135150 /// </summary>
136151 public bool Validate ( )
137152 {
138153 return ( ! RequiresValue < T1 > ( ) || IsValue1 ) && ( ! RequiresValue < T2 > ( ) || IsValue2 ) ;
139154 }
140155
141156 /// <summary>
142- ///
157+ ///
143158 /// </summary>
144159 public TResult ? Match < TResult > (
145160 global ::System . Func < T1 , TResult > ? value1 = null ,
@@ -164,10 +179,34 @@ public bool Validate()
164179 }
165180
166181 /// <summary>
167- ///
182+ ///
168183 /// </summary>
169184 public void Match (
170185 global ::System . Action < T1 > ? value1 = null ,
186+
187+ global ::System . Action < T2 > ? value2 = null ,
188+ bool validate = true )
189+ {
190+ if ( validate )
191+ {
192+ Validate ( ) ;
193+ }
194+
195+ if ( IsValue1 )
196+ {
197+ value1 ? . Invoke ( Value1 ! ) ;
198+ }
199+ else if ( IsValue2 )
200+ {
201+ value2 ? . Invoke ( Value2 ! ) ;
202+ }
203+ }
204+
205+ /// <summary>
206+ ///
207+ /// </summary>
208+ public void Switch (
209+ global ::System . Action < T1 > ? value1 = null ,
171210 global ::System . Action < T2 > ? value2 = null ,
172211 bool validate = true )
173212 {
@@ -187,7 +226,7 @@ public void Match(
187226 }
188227
189228 /// <summary>
190- ///
229+ ///
191230 /// </summary>
192231 public override int GetHashCode ( )
193232 {
@@ -208,34 +247,34 @@ static int HashCodeAggregator(int hashCode, object? value) => value == null
208247 }
209248
210249 /// <summary>
211- ///
250+ ///
212251 /// </summary>
213252 public bool Equals ( AllOf < T1 , T2 > other )
214253 {
215254 return
216255 global ::System . Collections . Generic . EqualityComparer < T1 ? > . Default . Equals ( Value1 , other . Value1 ) &&
217- global ::System . Collections . Generic . EqualityComparer < T2 ? > . Default . Equals ( Value2 , other . Value2 )
256+ global ::System . Collections . Generic . EqualityComparer < T2 ? > . Default . Equals ( Value2 , other . Value2 )
218257 ;
219258 }
220259
221260 /// <summary>
222- ///
261+ ///
223262 /// </summary>
224263 public static bool operator == ( AllOf < T1 , T2 > obj1 , AllOf < T1 , T2 > obj2 )
225264 {
226265 return global ::System . Collections . Generic . EqualityComparer < AllOf < T1 , T2 > > . Default . Equals ( obj1 , obj2 ) ;
227266 }
228267
229268 /// <summary>
230- ///
269+ ///
231270 /// </summary>
232271 public static bool operator != ( AllOf < T1 , T2 > obj1 , AllOf < T1 , T2 > obj2 )
233272 {
234273 return ! ( obj1 == obj2 ) ;
235274 }
236275
237276 /// <summary>
238- ///
277+ ///
239278 /// </summary>
240279 public override bool Equals ( object ? obj )
241280 {
0 commit comments