when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String? masterKeyLog,
    2. bool? show,
    3. Object? target,
    4. Object? dest,
    5. String? type,
    6. int? xver,
    7. List<String>? serverNames,
    8. String? privateKey,
    9. String? minClientVer,
    10. String? maxClientVer,
    11. int? maxTimeDiff,
    12. List<String>? shortIds,
    13. String? mldsa65Seed,
    14. LimitFallback? limitFallbackUpload,
    15. LimitFallback? limitFallbackDownload,
    16. String? fingerprint,
    17. String? serverName,
    18. String? password,
    19. String? publicKey,
    20. String? shortId,
    21. String? mldsa65Verify,
    22. String? spiderX,
    )
)

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(
          String? masterKeyLog,
          bool? show,
          Object? target,
          Object? dest,
          String? type,
          int? xver,
          List<String>? serverNames,
          String? privateKey,
          String? minClientVer,
          String? maxClientVer,
          int? maxTimeDiff,
          List<String>? shortIds,
          String? mldsa65Seed,
          LimitFallback? limitFallbackUpload,
          LimitFallback? limitFallbackDownload,
          String? fingerprint,
          String? serverName,
          String? password,
          String? publicKey,
          String? shortId,
          String? mldsa65Verify,
          String? spiderX)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _REALITYConfig():
      return $default(
          _that.masterKeyLog,
          _that.show,
          _that.target,
          _that.dest,
          _that.type,
          _that.xver,
          _that.serverNames,
          _that.privateKey,
          _that.minClientVer,
          _that.maxClientVer,
          _that.maxTimeDiff,
          _that.shortIds,
          _that.mldsa65Seed,
          _that.limitFallbackUpload,
          _that.limitFallbackDownload,
          _that.fingerprint,
          _that.serverName,
          _that.password,
          _that.publicKey,
          _that.shortId,
          _that.mldsa65Verify,
          _that.spiderX);
    case _:
      throw StateError('Unexpected subclass');
  }
}