mercredi 11 août 2021

Converting reflect.Type back to reflect.Value

Is it possible to convert an instance of reflect.Type to a reflect.Value? Assuming I don't have access to the actual variable, only to an instance of a type that implements reflect.Type, for example:

package main

func main() {
  t := reflect.TypeOf(main)
  v := /* convert to reflect.Value */
}

The example above is not the real situation. I can't simple call reflect.ValueOf(main) - I only have access to t. I tried playing around with the methods of t, but nothing really worked, unfortunately.

Thank you!





Aucun commentaire:

Enregistrer un commentaire