I would like to write a class representing a Method and an variably-sized array of parameters to pass into the method on invocation.
Is there a more elegant solution to calling invoke of the Method than one call for each of the number of parameters I want to support?
class EvccTask {
private var _method as Method;
private var _args as Array<Object>;
public function initialize( method as Method, args as Array<Object>? ) {
_method = method;
_args = args == null ? new Array<Object>[0] : args;
}
public function invoke() as Void {
if( _args == null || _args.size() == 0 ) {
_method.invoke();
} else if (_args.size() == 1 ) {
_method.invoke( _args[0] );
} else if (_args.size() == 2 ) {
_method.invoke( _args[0], _args[1] );
} else if (_args.size() == 3 ) {
_method.invoke( _args[0], _args[1], _args[2] );
} else {
throw new OperationNotAllowedException( "EvccTask: too many arguments!" );
}
}
}