@@ -150,11 +150,11 @@ private static SetupArgumentDefinitions WrapArgumentDefinitions(SetupArgumentDef
150150 Expression setupExpression ;
151151 if ( isRef || isOut )
152152 {
153- setupExpression = BuildRefArgumentExpression ( i , definition , parameterType , elementType , ref forwardedArgs ) ;
153+ setupExpression = BuildPassByRefArgumentExpression ( i , definition , parameterType , elementType , ref forwardedArgs ) ;
154154 }
155155 else
156156 {
157- setupExpression = BuildValueArgumentExpression ( i , definition , parameterType ) ;
157+ setupExpression = BuildPassByValueArgumentExpression ( i , definition , parameterType ) ;
158158 }
159159
160160 resolvedArguments . Add ( setupExpression ) ;
@@ -163,7 +163,7 @@ private static SetupArgumentDefinitions WrapArgumentDefinitions(SetupArgumentDef
163163 return ( resolvedArguments , forwardedArgs ) ;
164164 }
165165
166- private Expression BuildValueArgumentExpression ( int index , SetupArgumentDefinition definition , Type parameterType )
166+ private Expression BuildPassByValueArgumentExpression ( int index , SetupArgumentDefinition definition , Type parameterType )
167167 {
168168 var itType = typeof ( It ) ;
169169 MethodInfo itMemberInfo ;
@@ -174,7 +174,7 @@ private Expression BuildValueArgumentExpression(int index, SetupArgumentDefiniti
174174 switch ( definition . Type )
175175 {
176176 case SetupArgumentType . Is :
177- itMemberInfo = itType . GetMethod ( nameof ( It . Is ) ) . MakeGenericMethod ( parameterType ) ;
177+ itMemberInfo = itType . GetMethods ( ) . Single ( x => x . Name == nameof ( It . Is ) && x . IsGenericMethodDefinition && x . GetParameters ( ) . All ( y => y . ParameterType . GetGenericArguments ( ) . All ( z => z . GetGenericTypeDefinition ( ) == typeof ( Func < , > ) ) ) ) . MakeGenericMethod ( parameterType ) ;
178178 var value = definition . Values [ 0 ] ;
179179 if ( value != null && value . GetType ( ) != parameterType )
180180 {
@@ -234,7 +234,7 @@ private Expression BuildValueArgumentExpression(int index, SetupArgumentDefiniti
234234 return Expression . Call ( itMemberInfo , itArgumentExpressions ) ;
235235 }
236236
237- private Expression BuildRefArgumentExpression ( int index , SetupArgumentDefinition definition , Type refType , Type elementType , ref Dictionary < ParameterExpression , object > forwardedArgs )
237+ private Expression BuildPassByRefArgumentExpression ( int index , SetupArgumentDefinition definition , Type refType , Type elementType , ref Dictionary < ParameterExpression , object > forwardedArgs )
238238 {
239239 ParameterExpression parameterExpression ;
240240 switch ( definition . Type )
@@ -259,14 +259,24 @@ public void Test()
259259 // TODO: need to take care that the args passed into DynamicInvoke do not need to be ref'd - it should be
260260 // TODO: passed in as values then made ref within the expression tree.
261261 var name = $ "p{ index : 00} ";
262- parameterExpression = Expression . Parameter ( elementType , name ) ;
263- forwardedArgs . Add ( parameterExpression , definition . Values [ 0 ] ) ;
262+ /*
263+ var forwardedArgExpression = Expression.Parameter(elementType, name);
264+ // forwardedArgs.Add(forwardedArgExpression, definition.Values[0]);
265+
266+ var conditionExpression = Expression.Lambda();
267+ var itByRefType = typeof(ItByRef<>).MakeGenericType(elementType);
268+ var itMemberInfo = Reflection.GetMethodExt(itByRefType, nameof(ItByRef<object>.Is));
269+ var itByRefExpression = Expression.Call(itMemberInfo, forwardedArgExpression, null);
270+
271+ parameterExpression = Expression.Field();
264272 return parameterExpression;
273+ */
274+ return null ;
265275 case SetupArgumentType . IsAny :
266276 var itRefType = typeof ( It . Ref < > ) . MakeGenericType ( elementType ) ;
267- var itMemberInfo = itRefType . GetField ( nameof ( It . IsAny ) ) ;
277+ var itFieldInfo = itRefType . GetField ( nameof ( It . IsAny ) ) ;
268278 parameterExpression = Expression . Parameter ( itRefType , "r" ) ;
269- return Expression . Field ( parameterExpression , itMemberInfo ) ;
279+ return Expression . Field ( parameterExpression , itFieldInfo ) ;
270280 case SetupArgumentType . IsIn :
271281 throw new NotSupportedException ( $ "The { nameof ( SetupArgumentType . IsIn ) } type is not implemented for ref argument") ;
272282 case SetupArgumentType . IsInRange :
0 commit comments