How to display an entity property 'type' with form api 'type' for display in a form and then setting with the submitted value? Is there is process/ function that maps data types that you can use in entities (specifically custom entities using the Entity API) to form #type options? This is to dynamically add a field to a form from the entity and then once I've got the value from the submit handler, use the wrappers to set the property on a entity of the same entity type. Or am I taking the wrong approach here?

I am trying to get an entity property type and am currently using...

$property_info = entity_get_all_property_info('MY ENTITY TYPE');


Which generates $property_info['field_postcode'] which has this value...

field_postcode      Array [10]  
    label               Post Code   
    type                text    
    description         Field "field_postcode". 
    getter callback     entity_metadata_field_property_get  
    setter callback     entity_metadata_field_property_set  
    access callback     entity_metadata_field_access_callback   
    query callback      entity_metadata_field_query 
    translatable        false   
    field               true    
    required            true    


There I can see that it's got a 'type' of text which seems to translate well to a textfield in the Form API. But what about something like "file" in the Form API?

I wonder if I'm missing a piece of the puzzle here.
In response to Clive's comments under my question I have setup a project on drupal.org and issue to the Entity module issue queue as adding this functionality appears to be the best action. This would be the first contribution I've made so I'm eager for others to take on co-maintenance.

After I've thought a bit on how to go about doing this (still very open to suggestions) I'll add code etc. For the time being Clive's suggestion of using Entity module might be right but I've not yet checked it all out. 

In the meantime, here is the code I was using (just as a fairly straight-forward form callback) with a form and call_user_func_array() passing through the callback the user would have used. That's just in a basic custom module I called entity_to_form because tbh that's all I know how to do at the moment).

code:

/**
 * Form callback
 * 
 * @param entity type, existing entity type as in entity_load() $entity_type
 * @param callback, as in call_user_func_array() $callback
 * @param array, as in call_user_func_array() $param_arr
 */
function entity_to_form_new_form($form, &amp;$form_state, $entity_type, $callback) {
    // if not a valid entity type, set error and return
    $info = entity_get_info($entity_type);
    if (!is_array($info)) {
        global $user;
        $variables = array(
            '%uid' =&gt; $user-&gt;uid,
            '%timestamp' =&gt; time(),
            '%callback' =&gt; $callback,
            '%param_arr' =&gt; json_encode($param_arr),
        );
        watchdog('entity_to_form', 'callback not existing: error during function 
            entity_to_form_new_form() timestamp = %timestamp, uid = %uid, 
            callback = %callback, param_arr = %param_arr', $variables, 
            WATCHDOG_ERROR, $link = NULL);
        drupal_set_message('An error occurred and processing did not complete', 
            'error');
        return;
    }
    // if not a valid callback, set error and return
    if (!function_exists($callback)) {
        global $user;
        $variables = array(
            '%uid' =&gt; $user-&gt;uid,
            '%timestamp' =&gt; time(),
            '%callback' =&gt; $callback,
            '%param_arr' =&gt; json_encode($param_arr),
        );
        watchdog('entity_to_form', 'callback not existing: error during function 
            entity_to_form_new_form() timestamp = %timestamp, uid = %uid, 
            callback = %callback, param_arr = %param_arr', $variables, 
            WATCHDOG_ERROR, $link = NULL);
        drupal_set_message('An error occurred and processing did not complete', 
            'error');
        return;
    }
    // get information about the entity properties and custom fields
    $property_info = entity_get_all_property_info($entity_type);

    // dynamically set elements for the properties and custom fields

    // fullfil the final requirements for the submit handler
    $form['entity-to-form']['submit-callback'] = array(
        '#type' =&gt; 'value',
        '#value' =&gt; $callback,
    );
    $form['entity-to-form']['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; 'Submit',
    );
    return $form;
}

/**
 * Form submit handler
 */
function entity_to_form_new_form_submit($form, &amp;$form_state) {
    $callback = $form_state['values']['submit-callback'];
    $variables = '';
    call_user_func_array($callback, $variables);
}