when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. XrayTargetStrategy? targetStrategy,
    2. XrayTargetStrategy? domainStrategy,
    3. String? redirect,
    4. int? userLevel,
    5. Fragment? fragment,
    6. Noise? noise,
    7. List<Noise>? noises,
    8. int? proxyProtocol,
    9. XrayStringList? ipsBlocked,
    10. List<FreedomFinalRuleConfig>? finalRules,
    )
)

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(
          XrayTargetStrategy? targetStrategy,
          XrayTargetStrategy? domainStrategy,
          String? redirect,
          int? userLevel,
          Fragment? fragment,
          Noise? noise,
          List<Noise>? noises,
          int? proxyProtocol,
          XrayStringList? ipsBlocked,
          List<FreedomFinalRuleConfig>? finalRules)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _FreedomConfig():
      return $default(
          _that.targetStrategy,
          _that.domainStrategy,
          _that.redirect,
          _that.userLevel,
          _that.fragment,
          _that.noise,
          _that.noises,
          _that.proxyProtocol,
          _that.ipsBlocked,
          _that.finalRules);
    case _:
      throw StateError('Unexpected subclass');
  }
}