when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String name,
- bool isDeprecated,
- bool isExperimental,
- bool isSealed,
- bool isAbstract,
- Set<
TypeUsage> typeUsages, - List<
String> typeParameterNames, - Set<
String> superTypeNames, - List<
ExecutableDeclaration> executableDeclarations, - List<
FieldDeclaration> fieldDeclarations, - Set<
String> ? entryPoints, - String relativePath,
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 name,
bool isDeprecated,
bool isExperimental,
bool isSealed,
bool isAbstract,
Set<TypeUsage> typeUsages,
List<String> typeParameterNames,
Set<String> superTypeNames,
List<ExecutableDeclaration> executableDeclarations,
List<FieldDeclaration> fieldDeclarations,
Set<String>? entryPoints,
String relativePath)
$default,
) {
final _that = this;
switch (_that) {
case _InterfaceDeclaration():
return $default(
_that.name,
_that.isDeprecated,
_that.isExperimental,
_that.isSealed,
_that.isAbstract,
_that.typeUsages,
_that.typeParameterNames,
_that.superTypeNames,
_that.executableDeclarations,
_that.fieldDeclarations,
_that.entryPoints,
_that.relativePath);
}
}