when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. XrayInt32Range? delay,
    2. int? rand,
    3. XrayInt32Range? randRange,
    4. String? capture,
    5. String? type,
    6. String? reuse,
    7. CustomTransform? transform,
    8. Object? packet,
    )
)

A switch-like method, using callbacks.

As opposed to map, this offers destructuring. It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case Subclass2(:final field2):
    return ...;
}

Implementation

@optionalTypeArgs
TResult when<TResult extends Object?>(
  TResult Function(
          XrayInt32Range? delay,
          int? rand,
          XrayInt32Range? randRange,
          String? capture,
          String? type,
          String? reuse,
          CustomTransform? transform,
          Object? packet)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _TCPItem():
      return $default(_that.delay, _that.rand, _that.randRange, _that.capture,
          _that.type, _that.reuse, _that.transform, _that.packet);
    case _:
      throw StateError('Unexpected subclass');
  }
}