1
- // Licensed to the .NET Foundation under one or more agreements.
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT License.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System ;
6
6
using System . Linq ;
7
7
using System . Reactive . Linq ;
8
- using System . Reflection ;
9
8
using Microsoft . Reactive . Testing ;
10
9
using NUnit . Framework ;
11
- using UnityEngine . TestTools ;
12
10
13
11
namespace ReactiveTests . Tests
14
12
{
@@ -145,22 +143,21 @@ public void EitherSwitchAction()
145
143
146
144
internal class EitherBase
147
145
{
148
- protected object _value ;
146
+ protected object ProxyValue ;
149
147
150
148
public override bool Equals ( object obj )
151
149
{
152
- var equ = _value . GetType ( ) . GetMethods ( ) . Where ( m => m . Name == "Equals" && m . GetParameters ( ) [ 0 ] . ParameterType == typeof ( object ) ) . Single ( ) ;
153
- return ( bool ) equ . Invoke ( _value , new object [ ] { obj is EitherBase ? ( ( EitherBase ) obj ) . _value : obj } ) ;
150
+ return ProxyValue . Equals ( obj is EitherBase ? ( ( EitherBase ) obj ) . ProxyValue : obj ) ;
154
151
}
155
152
156
153
public override int GetHashCode ( )
157
154
{
158
- return ( int ) _value . GetType ( ) . GetMethod ( nameof ( GetHashCode ) ) . Invoke ( _value , null ) ;
155
+ return ( int ) ProxyValue . GetType ( ) . GetMethod ( nameof ( GetHashCode ) ) . Invoke ( ProxyValue , null ) ;
159
156
}
160
157
161
158
public override string ToString ( )
162
159
{
163
- return ( string ) _value . GetType ( ) . GetMethod ( nameof ( ToString ) ) . Invoke ( _value , null ) ;
160
+ return ( string ) ProxyValue . GetType ( ) . GetMethod ( nameof ( ToString ) ) . Invoke ( ProxyValue , null ) ;
164
161
}
165
162
}
166
163
@@ -175,23 +172,20 @@ public static Either<TLeft, TRight> CreateRight(TRight value)
175
172
{
176
173
return new Right ( System . Reactive . Either < TLeft , TRight > . CreateRight ( value ) ) ;
177
174
}
178
-
175
+
179
176
public TResult Switch < TResult > ( Func < TLeft , TResult > caseLeft , Func < TRight , TResult > caseRight )
180
177
{
181
- return _value switch
178
+ return ProxyValue switch
182
179
{
183
180
System . Reactive . Either < TLeft , TRight > . Left left => left . Switch ( caseLeft , caseRight ) ,
184
181
System . Reactive . Either < TLeft , TRight > . Right right => right . Switch ( caseLeft , caseRight ) ,
185
- _ => throw new InvalidOperationException ( $ "This instance was created using an unsupported type { _value . GetType ( ) } for a { nameof ( _value ) } ") ,
182
+ _ => throw new InvalidOperationException ( $ "This instance was created using an unsupported type { ProxyValue . GetType ( ) } for a { nameof ( ProxyValue ) } ") ,
186
183
} ;
187
-
188
- //var mth = _value.GetType().GetMethods().Where(m => m.Name == nameof(Switch) && m.ReturnType != typeof(void)).Single().MakeGenericMethod(typeof(TResult));
189
- //return (TResult)mth.Invoke(_value, new object[] { caseLeft, caseRight });
190
184
}
191
185
192
186
public void Switch ( Action < TLeft > caseLeft , Action < TRight > caseRight )
193
187
{
194
- switch ( _value )
188
+ switch ( ProxyValue )
195
189
{
196
190
case System . Reactive . Either < TLeft , TRight > . Left left :
197
191
left . Switch ( caseLeft , caseRight ) ;
@@ -202,11 +196,8 @@ public void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight)
202
196
break ;
203
197
204
198
default :
205
- throw new InvalidOperationException ( $ "This instance was created using an unsupported type { _value . GetType ( ) } for a { nameof ( _value ) } ") ;
199
+ throw new InvalidOperationException ( $ "This instance was created using an unsupported type { ProxyValue . GetType ( ) } for a { nameof ( ProxyValue ) } ") ;
206
200
}
207
-
208
- //var mth = _value.GetType().GetMethods().Where(m => m.Name == nameof(Switch) && m.ReturnType == typeof(void)).Single();
209
- //mth.Invoke(_value, new object[] { caseLeft, caseRight });
210
201
}
211
202
212
203
public sealed class Left : Either < TLeft , TRight > , IEquatable < Left >
@@ -215,19 +206,19 @@ public TLeft Value
215
206
{
216
207
get
217
208
{
218
- return ( TLeft ) _value . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( _value , null ) ;
209
+ return ( TLeft ) ProxyValue . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( ProxyValue , null ) ;
219
210
}
220
211
}
221
212
222
213
public Left ( System . Reactive . Either < TLeft , TRight > value )
223
214
{
224
- _value = value ;
215
+ ProxyValue = value ;
225
216
}
226
217
227
218
public bool Equals ( Left other )
228
219
{
229
- var equ = _value . GetType ( ) . GetMethods ( ) . Where ( m => m . Name == nameof ( Equals ) && m . GetParameters ( ) [ 0 ] . ParameterType != typeof ( object ) ) . Single ( ) ;
230
- return ( bool ) equ . Invoke ( _value , new object [ ] { other ? . _value } ) ;
220
+ var equ = ProxyValue . GetType ( ) . GetMethods ( ) . Where ( m => m . Name == nameof ( Equals ) && m . GetParameters ( ) [ 0 ] . ParameterType != typeof ( object ) ) . Single ( ) ;
221
+ return ( bool ) equ . Invoke ( ProxyValue , new object [ ] { other ? . ProxyValue } ) ;
231
222
}
232
223
}
233
224
@@ -237,19 +228,19 @@ public TRight Value
237
228
{
238
229
get
239
230
{
240
- return ( TRight ) _value . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( _value , null ) ;
231
+ return ( TRight ) ProxyValue . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( ProxyValue , null ) ;
241
232
}
242
233
}
243
234
244
235
public Right ( System . Reactive . Either < TLeft , TRight > value )
245
236
{
246
- _value = value ;
237
+ ProxyValue = value ;
247
238
}
248
239
249
240
public bool Equals ( Right other )
250
241
{
251
- var equ = _value . GetType ( ) . GetMethods ( ) . Where ( m => m . Name == nameof ( Equals ) && m . GetParameters ( ) [ 0 ] . ParameterType != typeof ( object ) ) . Single ( ) ;
252
- return ( bool ) equ . Invoke ( _value , new object [ ] { other ? . _value } ) ;
242
+ var equ = ProxyValue . GetType ( ) . GetMethods ( ) . Where ( m => m . Name == nameof ( Equals ) && m . GetParameters ( ) [ 0 ] . ParameterType != typeof ( object ) ) . Single ( ) ;
243
+ return ( bool ) equ . Invoke ( ProxyValue , new object [ ] { other ? . ProxyValue } ) ;
253
244
}
254
245
}
255
246
}
0 commit comments