when<TResult extends Object?> method
- @optionalTypeArgs
- required TResult cookie(),
- required TResult header(),
- required TResult query(),
- required TResult path(),
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?>({required TResult Function( String? name, String? description, bool? required, bool? deprecated, String? style, bool? explode, bool? allowReserved, String? example, Schema schema, @JsonKey(name: '\$ref')@_ParamRefConverter() String? ref) cookie,required TResult Function( String? name, String? description, bool? required, bool? deprecated, String? style, bool? explode, bool? allowReserved, String? example, Schema schema, @JsonKey(name: '\$ref')@_ParamRefConverter() String? ref) header,required TResult Function( String? name, String? description, bool? required, bool? deprecated, String? style, bool? explode, bool? allowReserved, String? example, Schema schema, @JsonKey(name: '\$ref')@_ParamRefConverter() String? ref) query,required TResult Function( String? name, String? description, bool? deprecated, String? style, bool? explode, bool? allowReserved, String? example, Schema? schema, @JsonKey(name: '\$ref')@_ParamRefConverter() String? ref) path,}) {final _that = this;
switch (_that) {
case ParameterCookie():
return cookie(_that.name,_that.description,_that.required,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case ParameterHeader():
return header(_that.name,_that.description,_that.required,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case ParameterQuery():
return query(_that.name,_that.description,_that.required,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case ParameterPath():
return path(_that.name,_that.description,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case _:
throw StateError('Unexpected subclass');
}
}