@@ -217,90 +217,117 @@ private void AttachOutputs(StepSourceV1 source, Type dataType, Type stepType, Wo
217217 var sourceExpr = DynamicExpressionParser . ParseLambda ( new [ ] { stepParameter } , typeof ( object ) , output . Value ) ;
218218
219219 var dataParameter = Expression . Parameter ( dataType , "data" ) ;
220- Expression targetProperty = dataParameter ;
221220
222- // Check if our datatype has a matching property
223221
224- PropertyInfo propertyInfo = null ;
225- String [ ] paths = output . Key . Split ( '.' ) ;
226-
227- bool hasAddOutput = false ;
228-
229- foreach ( String propertyName in paths )
222+ if ( output . Key . Contains ( "." ) || output . Key . Contains ( "[" ) )
230223 {
231- if ( hasAddOutput )
232- {
233- throw new ArgumentException ( $ "Unknown property for output { output . Key } on { source . Id } ") ;
234- }
224+ AttachNestedOutput ( output , step , source , sourceExpr , dataParameter ) ;
225+ } else
226+ {
227+ AttachDirectlyOutput ( output , step , dataType , sourceExpr , dataParameter ) ;
228+ }
229+ }
230+ }
235231
236- if ( targetProperty == null )
237- {
238- break ;
239- }
232+ private void AttachDirectlyOutput ( KeyValuePair < string , string > output , WorkflowStep step , Type dataType , LambdaExpression sourceExpr , ParameterExpression dataParameter )
233+ {
234+ Expression targetProperty ;
240235
241- if ( propertyName . Contains ( "[" ) )
242- {
243- String [ ] items = propertyName . Split ( '[' ) ;
236+ // Check if our datatype has a matching property
237+ var propertyInfo = dataType . GetProperty ( output . Key ) ;
238+ if ( propertyInfo != null )
239+ {
240+ targetProperty = Expression . Property ( dataParameter , propertyInfo ) ;
241+ var targetExpr = Expression . Lambda ( targetProperty , dataParameter ) ;
242+ step . Outputs . Add ( new MemberMapParameter ( sourceExpr , targetExpr ) ) ;
243+ }
244+ else
245+ {
246+ // If we did not find a matching property try to find a Indexer with string parameter
247+ propertyInfo = dataType . GetProperty ( "Item" ) ;
248+ targetProperty = Expression . Property ( dataParameter , propertyInfo , Expression . Constant ( output . Key ) ) ;
244249
245- if ( items . Length != 2 )
246- {
247- throw new ArgumentException ( $ "Unknown property for output { output . Key } on { source . Id } ") ;
248- }
250+ Action < IStepBody , object > acn = ( pStep , pData ) =>
251+ {
252+ object resolvedValue = sourceExpr . Compile ( ) . DynamicInvoke ( pStep ) ; ;
253+ propertyInfo . SetValue ( pData , resolvedValue , new object [ ] { output . Key } ) ;
254+ } ;
249255
250- items [ 1 ] = items [ 1 ] . Trim ( ) . TrimEnd ( ']' ) . Trim ( ) . Trim ( '"' ) ;
256+ step . Outputs . Add ( new ActionParameter < IStepBody , object > ( acn ) ) ;
257+ }
251258
252- MemberExpression memberExpression = Expression . Property ( targetProperty , items [ 0 ] ) ;
259+ }
253260
254- if ( memberExpression == null )
255- {
256- throw new ArgumentException ( $ "Unknown property for output { output . Key } on { source . Id } ") ;
257- }
258- propertyInfo = ( ( PropertyInfo ) memberExpression . Member ) . PropertyType . GetProperty ( "Item" ) ;
261+ private void AttachNestedOutput ( KeyValuePair < string , string > output , WorkflowStep step , StepSourceV1 source , LambdaExpression sourceExpr , ParameterExpression dataParameter )
262+ {
263+ PropertyInfo propertyInfo = null ;
264+ String [ ] paths = output . Key . Split ( '.' ) ;
265+
266+ Expression targetProperty = dataParameter ;
259267
260- Action < IStepBody , object > acn = ( pStep , pData ) =>
261- {
262- var targetExpr = Expression . Lambda ( memberExpression , dataParameter ) ;
263- object data = targetExpr . Compile ( ) . DynamicInvoke ( pData ) ;
264- object resolvedValue = sourceExpr . Compile ( ) . DynamicInvoke ( pStep ) ; ;
265- propertyInfo . SetValue ( data , resolvedValue , new object [ ] { items [ 1 ] } ) ;
266- } ;
267-
268- step . Outputs . Add ( new ActionParameter < IStepBody , object > ( acn ) ) ;
269- hasAddOutput = true ;
270- }
271- else
272- {
273- try
274- {
275- targetProperty = Expression . Property ( targetProperty , propertyName ) ;
276- } catch
277- {
278- targetProperty = null ;
279- break ;
280- }
281- }
268+ bool hasAddOutput = false ;
269+
270+ foreach ( String propertyName in paths )
271+ {
272+ if ( hasAddOutput )
273+ {
274+ throw new ArgumentException ( $ "Unknown property for output { output . Key } on { source . Id } ") ;
282275 }
283276
284- if ( targetProperty != null && ! hasAddOutput )
277+ if ( targetProperty == null )
285278 {
286- var targetExpr = Expression . Lambda ( targetProperty , dataParameter ) ;
287- step . Outputs . Add ( new MemberMapParameter ( sourceExpr , targetExpr ) ) ;
279+ break ;
288280 }
289- else if ( ! hasAddOutput )
281+
282+ if ( propertyName . Contains ( "[" ) )
290283 {
291- // If we did not find a matching property try to find a Indexer with string parameter
292- propertyInfo = dataType . GetProperty ( "Item" ) ;
293- targetProperty = Expression . Property ( dataParameter , propertyInfo , Expression . Constant ( output . Key ) ) ;
284+ String [ ] items = propertyName . Split ( '[' ) ;
285+
286+ if ( items . Length != 2 )
287+ {
288+ throw new ArgumentException ( $ "Unknown property for output { output . Key } on { source . Id } ") ;
289+ }
290+
291+ items [ 1 ] = items [ 1 ] . Trim ( ) . TrimEnd ( ']' ) . Trim ( ) . Trim ( '"' ) ;
292+
293+ MemberExpression memberExpression = Expression . Property ( targetProperty , items [ 0 ] ) ;
294+
295+ if ( memberExpression == null )
296+ {
297+ throw new ArgumentException ( $ "Unknown property for output { output . Key } on { source . Id } ") ;
298+ }
299+ propertyInfo = ( ( PropertyInfo ) memberExpression . Member ) . PropertyType . GetProperty ( "Item" ) ;
294300
295301 Action < IStepBody , object > acn = ( pStep , pData ) =>
296302 {
303+ var targetExpr = Expression . Lambda ( memberExpression , dataParameter ) ;
304+ object data = targetExpr . Compile ( ) . DynamicInvoke ( pData ) ;
297305 object resolvedValue = sourceExpr . Compile ( ) . DynamicInvoke ( pStep ) ; ;
298- propertyInfo . SetValue ( pData , resolvedValue , new object [ ] { output . Key } ) ;
306+ propertyInfo . SetValue ( data , resolvedValue , new object [ ] { items [ 1 ] } ) ;
299307 } ;
300308
301309 step . Outputs . Add ( new ActionParameter < IStepBody , object > ( acn ) ) ;
310+ hasAddOutput = true ;
311+ }
312+ else
313+ {
314+ try
315+ {
316+ targetProperty = Expression . Property ( targetProperty , propertyName ) ;
317+ }
318+ catch
319+ {
320+ targetProperty = null ;
321+ break ;
322+ }
302323 }
303324 }
325+
326+ if ( targetProperty != null && ! hasAddOutput )
327+ {
328+ var targetExpr = Expression . Lambda ( targetProperty , dataParameter ) ;
329+ step . Outputs . Add ( new MemberMapParameter ( sourceExpr , targetExpr ) ) ;
330+ }
304331 }
305332
306333 private void AttachOutcomes ( StepSourceV1 source , Type dataType , WorkflowStep step )
0 commit comments