operator [] method

Parameter operator [](
  1. dynamic key
)

Returns a single parameter.

If key is a String, the request is expected to provide named parameters. If it's an int, the request is expected to provide positional parameters. Requests that don't do so will be rejected automatically.

Whether or not the given parameter exists, this returns a Parameter object. If a parameter's value is accessed through a getter like value or Parameter.asNum, the request will be rejected if that parameter doesn't exist. On the other hand, if it's accessed through a method with a default value like Parameter.valueOr or Parameter.asNumOr, the default value will be returned.

Implementation

Parameter operator [](key) {
  if (key is int) {
    _assertPositional();
    if (key < value.length) {
      return Parameter._(method, value[key], this, key);
    } else {
      return _MissingParameter(method, this, key);
    }
  } else if (key is String) {
    _assertNamed();
    if (value.containsKey(key)) {
      return Parameter._(method, value[key], this, key);
    } else {
      return _MissingParameter(method, this, key);
    }
  } else {
    throw ArgumentError('Parameters[] only takes an int or a string, was '
        '"$key".');
  }
}