I have the fallowing:
func NewMethodDescriptor(typ interface{}) *MethodDescriptor {
reflectedMethod := reflect.ValueOf(typ)
methodType := reflectedMethod.Type
paramCount := methodType.NumIn() - 1
...
But when I try:
NewMethodDescriptor(func(){})
I get this compile time error:
methodType.NumIn undefined (type func() reflect.Type has no field or method NumIn)
To be more specific:
reflectedMethod.Type
returns the function func (v Value) Type() Type
reflectedMethod.Type()
returns the result, meaning v's type.You can see a more complete example in "Fun with the reflection package to analyse any function."
func FuncAnalyse(m interface{}) {
//Reflection type of the underlying data of the interface
x := reflect.TypeOf(m)
numIn := x.NumIn() //Count inbound parameters
numOut := x.NumOut() //Count outbounding parameters
fmt.Println("Method:", x.String())
fmt.Println("Variadic:", x.IsVariadic()) // Used (<type> ...) ?
fmt.Println("Package:", x.PkgPath())
}