MCPcopy Index your code
hub / github.com/devfeel/mapper / MapDirectSlice

Function MapDirectSlice

mapper_func.go:134–153  ·  view source on GitHub ↗

MapDirectSlice 批量映射 使用示例: dtos := mapper.MapDirectSlice[User, UserDTO](users)

(from []From)

Source from the content-addressed store, hash-verified

132// MapDirectSlice 批量映射
133// 使用示例: dtos := mapper.MapDirectSlice[User, UserDTO](users)
134func MapDirectSlice[From, To any](from []From) []To {
135 if from == nil {
136 return nil
137 }
138
139 // 尝试预获取映射关系以优化批量操作
140 fromType := reflect.TypeOf((*From)(nil)).Elem()
141 toType := reflect.TypeOf((*To)(nil)).Elem()
142
143 _, hasCache := getFieldMappings(fromType, toType)
144 if !hasCache {
145 buildFieldMappings(fromType, toType)
146 }
147
148 result := make([]To, len(from))
149 for i, v := range from {
150 result[i] = MapDirect[From, To](v)
151 }
152 return result
153}
154
155// MapDirectPtrSlice 指针切片映射
156// 使用示例: dtos := mapper.MapDirectPtrSlice[User, UserDTO](&users)

Callers

nothing calls this directly

Calls 2

getFieldMappingsFunction · 0.85
buildFieldMappingsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…