-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MSR: Generate additional constructors to reduce usage of reflection (#…
…18529) Closes #18357 This PR implements the idea described in the linked issue: Whenever there's an NSObject constructor that we call from a registrar callback, we need to create a separate constructor that will first set the `handle` and `flags` values of the NSObject before calling the original constructor. Here's an example of the code we generate: ```csharp // The original constructor: public .ctor (T0 p0, T1 p1, ...) { /* ... */ } // The generated constructor with pre-initialization: public .ctor (T0 p0, T1 p1, ..., IntPtr handle, IManagedRegistrar dummy) { this.handle = (NativeHandle)handle; this.flags = 2; // Flags.NativeRef == 2 this..ctor (p0, p1, ...); } ``` - This code can't be expressed in C# and it can only be expressed directly in IL. - The reason we need to do this is because the base NSObject parameterless constructor would allocate a new Objective-C object if `handle` is a zero pointer. - The `IManagedRegistrar` type is added only to make the constructor signature unique (IManagedRegistrar is not a public class and customers can't use it in their apps directly)
- Loading branch information
1 parent
1e7e084
commit 14f75f0
Showing
4 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.