Would it be possible to assign a method with out
parameters to a Func<T1, T2>
method parameter?
An example method I could use as parameter:
public string HelloMethod(out bool success)
{
success = true;
return "Hello";
};
The reason I want to do this is that I call a library where many (but not all) methods have out
parameters with error codes and I want create a method to wrap the calls to the library with try catch log
etc:
private TResult MakeLibraryCall(...func...) // what signature?
{
try
{
return func(...); // unclear how to make call with out parameter
}
catch(Exception error)
{
Log(error);
}
return default;
}
Further I'm not sure how this would be called. I hope for something like:
var greeting = MakeLibraryCall((out success) => HelloMetod(out success));
Console.WriteLine(greeting) // => Hello
Console.WriteLine(success) // => true
Any help appreciated!