public function castValues(string $cls): self
    {
        $refl = new \ReflectionClass($cls);
        if (!$refl->isSubclassOf(AttributeValue::class)) {
            throw new \LogicException(
                "$cls must be derived from " . AttributeValue::class . ".");
        }
        $oid = $this->oid();
        $values = array_map(
            function (AttributeValue $value) use ($cls, $oid) {
                $value = $cls::fromSelf($value);
                if ($value->oid() != $oid) {
                    throw new \LogicException("Attribute OID mismatch.");
                }
                return $value;
            }, $this->_values);
        return self::fromAttributeValues(...$values);
    }