when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- List<
NameServerConfig> ? servers, - HostsWrapper? hosts,
- XrayAddress? clientIp,
- String? tag,
- DnsQueryStrategy? queryStrategy,
- bool? disableCache,
- bool? serveStale,
- int? serveExpiredTTL,
- bool? disableFallback,
- bool? disableFallbackIfMatch,
- bool? enableParallelQuery,
- bool? useSystemHosts,
- List<
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(
List<NameServerConfig>? servers,
HostsWrapper? hosts,
XrayAddress? clientIp,
String? tag,
DnsQueryStrategy? queryStrategy,
bool? disableCache,
bool? serveStale,
int? serveExpiredTTL,
bool? disableFallback,
bool? disableFallbackIfMatch,
bool? enableParallelQuery,
bool? useSystemHosts)
$default,
) {
final _that = this;
switch (_that) {
case _DNSConfig():
return $default(
_that.servers,
_that.hosts,
_that.clientIp,
_that.tag,
_that.queryStrategy,
_that.disableCache,
_that.serveStale,
_that.serveExpiredTTL,
_that.disableFallback,
_that.disableFallbackIfMatch,
_that.enableParallelQuery,
_that.useSystemHosts);
case _:
throw StateError('Unexpected subclass');
}
}