Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/ModularPipelines/Engine/ModuleExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,25 @@ private async Task<IModuleResult> ExecuteTypedModule(
var resultType = module.ResultType;

// Use reflection to call the generic ExecuteAsync method
var executeMethod = typeof(IModuleExecutionPipeline).GetMethod(nameof(IModuleExecutionPipeline.ExecuteAsync))!
.MakeGenericMethod(resultType);
var executeMethodInfo = typeof(IModuleExecutionPipeline).GetMethod(nameof(IModuleExecutionPipeline.ExecuteAsync))
?? throw new InvalidOperationException($"Method '{nameof(IModuleExecutionPipeline.ExecuteAsync)}' not found on type '{nameof(IModuleExecutionPipeline)}'.");

var task = (Task) executeMethod.Invoke(_executionPipeline, new object[] { module, executionContext, moduleContext, cancellationToken })!;
var executeMethod = executeMethodInfo.MakeGenericMethod(resultType);

var invokeResult = executeMethod.Invoke(_executionPipeline, new object[] { module, executionContext, moduleContext, cancellationToken })
?? throw new InvalidOperationException($"Invocation of '{nameof(IModuleExecutionPipeline.ExecuteAsync)}' returned null.");

var task = (Task)invokeResult;
await task;

// Get the result from the completed task
var resultProperty = task.GetType().GetProperty("Result")!;
return (IModuleResult) resultProperty.GetValue(task)!;
var resultProperty = task.GetType().GetProperty("Result")
?? throw new InvalidOperationException($"Property 'Result' not found on task type '{task.GetType().Name}'.");

var resultValue = resultProperty.GetValue(task)
?? throw new InvalidOperationException($"Property 'Result' returned null for task type '{task.GetType().Name}'.");

return (IModuleResult)resultValue;
}

private async Task<IDisposable> WaitForParallelLimiter(Type moduleType)
Expand Down
10 changes: 9 additions & 1 deletion src/ModularPipelines/Engine/OptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ public OptionsProvider(IPipelineServiceContainerWrapper pipelineServiceContainer

foreach (var option in types.Select(t => _serviceProvider.GetService(typeof(IOptions<>).MakeGenericType(t))))
{
yield return option!.GetType().GetProperty("Value", BindingFlags.Public | BindingFlags.Instance)!.GetValue(option);
if (option is null)
{
continue;
}

var valueProperty = option.GetType().GetProperty("Value", BindingFlags.Public | BindingFlags.Instance)
?? throw new InvalidOperationException($"Property 'Value' not found on type '{option.GetType().Name}'.");

yield return valueProperty.GetValue(option);
}
}
}
Loading