whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. XrayAddress? address,
    2. int? port,
    3. TransportProtocol? network,
    4. SecurityProtocol? security,
    5. FinalMask? finalmask,
    6. TCPConfig? rawSettings,
    7. TCPConfig? tcpSettings,
    8. SplitHTTPConfig? xhttpSettings,
    9. KCPConfig? kcpSettings,
    10. WebSocketConfig? wsSettings,
    11. HttpUpgradeConfig? httpupgradeSettings,
    12. SplitHTTPConfig? splithttpSettings,
    13. GRPCConfig? grpcSettings,
    14. HysteriaConfig? hysteriaSettings,
    15. TLSConfig? tlsSettings,
    16. REALITYConfig? realitySettings,
    17. SocketConfig? sockopt,
    )?
)

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,  int? port,  TransportProtocol? network,  SecurityProtocol? security,  FinalMask? finalmask,  TCPConfig? rawSettings,  TCPConfig? tcpSettings,  SplitHTTPConfig? xhttpSettings,  KCPConfig? kcpSettings,  WebSocketConfig? wsSettings,  HttpUpgradeConfig? httpupgradeSettings,  SplitHTTPConfig? splithttpSettings,  GRPCConfig? grpcSettings,  HysteriaConfig? hysteriaSettings,  TLSConfig? tlsSettings,  REALITYConfig? realitySettings,  SocketConfig? sockopt)?  $default,) {final _that = this;
switch (_that) {
case _StreamConfig() when $default != null:
return $default(_that.address,_that.port,_that.network,_that.security,_that.finalmask,_that.rawSettings,_that.tcpSettings,_that.xhttpSettings,_that.kcpSettings,_that.wsSettings,_that.httpupgradeSettings,_that.splithttpSettings,_that.grpcSettings,_that.hysteriaSettings,_that.tlsSettings,_that.realitySettings,_that.sockopt);case _:
  return null;

}
}