PolymorphicKind<T> class
final
Kind for situations when an instance is one of several possible kinds.
If you know all possible kinds, use PolymorphicKind.sealed constructor.
Otherwise the kind can be:
- defaultKinds
- OR any kind in Kind.all
The defaultKind is the first kind in defaultKinds or the first matching kind in Kind.all.
JSON encoding
The JSON encoding of a polymorphic kind is a JSON object with a field named jsonDiscriminator with the value of Kind.name of the kind. The default value of jsonDiscriminator is "@type" (PolymorphicKind.defaultJsonDiscriminator).
For example, serialization of Person
class would look like:
{
"@type": "Person",
"name": "John Doe",
}
Constructors
-
PolymorphicKind({String? name, String jsonDiscriminator = defaultJsonDiscriminator, List<
Kind< defaultKinds = const []})T> > -
Constructs a polymorphic kind.
const
-
PolymorphicKind.sealed({String? name, String jsonDiscriminator = defaultJsonDiscriminator, required List<
Kind< defaultKinds})T> > -
Constructor for situations when all possible kinds are known.
const
Properties
-
allKinds
→ Iterable<
Kind< T> > -
Returns defaultKinds and matching kinds in Kind.all (unless isSealed
is true).
no setter
- dartType → Type
-
Type
T
.no setterinherited -
defaultKind
→ Kind<
T> -
Returns default kind.
no setter
-
defaultKinds
→ List<
Kind< T> > -
Possible kinds.
final
- defaultValueMirror → InstanceMirror
-
InstanceMirror for the default value.
no setterinherited
- equality → Equality
-
Equality for the kind;
no setterinherited
-
examples
→ Iterable<
T> -
Examples of instances that are valid (isValidDynamic).
no setterinherited
-
examplesThatAreInvalid
→ Iterable<
T> -
Examples of instances that are NOT valid (isValidDynamic).
no setterinherited
-
examplesWithoutValidation
→ Iterable<
T> -
Interesting examples of instances (may be valid or invalid).
no setteroverride
- hashCode → int
-
The hash code for this object.
no setteroverride
- isNullable → bool
-
Whether this kind is nullable.
no setterinherited
- isPrimitive → bool
-
Whether instances of the kind can't have references to other instances.
no setteroverride
- isSealed → bool
-
Whether defaultKinds contains all possible kinds.
final
- jsonDiscriminator → String
-
Discriminator field name
final
- jsonName → String?
-
JSON identifier of the class.
finalinherited
- name → String
-
Dart identifier of the class.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
traits
→ List<
Trait> -
Traits of the kind.
finalinherited
Methods
-
asType(
Object? value) → T -
Casts
value
toT
.inherited -
checkDeclaration(
) → void -
Checks that the declaration makes sense.
inherited
-
checkInstance(
Object? value) → void -
inherited
-
checkValid(
T instance) → void -
override
-
checkValidDynamic(
Object? instance) → void -
Throws ArgumentError error if
instance
is not valid (isValidDynamic).inherited -
clone(
T instance) → T -
Clones the instance.
override
-
compare(
T left, T right) → int -
Compares two values.
override
-
debugString(
T instance) → String -
Constructs a string for debugging
instance
.inherited -
decodeJsonTree(
Object? json) → T -
Converts
json
(any JSON tree) to an instance ofT
.override -
decodeString(
String string) → T -
Decodes
string
to an instance ofT
.inherited -
encodeJsonTree(
T instance) → Object? -
Converts
instance
to a JSON tree.override -
encodeString(
T instance) → String -
Converts
instance
to a string.inherited -
findKindByInstance(
T instance) → Kind< T> -
Finds kind by
instance
. -
findKindByName(
String name) → Kind< T> -
Finds kind by
name
. -
isDefaultValue(
Object? instance) → bool -
Determines whether the argument is a default value of this kind.
override
-
isInstance(
Object? instance) → bool -
Determines whether the argument is an instance of
T
.inherited -
isInstanceOfList(
Object? instance) → bool -
Determines whether the argument is an instance of
List<T>
.inherited -
isInstanceOfSet(
Object? instance) → bool -
Determines whether the argument is an instance of
Set<T>
.inherited -
isNullableSubKind(
Kind other, {bool andNotEqual = true}) → bool -
Tells whether the argument is instance of
Kind<T>
and dartType values are different.inherited -
isSubKind(
Kind other, {bool andNotEqual = true}) → bool -
Tells whether the argument is instance of
Kind<T>
and dartType values are different.inherited -
isValid(
T instance) → bool -
Tells whether the instance is valid.
override
-
isValidDynamic(
Object? instance) → bool -
Tells whether the instance is valid.
inherited
-
kindIndexOfKind(
Kind< T> kind) → int -
memorySize(
T instance) → int -
Estimates memory usage of
instance
.override -
memorySizeWith(
MemoryCounter counter, T instance) → void -
Estimates memory usage with an instance of MemoryCounter.
override
-
newInstance(
) → T -
Constructs a new instance of the default value.
override
-
newList(
int length, {bool growable = true}) → List< T> -
Constructs a new list.
inherited
-
newListFrom(
Iterable< T> iterable, {bool growable = true}) → List<T> -
Constructs a new list from
iterable
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
permute(
T instance) → T -
Generates another instance with some deterministic function.
override
-
register(
) → void -
Registers this kind so that it will be visible in Kind.all.
override
-
toList(
) → Kind< List< T> > -
Constructs Kind for
List<T>
.inherited -
toNonNullable(
) → Kind< T> -
Returns a non-nullable kind.
inherited
-
toNullable(
) → Kind< T?> -
Constructs Kind for
T?
.inherited -
toPolymorphic(
) → PolymorphicKind< T> -
Constructs a PolymorphicKind for this kind.
override
-
toSet(
) → Kind< Set< T> > -
Constructs Kind for
Set<T>
.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Constants
- defaultJsonDiscriminator → const String
- Default JSON discriminator ("@type").