whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. int? mark,
    2. Object? tcpFastOpen,
    3. TProxyMode? tproxy,
    4. bool? acceptProxyProtocol,
    5. XrayTargetStrategy? domainStrategy,
    6. String? dialerProxy,
    7. int? tcpKeepAliveInterval,
    8. int? tcpKeepAliveIdle,
    9. String? tcpCongestion,
    10. int? tcpWindowClamp,
    11. int? tcpMaxSeg,
    12. bool? penetrate,
    13. int? tcpUserTimeout,
    14. bool? v6only,
    15. @JsonKey.new(name: 'interface') String? interfaceName,
    16. bool? tcpMptcp,
    17. List<CustomSockoptConfig>? customSockopt,
    18. AddressPortStrategy? addressPortStrategy,
    19. HappyEyeballsConfig? happyEyeballs,
    20. List<String>? trustedXForwardedFor,
    )?
)

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(
          int? mark,
          Object? tcpFastOpen,
          TProxyMode? tproxy,
          bool? acceptProxyProtocol,
          XrayTargetStrategy? domainStrategy,
          String? dialerProxy,
          int? tcpKeepAliveInterval,
          int? tcpKeepAliveIdle,
          String? tcpCongestion,
          int? tcpWindowClamp,
          int? tcpMaxSeg,
          bool? penetrate,
          int? tcpUserTimeout,
          bool? v6only,
          @JsonKey(name: 'interface') String? interfaceName,
          bool? tcpMptcp,
          List<CustomSockoptConfig>? customSockopt,
          AddressPortStrategy? addressPortStrategy,
          HappyEyeballsConfig? happyEyeballs,
          List<String>? trustedXForwardedFor)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _SocketConfig() when $default != null:
      return $default(
          _that.mark,
          _that.tcpFastOpen,
          _that.tproxy,
          _that.acceptProxyProtocol,
          _that.domainStrategy,
          _that.dialerProxy,
          _that.tcpKeepAliveInterval,
          _that.tcpKeepAliveIdle,
          _that.tcpCongestion,
          _that.tcpWindowClamp,
          _that.tcpMaxSeg,
          _that.penetrate,
          _that.tcpUserTimeout,
          _that.v6only,
          _that.interfaceName,
          _that.tcpMptcp,
          _that.customSockopt,
          _that.addressPortStrategy,
          _that.happyEyeballs,
          _that.trustedXForwardedFor);
    case _:
      return null;
  }
}