Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@quantumsheep
Copy link

@quantumsheep quantumsheep commented May 15, 2024

My use-case:

type CustomNativeType struct {
	reflect.Type
}

func (t *CustomNativeType) FieldByName(name string) (reflect.StructField, bool) {
	name = strcase.ToPascal(name)
	return t.Type.FieldByName(name)
}

type Foo struct {
	MyField string
}

func main() {
	fooType := &CustomNativeType{Type: reflect.TypeOf(Foo{})}

	env, err := cel.NewEnv(
		ext.NativeTypes(fooType),
		cel.Variable("foo", cel.ObjectType("package.Foo")),
	)
	if err != nil {
		panic(err)
	}

	// Evaluate "foo.my_field"
}

if !ok {
return nil, false
}
refFieldName := refField.Name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow how the input field name differs from the refField.Name value in this case. Could you add a test to illustrate the change in behavior?

@TristonianJones
Copy link
Collaborator

@quantumsheep would you mind helping me understand how this change accomplishes your goal. I think the idea is to proxy to another object which implements an interface similar to what golang reflection does, but I'm not sure I understand how this PR accomplishes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants