`

reflect all arguments' type for a method

 
阅读更多
package main

type Foo struct{

    C float64

}

func (f *Foo) DoSomething(a int, b string){

    fmt.Println(a,b,f.C)

}

func main() {

foo:=&Foo{

    C: 3.14,

}

method:=reflect.ValueOf(foo).MethodByName("DoSomething")

//注意这里不能用reflect.TypeOf(method),而是用method.Type()

methodType:=method.Type()

for i:=0; i<methodType.NumIn(); i++{

    fmt.Println(i,"-----",methodType.In(i))

}

//调用method,略,前人之述备矣

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics