when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String? ruleTag,
- String? outboundTag,
- String? balancerTag,
- XrayStringList? domain,
- XrayStringList? domains,
- XrayStringList? ip,
- XrayPortList? port,
- XrayNetworkList? network,
- XrayStringList? sourceIP,
- XrayStringList? source,
- XrayPortList? sourcePort,
- XrayStringList? user,
- XrayPortList? vlessRoute,
- XrayStringList? inboundTag,
- @JsonKey.new(name: 'protocol') XrayStringList? protocols,
- @JsonKey.new(name: 'attrs') Map<
String, String> ? attributes, - XrayStringList? localIP,
- XrayPortList? localPort,
- XrayStringList? process,
- WebhookRuleConfig? webhook,
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? ruleTag,
String? outboundTag,
String? balancerTag,
XrayStringList? domain,
XrayStringList? domains,
XrayStringList? ip,
XrayPortList? port,
XrayNetworkList? network,
XrayStringList? sourceIP,
XrayStringList? source,
XrayPortList? sourcePort,
XrayStringList? user,
XrayPortList? vlessRoute,
XrayStringList? inboundTag,
@JsonKey(name: 'protocol') XrayStringList? protocols,
@JsonKey(name: 'attrs') Map<String, String>? attributes,
XrayStringList? localIP,
XrayPortList? localPort,
XrayStringList? process,
WebhookRuleConfig? webhook)
$default,
) {
final _that = this;
switch (_that) {
case _RouterRule():
return $default(
_that.ruleTag,
_that.outboundTag,
_that.balancerTag,
_that.domain,
_that.domains,
_that.ip,
_that.port,
_that.network,
_that.sourceIP,
_that.source,
_that.sourcePort,
_that.user,
_that.vlessRoute,
_that.inboundTag,
_that.protocols,
_that.attributes,
_that.localIP,
_that.localPort,
_that.process,
_that.webhook);
case _:
throw StateError('Unexpected subclass');
}
}