1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT License.
33// See the LICENSE file in the project root for more information.
44
55using System ;
66using System . Linq ;
77using System . Reactive . Linq ;
8- using System . Reflection ;
98using Microsoft . Reactive . Testing ;
109using NUnit . Framework ;
11- using UnityEngine . TestTools ;
1210
1311namespace ReactiveTests . Tests
1412{
@@ -145,22 +143,21 @@ public void EitherSwitchAction()
145143
146144 internal class EitherBase
147145 {
148- protected object _value ;
146+ protected object ProxyValue ;
149147
150148 public override bool Equals ( object obj )
151149 {
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 ) ;
154151 }
155152
156153 public override int GetHashCode ( )
157154 {
158- return ( int ) _value . GetType ( ) . GetMethod ( nameof ( GetHashCode ) ) . Invoke ( _value , null ) ;
155+ return ( int ) ProxyValue . GetType ( ) . GetMethod ( nameof ( GetHashCode ) ) . Invoke ( ProxyValue , null ) ;
159156 }
160157
161158 public override string ToString ( )
162159 {
163- return ( string ) _value . GetType ( ) . GetMethod ( nameof ( ToString ) ) . Invoke ( _value , null ) ;
160+ return ( string ) ProxyValue . GetType ( ) . GetMethod ( nameof ( ToString ) ) . Invoke ( ProxyValue , null ) ;
164161 }
165162 }
166163
@@ -175,23 +172,20 @@ public static Either<TLeft, TRight> CreateRight(TRight value)
175172 {
176173 return new Right ( System . Reactive . Either < TLeft , TRight > . CreateRight ( value ) ) ;
177174 }
178-
175+
179176 public TResult Switch < TResult > ( Func < TLeft , TResult > caseLeft , Func < TRight , TResult > caseRight )
180177 {
181- return _value switch
178+ return ProxyValue switch
182179 {
183180 System . Reactive . Either < TLeft , TRight > . Left left => left . Switch ( caseLeft , caseRight ) ,
184181 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 ) } ") ,
186183 } ;
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 });
190184 }
191185
192186 public void Switch ( Action < TLeft > caseLeft , Action < TRight > caseRight )
193187 {
194- switch ( _value )
188+ switch ( ProxyValue )
195189 {
196190 case System . Reactive . Either < TLeft , TRight > . Left left :
197191 left . Switch ( caseLeft , caseRight ) ;
@@ -202,11 +196,8 @@ public void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight)
202196 break ;
203197
204198 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 ) } ") ;
206200 }
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 });
210201 }
211202
212203 public sealed class Left : Either < TLeft , TRight > , IEquatable < Left >
@@ -215,19 +206,19 @@ public TLeft Value
215206 {
216207 get
217208 {
218- return ( TLeft ) _value . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( _value , null ) ;
209+ return ( TLeft ) ProxyValue . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( ProxyValue , null ) ;
219210 }
220211 }
221212
222213 public Left ( System . Reactive . Either < TLeft , TRight > value )
223214 {
224- _value = value ;
215+ ProxyValue = value ;
225216 }
226217
227218 public bool Equals ( Left other )
228219 {
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 } ) ;
231222 }
232223 }
233224
@@ -237,19 +228,19 @@ public TRight Value
237228 {
238229 get
239230 {
240- return ( TRight ) _value . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( _value , null ) ;
231+ return ( TRight ) ProxyValue . GetType ( ) . GetProperty ( nameof ( Value ) ) . GetValue ( ProxyValue , null ) ;
241232 }
242233 }
243234
244235 public Right ( System . Reactive . Either < TLeft , TRight > value )
245236 {
246- _value = value ;
237+ ProxyValue = value ;
247238 }
248239
249240 public bool Equals ( Right other )
250241 {
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 } ) ;
253244 }
254245 }
255246 }
0 commit comments