when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- Map<
String, dynamic> ? transport, - LogConfig? log,
- RouterConfig? routing,
- DNSConfig? dns,
- List<
InboundDetourConfig> ? inbounds, - List<
OutboundDetourConfig> ? outbounds, - PolicyConfig? policy,
- APIConfig? api,
- MetricsConfig? metrics,
- StatsConfig? stats,
- ReverseConfig? reverse,
- @JsonKey.new(name: 'fakeDns') FakeDNSConfig? fakeDns,
- ObservatoryConfig? observatory,
- BurstObservatoryConfig? burstObservatory,
- VersionConfig? version,
- GeodataConfig? geodata,
- Map<
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( Map<String, dynamic>? transport, LogConfig? log, RouterConfig? routing, DNSConfig? dns, List<InboundDetourConfig>? inbounds, List<OutboundDetourConfig>? outbounds, PolicyConfig? policy, APIConfig? api, MetricsConfig? metrics, StatsConfig? stats, ReverseConfig? reverse, @JsonKey(name: 'fakeDns') FakeDNSConfig? fakeDns, ObservatoryConfig? observatory, BurstObservatoryConfig? burstObservatory, VersionConfig? version, GeodataConfig? geodata) $default,) {final _that = this;
switch (_that) {
case _XrayConfig():
return $default(_that.transport,_that.log,_that.routing,_that.dns,_that.inbounds,_that.outbounds,_that.policy,_that.api,_that.metrics,_that.stats,_that.reverse,_that.fakeDns,_that.observatory,_that.burstObservatory,_that.version,_that.geodata);case _:
throw StateError('Unexpected subclass');
}
}