In C#:
Is it possible define a method that input parameter is any method?
Let me better description:
I want a method with signature
bool IsDoit(var method)
{
try
{
method(...);
return true;
}
catch{return false;}
}
This get a method and return a boolean that is throw exception or not!
Generic Delegate? Generic Action? Generic Func?
Do You have any idea or it is not possible?
What would go in the “…” here? It sounds like you want a delegate of some description – and that delegate signature should match the one of the method you want to call. For example:
That will allow method group conversions for any parameterless void method:
If the caller wants to call a method which takes other parameters, they can use a lambda expression to wrap it in an
Action:Personally I’m not at all sure about the wisdom of this design in the first place, mind you – catching exceptions and swallowing them without any sort of logging seems like a really bad idea to me.