gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/datax/reflectx/ref-iface.go (about) 1 package reflectx 2 3 type IRefObject interface { 4 // RefType 结构的类名 5 RefType() string 6 } 7 8 type IRefType interface { 9 // RefType 结构的类名 10 RefType() string 11 // RefNew 生成结构 12 RefNew() IRefObject 13 } 14 15 type IRefField interface { 16 IRefType 17 // RefHas 是否包含字段 18 RefHas(field string) bool 19 // RefGet 获取field的值 20 RefGet(obj IRefObject, field string) (val interface{}, isNil bool) 21 // RefSet 设置field的值 22 RefSet(obj IRefObject, field string, val interface{}) 23 } 24 25 type IRefMap interface { 26 IRefField 27 RefMapGet(obj IRefObject, field string, key string) (val interface{}, isNil bool) 28 RefMapSet(obj IRefObject, field string, key string, val interface{}) 29 RefMapKeys(obj IRefObject, field string) []string 30 RefMapNew(field string) interface{} 31 } 32 33 type IRefSlice interface { 34 IRefField 35 RefSliceGet(obj IRefObject, field string, index int) (val interface{}, isNil bool) 36 RefSliceSet(obj IRefObject, field string, index int, val interface{}) 37 RefSliceNew(field string, len int, cap int) interface{} 38 RefSliceLength(obj IRefObject, field string) int 39 } 40 41 func init() { 42 list := []IRefType{ 43 &ClassDeclRef{}, 44 &InterfaceDeclRef{}, 45 &FieldRef{}, 46 &EnumDeclRef{}, 47 &AnyTypeRef{}, 48 &BasicTypeRef{}, 49 &ClassTypeRef{}, 50 &EnumTypeRef{}, 51 &MapTypeRef{}, 52 &ArrayTypeRef{}, 53 &FuncTypeRef{}, 54 } 55 56 for _, val := range list { 57 AddType(val) 58 } 59 return 60 }