Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reflection when wrapping unknown handles #919

Open
badcel opened this issue Aug 2, 2023 · 0 comments · May be fixed by #1006
Open

Avoid reflection when wrapping unknown handles #919

badcel opened this issue Aug 2, 2023 · 0 comments · May be fixed by #1006
Milestone

Comments

@badcel
Copy link
Member

badcel commented Aug 2, 2023

GObject.Internal.ObjectWrapper.WrapHandle needs to create a new instance of a class if the given handle is not known. It uses reflection to find the correct constructor.

With dotnet 7 it is possible to define static methods in interfaces. This allows all classes to implement a certain interface (e.g. CreateableClass) which defines a method like Create(ptr, owned). The WrapHandle method can check if the given T implements this interface and then call the Create method which in turns calls the constructor. In this way reflection can be avoided. If the interface is not implemented throw an exception.

Create a fallback implementation for dotnet 6 which relies on reflection (similar to GTypeProviderHelper).

Verify if this can be applied to interfaces and records, too.

@badcel badcel added this to the 0.13.0 milestone Aug 2, 2023
@badcel badcel linked a pull request Jan 21, 2024 that will close this issue
6 tasks
@badcel badcel linked a pull request Jan 21, 2024 that will close this issue
6 tasks
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 a pull request may close this issue.

1 participant