How to Check If Invoking Was Successful or Not?

I am giving players the ability to write commands in game like a console, i am relying on reflection system and invoking methods.
The only problem now is i want the console to print a message if the user enters something that isn’t a method name/Command.

here is the part of code where i invoke a method.

MethodInfo methodInfo = developerCommand.GetType().GetMethod(methodName, types);
methodInfo?.Invoke(developerCommand, parametersArray);

Using methodInfo?. solves the problem when it comes to only invoking if the arguments provided are valid, I want to display the message if they are invalid.

How can i achieve this?

Can’t you just check if methodInfo is null or not? That’s already what the ?. operator does, it just ignores the call if methodInfo is null.

1 Like

Right, so many people use the new fancy syntax goodies and forget what they’re actually doing -.-

That’s why I’m not a fan of many new technologies. People literally degrade / get dumber over time. For example all the neat features new cars have which help you with many common situations. They keep you on track, they keep the distance to car in front of you and hold a certain speed. As a result people unlearn how to properly and safely operate a car… It’s kinda scary.

1 Like