I have two functions in my class with this signatures,
public static TResult Execute<TResult>(Func<T, TResult> remoteCall); public static void Execute(Action<T> remoteCall)
How can I pass the same delegate in the second method to the first one? Creating method with Delegate argument is not a way, because I am losing some exception information.
The Types you are looking for are Action<> or Func<> . The generic parameters on both types determine the type signature of the method. If your method has no return value use Action . If it has a return value use Func whereby the last generic parameter is the return type.
Func<T, TResult> defines a function that accepts one parameter (of type T) and returns an object (of type TResult).
Func is a generic delegate included in the System namespace. It has zero or more input parameters and one out parameter. The last parameter is considered as an out parameter. The Func delegate that takes one input parameter and one out parameter is defined in the System namespace, as shown below: Signature: Func.
An Action type delegate is the same as Func delegate except that the Action delegate doesn't return a value. In other words, an Action delegate can be used with a method that has a void return type. It can contain minimum 1 and maximum of 16 input parameters and does not contain any output parameter.
Wrap it in a delegate of type Func<T, TResult>
with a dummy return value, e.g.
public static void Execute(Action<T> remoteCall) { Execute(t => { remoteCall(t); return true; }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With