I am trying to use void methods with MapResult method in Main() method in console application. Following is my code, Class1, Class2 and Class3 inherits AbstractClass and implements it's Execute() method:
Parser.Default.ParseArguments<
Class1,
Class2,
Class3>(command.Split(' '))
.MapResult((AbstractClass o) => o.Execute(), err => null);
In the above code, my Execute() method returns void. I receive following error:
The type arguments for method 'ParserResultExtensions.MapResult(ParserResult, Func, Func, TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
However, if I change return type of Execute() method to int, it works fine.
Please suggest me some solution to use void returning method with MapResult.
Assuming you are using CommandLineParser (https://github.com/commandlineparser/commandline), MapResult requires you to provide a return value indicating success/failure. Try this:
.MapResult((AbstractClass o) => {o.Execute(); return 1;}, err => null);
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