when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String protocol,
- XrayPortList? port,
- XrayAddress? listen,
- XrayInboundSettings? settings,
- String? tag,
- StreamConfig? streamSettings,
- SniffingConfig? sniffing,
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(
String protocol,
XrayPortList? port,
XrayAddress? listen,
XrayInboundSettings? settings,
String? tag,
StreamConfig? streamSettings,
SniffingConfig? sniffing)
$default,
) {
final _that = this;
switch (_that) {
case _InboundDetourConfig():
return $default(_that.protocol, _that.port, _that.listen,
_that.settings, _that.tag, _that.streamSettings, _that.sniffing);
case _:
throw StateError('Unexpected subclass');
}
}