Class MultiDelegateInvoker<TBaseArg, TResult>
- Namespace
- Utils.Reflection
- Assembly
- Utils.dll
Invokes multiple delegates registered for a given argument type.
public class MultiDelegateInvoker<TBaseArg, TResult> : IEnumerable<Delegate>, IEnumerable
Type Parameters
TBaseArgThe base type for the argument of the delegates.
TResultThe return type of the delegates.
- Inheritance
-
MultiDelegateInvoker<TBaseArg, TResult>
- Implements
- Inherited Members
- Extension Methods
Constructors
MultiDelegateInvoker(int)
Initializes a new instance of the MultiDelegateInvoker<TBaseArg, TResult> class.
public MultiDelegateInvoker(int parallelThreshold = 4)
Parameters
parallelThresholdintMinimum number of delegates required to run in parallel when using InvokeSmartAsync(TBaseArg, CancellationToken).
Exceptions
- ArgumentOutOfRangeException
Thrown when
parallelThresholdis less than one.
Methods
Add<T>(Func<T, TResult>)
Registers a delegate function for a specific argument type derived from TBaseArg.
public void Add<T>(Func<T, TResult> function) where T : TBaseArg
Parameters
functionFunc<T, TResult>The delegate to register.
Type Parameters
TThe argument type for the delegate.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<Delegate> GetEnumerator()
Returns
- IEnumerator<Delegate>
An enumerator that can be used to iterate through the collection.
Invoke(TBaseArg)
Invokes the registered delegates sequentially for the runtime type of arg.
public TResult[] Invoke(TBaseArg arg)
Parameters
argTBaseArgThe argument to pass to each delegate.
Returns
- TResult[]
An array containing the results of each delegate call.
Exceptions
- MissingMethodException
Thrown when no delegate is registered for the argument type.
InvokeAsync(TBaseArg, CancellationToken)
Invokes the registered delegates sequentially on background threads.
public Task<TResult[]> InvokeAsync(TBaseArg arg, CancellationToken cancellationToken = default)
Parameters
argTBaseArgThe argument to pass to each delegate.
cancellationTokenCancellationTokenA token used to cancel the operation.
Returns
- Task<TResult[]>
A task producing an array with the results of each delegate call.
Exceptions
- MissingMethodException
Thrown when no delegate is registered for the argument type.
InvokeParallelAsync(TBaseArg, CancellationToken)
Invokes the registered delegates in parallel.
public Task<TResult[]> InvokeParallelAsync(TBaseArg arg, CancellationToken cancellationToken = default)
Parameters
argTBaseArgThe argument to pass to each delegate.
cancellationTokenCancellationTokenA token used to cancel the operation.
Returns
- Task<TResult[]>
A task producing an array with the results of each delegate call.
Exceptions
- MissingMethodException
Thrown when no delegate is registered for the argument type.
InvokeSmartAsync(TBaseArg, CancellationToken)
Invokes the registered delegates either sequentially or in parallel depending on the configured threshold.
public Task<TResult[]> InvokeSmartAsync(TBaseArg arg, CancellationToken cancellationToken = default)
Parameters
argTBaseArgThe argument to pass to each delegate.
cancellationTokenCancellationTokenA token used to cancel the operation.
Returns
- Task<TResult[]>
A task producing an array with the results of each delegate call.