Class ExtendedInvoker<TResult>
- Namespace
- Utils.Reflection
- Assembly
- Utils.dll
An invoker that can store multiple delegates sharing the same return type but with different parameter lists. On invocation, the best matching delegate is selected using the compiler's distance-based method search.
public class ExtendedInvoker<TResult> : IEnumerable<Delegate>, IEnumerable
Type Parameters
TResultThe common return type of all registered delegates.
- Inheritance
-
ExtendedInvoker<TResult>
- Implements
- Inherited Members
- Extension Methods
Methods
Add(Delegate)
Adds a delegate to the invoker. The delegate must return
TResult.
public void Add(Delegate function)
Parameters
functionDelegateThe delegate to add.
Exceptions
- ArgumentNullException
Thrown if
functionis null.- ArgumentException
Thrown if the delegate return type does not match
TResult.
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(params object?[])
Invokes the best matching delegate for the provided arguments or throws if none is found.
public TResult Invoke(params object?[] arguments)
Parameters
argumentsobject[]Arguments for the delegate call.
Returns
- TResult
The result of the invoked delegate.
Exceptions
- MissingMethodException
Thrown when no suitable delegate is registered.
- AmbiguousMatchException
Thrown when two or more delegates match the arguments with equal specificity.
TryInvoke(object?[], out TResult)
Attempts to invoke the best matching delegate with the provided arguments.
public bool TryInvoke(object?[] arguments, out TResult result)
Parameters
argumentsobject[]An array of arguments for the delegate call.
resultTResultReceives the invocation result if successful.
Returns
Remarks
Null arguments are treated as typeof(object) for overload resolution. Delegates
that accept a more specific reference type (e.g. Func<string, TResult>) are not
reachable when the corresponding argument is null; register a
Func<object, TResult> overload to handle the null case.
Ambiguity: when two or more registered delegates match with the same specificity distance, AmbiguousMatchException is thrown rather than silently selecting the first registration.
Exceptions: if the selected delegate throws, the original exception is rethrown directly (not wrapped in TargetInvocationException).
Exceptions
- AmbiguousMatchException
Thrown when two or more delegates match the arguments with equal specificity.