initializeFromObjectArgs initializes struct fields from object properties (named parameters)
(instance interface{}, obj *Value, typ reflect.Type, ctx *Context)
| 215 | |
| 216 | // initializeFromObjectArgs initializes struct fields from object properties (named parameters) |
| 217 | func initializeFromObjectArgs(instance interface{}, obj *Value, typ reflect.Type, ctx *Context) error { |
| 218 | val := reflect.ValueOf(instance).Elem() |
| 219 | |
| 220 | for i := 0; i < typ.NumField(); i++ { |
| 221 | field := typ.Field(i) |
| 222 | |
| 223 | // Skip unexported fields |
| 224 | if !field.IsExported() { |
| 225 | continue |
| 226 | } |
| 227 | |
| 228 | // Use unified tag parsing from marshal.go |
| 229 | tagInfo := parseFieldTag(field) |
| 230 | if tagInfo.Skip { |
| 231 | continue // Field marked with "-" tag |
| 232 | } |
| 233 | |
| 234 | // Check if object has this property and set field value |
| 235 | if obj.Has(tagInfo.Name) { |
| 236 | propValue := obj.Get(tagInfo.Name) |
| 237 | defer propValue.Free() |
| 238 | |
| 239 | fieldValue := val.Field(i) |
| 240 | if fieldValue.CanSet() { |
| 241 | if err := ctx.unmarshal(propValue, fieldValue); err != nil { |
| 242 | return fmt.Errorf("failed to set field %s from property %s: %w", field.Name, tagInfo.Name, err) |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return nil |
| 249 | } |
| 250 | |
| 251 | // addReflectionMethods scans struct methods and adds them to the ClassBuilder |
| 252 | // Only exported methods are processed due to Go reflection limitations |
no test coverage detected