Skip to content

Commit

Permalink
修改reflect.TypeFor的实现
Browse files Browse the repository at this point in the history
  • Loading branch information
wln32 committed Jan 13, 2025
1 parent ab45c0b commit ead979c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions database/gdb/gdb_convert_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ var (
convertConfig = gconv.NewConvertConfig("gf.orm")
)

func reflectTypeFor[T any]() reflect.Type {
return reflect.TypeOf((*T)(nil)).Elem()
}

func init() {
convertConfig.RegisterDefaultConvertFuncs()

convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]string](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]int64](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[map[string]any](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]string](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]int64](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[map[string]any](), convertToSliceFunc)

convertConfig.RegisterInterfaceTypeConvertFunc(reflect.TypeFor[sql.Scanner](), sqlScanner)
convertConfig.RegisterInterfaceTypeConvertFunc(reflectTypeFor[sql.Scanner](), sqlScanner)
}

func convertToSliceFunc(from any, to reflect.Value) error {
Expand Down

0 comments on commit ead979c

Please sign in to comment.