whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. XrayAddress address,
    2. XrayAddress? clientIp,
    3. int? port,
    4. bool? skipFallback,
    5. XrayStringList? domains,
    6. XrayStringList? expectedIPs,
    7. XrayStringList? expectIPs,
    8. DnsQueryStrategy? queryStrategy,
    9. String? tag,
    10. int? timeoutMs,
    11. bool? disableCache,
    12. bool? serveStale,
    13. int? serveExpiredTTL,
    14. bool? finalQuery,
    15. XrayStringList? unexpectedIPs,
    16. bool? simplified,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( XrayAddress address,  XrayAddress? clientIp,  int? port,  bool? skipFallback,  XrayStringList? domains,  XrayStringList? expectedIPs,  XrayStringList? expectIPs,  DnsQueryStrategy? queryStrategy,  String? tag,  int? timeoutMs,  bool? disableCache,  bool? serveStale,  int? serveExpiredTTL,  bool? finalQuery,  XrayStringList? unexpectedIPs,  bool? simplified)?  $default,) {final _that = this;
switch (_that) {
case _NameServerConfig() when $default != null:
return $default(_that.address,_that.clientIp,_that.port,_that.skipFallback,_that.domains,_that.expectedIPs,_that.expectIPs,_that.queryStrategy,_that.tag,_that.timeoutMs,_that.disableCache,_that.serveStale,_that.serveExpiredTTL,_that.finalQuery,_that.unexpectedIPs,_that.simplified);case _:
  return null;

}
}