valueFor<A> method
Get the value for given aspect
. This checks for any overrides, and
provides the overridden value if there is one, or _value
by transform
Optionally provide transform
. By default _value
is simply casted
Implementation
A valueFor<A>(InheritableAspect<T> aspect, [A Function(T)? transform]) {
assert(isSupportedAspect(aspect));
final maybeOverride = _overrides.lookup(aspect);
if (maybeOverride is AspectOverride) {
if (maybeOverride.override is A || maybeOverride.override == null)
return maybeOverride.override as A;
else
throw StateError(
'Invalid override provided for $aspect of $this, '
'expected value of type $A but got ${maybeOverride.override.runtimeType}',
);
}
if (aspect is TransformingAspect<A, T>) {
transform ??= aspect.transform;
}
return (transform ?? _defaultTransform)(_value);
}