public function toArray()
    {
        $array = ['name' => $this->getName()];

        foreach (static::$propertyMap[static::class] as $name => $property) {
            $value = $this->{$name};
            $array[$name] = $value instanceof XType ? $value->toArray() : $value;
        }

        if (!count($this->constraints)) {
            return $array;
        }

        $array['constraints'] = [];

        foreach ($this->constraints as $name=>$parameters) {
            $array['constraints'][$name] = $parameters;
        }

        return $array;
    }