/**
  * Returns the given result as property value of the specified property type.
  *
  * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject
  * @param string $propertyName
  * @param mixed $result The result
  * @return mixed
  */
 public function mapResultToPropertyValue(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, $result)
 {
     $propertyValue = NULL;
     if ($result instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LoadingStrategyInterface) {
         $propertyValue = $result;
     } else {
         $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
         if (in_array($propertyMetaData['type'], array('array', 'ArrayObject', 'SplObjectStorage', 'Tx_Extbase_Persistence_ObjectStorage', 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage'), TRUE)) {
             $objects = array();
             foreach ($result as $value) {
                 $objects[] = $value;
             }
             if ($propertyMetaData['type'] === 'ArrayObject') {
                 $propertyValue = new \ArrayObject($objects);
             } elseif (in_array($propertyMetaData['type'], array('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', 'Tx_Extbase_Persistence_ObjectStorage'), TRUE)) {
                 $propertyValue = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
                 foreach ($objects as $object) {
                     $propertyValue->attach($object);
                 }
                 $propertyValue->_memorizeCleanState();
             } else {
                 $propertyValue = $objects;
             }
         } elseif (strpbrk($propertyMetaData['type'], '_\\') !== FALSE) {
             if (is_object($result) && $result instanceof \TYPO3\CMS\Extbase\Persistence\QueryResultInterface) {
                 $propertyValue = $result->getFirst();
             } else {
                 $propertyValue = $result;
             }
         }
     }
     return $propertyValue;
 }